forked from Kriechi/aws-s3-reverse-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
79 lines (67 loc) · 2.54 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
79
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, "eu-test-1", h.Region)
assert.Equal(t, "https", h.UpstreamScheme)
assert.Equal(t, "s3.eu-test-1.amazonaws.com", 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")
}