-
Notifications
You must be signed in to change notification settings - Fork 21
/
main_test.go
78 lines (66 loc) · 2.47 KB
/
main_test.go
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
76
77
78
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseOptions(t *testing.T) {
h, err := NewAwsS3ReverseProxy(Options{
AllowedSourceEndpoint: "foobar.endpoint.example.com",
AllowedSourceSubnet: []string{"127.0.0.1/32", "192.168.1.0/24"},
AwsCredentials: []string{"fooooooooooooooo,bar", "baaaaaaaaaaaaaar,baz"},
Region: "eu-test-1",
})
assert.Nil(t, err)
assert.Equal(t, "https", h.UpstreamScheme)
assert.Equal(t, "", h.UpstreamEndpoint)
assert.Equal(t, "foobar.endpoint.example.com", h.AllowedSourceEndpoint)
assert.Len(t, h.AllowedSourceSubnet, 2)
assert.Equal(t, "127.0.0.1/32", h.AllowedSourceSubnet[0].String())
assert.Equal(t, "192.168.1.0/24", h.AllowedSourceSubnet[1].String())
assert.Len(t, h.AWSCredentials, 2)
assert.Equal(t, "bar", h.AWSCredentials["fooooooooooooooo"])
assert.Equal(t, "baz", h.AWSCredentials["baaaaaaaaaaaaaar"])
assert.Len(t, h.Signers, 2)
assert.Contains(t, h.Signers, "fooooooooooooooo")
assert.Contains(t, h.Signers, "baaaaaaaaaaaaaar")
}
func TestParseOptionsBrokenSubnets(t *testing.T) {
_, err := NewAwsS3ReverseProxy(Options{
AllowedSourceSubnet: []string{"foobar"},
})
assert.Contains(t, err.Error(), "Invalid allowed source subnet")
_, err = NewAwsS3ReverseProxy(Options{
AllowedSourceSubnet: []string{""},
})
assert.Contains(t, err.Error(), "Invalid allowed source subnet")
_, err = NewAwsS3ReverseProxy(Options{
AllowedSourceSubnet: []string{"127.0.0.1/XXX"},
})
assert.Contains(t, err.Error(), "Invalid allowed source subnet")
_, err = NewAwsS3ReverseProxy(Options{
AllowedSourceSubnet: []string{"127.0.0.1"},
})
assert.Contains(t, err.Error(), "Invalid allowed source subnet")
_, err = NewAwsS3ReverseProxy(Options{
AllowedSourceSubnet: []string{"256.0.0.1"},
})
assert.Contains(t, err.Error(), "Invalid allowed source subnet")
}
func TestParseOptionsBrokenAWSCredentials(t *testing.T) {
_, err := NewAwsS3ReverseProxy(Options{
AwsCredentials: []string{""},
})
assert.Contains(t, err.Error(), "Invalid AWS credentials")
_, err = NewAwsS3ReverseProxy(Options{
AwsCredentials: []string{"foobar"},
})
assert.Contains(t, err.Error(), "Invalid AWS credentials")
_, err = NewAwsS3ReverseProxy(Options{
AwsCredentials: []string{"foooooooooooobar"},
})
assert.Contains(t, err.Error(), "Invalid AWS credentials")
_, err = NewAwsS3ReverseProxy(Options{
AwsCredentials: []string{"foooooooooooobar,"},
})
assert.Contains(t, err.Error(), "Invalid AWS credentials")
}