aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/host_test.go
blob: 254c9fab4faf2eea4931b8bade143f9993b188f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package awsrulesfn

import (
	"testing"
)

func TestIsVirtualHostableS3Bucket(t *testing.T) {
	cases := map[string]struct {
		input           string
		allowSubDomains bool
		expect          bool
	}{
		"single label no split": {
			input:  "abc123-",
			expect: true,
		},
		"single label no split too short": {
			input:  "a",
			expect: false,
		},
		"single label with split": {
			input:           "abc123-",
			allowSubDomains: true,
			expect:          true,
		},
		"multiple labels no split": {
			input:  "abc.123-",
			expect: false,
		},
		"multiple labels with split": {
			input:           "abc.123-",
			allowSubDomains: true,
			expect:          true,
		},
		"multiple labels with split invalid label": {
			input:           "abc.123-...",
			allowSubDomains: true,
			expect:          false,
		},
		"max length host label": {
			input:  "012345678901234567890123456789012345678901234567890123456789123",
			expect: true,
		},
		"too large host label": {
			input:  "0123456789012345678901234567890123456789012345678901234567891234",
			expect: false,
		},
		"too small host label": {
			input:  "",
			expect: false,
		},
		"lower case only": {
			input:  "AbC",
			expect: false,
		},
		"like IP address": {
			input:  "127.111.222.123",
			expect: false,
		},
		"multiple labels like IP address": {
			input:           "127.111.222.123",
			allowSubDomains: true,
			expect:          false,
		},
	}

	for name, c := range cases {
		t.Run(name, func(t *testing.T) {
			actual := IsVirtualHostableS3Bucket(c.input, c.allowSubDomains)
			if e, a := c.expect, actual; e != a {
				t.Fatalf("expect %v hostable bucket, got %v", e, a)
			}
		})
	}
}