1 package awsrulesfn
2
3 import (
4 "testing"
5 )
6
7 func TestIsVirtualHostableS3Bucket(t *testing.T) {
8 cases := map[string]struct {
9 input string
10 allowSubDomains bool
11 expect bool
12 }{
13 "single label no split": {
14 input: "abc123-",
15 expect: true,
16 },
17 "single label no split too short": {
18 input: "a",
19 expect: false,
20 },
21 "single label with split": {
22 input: "abc123-",
23 allowSubDomains: true,
24 expect: true,
25 },
26 "multiple labels no split": {
27 input: "abc.123-",
28 expect: false,
29 },
30 "multiple labels with split": {
31 input: "abc.123-",
32 allowSubDomains: true,
33 expect: true,
34 },
35 "multiple labels with split invalid label": {
36 input: "abc.123-...",
37 allowSubDomains: true,
38 expect: false,
39 },
40 "max length host label": {
41 input: "012345678901234567890123456789012345678901234567890123456789123",
42 expect: true,
43 },
44 "too large host label": {
45 input: "0123456789012345678901234567890123456789012345678901234567891234",
46 expect: false,
47 },
48 "too small host label": {
49 input: "",
50 expect: false,
51 },
52 "lower case only": {
53 input: "AbC",
54 expect: false,
55 },
56 "like IP address": {
57 input: "127.111.222.123",
58 expect: false,
59 },
60 "multiple labels like IP address": {
61 input: "127.111.222.123",
62 allowSubDomains: true,
63 expect: false,
64 },
65 }
66
67 for name, c := range cases {
68 t.Run(name, func(t *testing.T) {
69 actual := IsVirtualHostableS3Bucket(c.input, c.allowSubDomains)
70 if e, a := c.expect, actual; e != a {
71 t.Fatalf("expect %v hostable bucket, got %v", e, a)
72 }
73 })
74 }
75 }
76
View as plain text