-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfiguration_test.go
96 lines (74 loc) · 2.93 KB
/
configuration_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package authproxy
import (
. "gopkg.in/check.v1"
"testing"
)
func TestConfiguration(t *testing.T) { TestingT(t) }
type ConfigurationSuite struct{}
var _ = Suite(&ConfigurationSuite{})
func (s *ConfigurationSuite) TestJsonReadFile(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
c.Assert(len(config.Upstreams), Equals, 2)
}
func (s *ConfigurationSuite) TestJsonReadFileForUsers(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
c.Assert(len(config.Users), Equals, 2)
}
func (s *ConfigurationSuite) TestAuthenticationContext(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
c.Assert(config.AuthenticationContextName, Equals, "github")
}
func (s *ConfigurationSuite) TestJsonReadFileForUsersAndValidateError(c *C) {
configLocation := "fixtures/testconfigwithnousers.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
_, err := NewConfiguration(data)
c.Assert(err, Not(Equals), nil)
}
func (s *ConfigurationSuite) TestUserWithNoRestriction(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
c.Assert(len(config.Users), Equals, 2)
c.Assert(config.Users[0].Username, Equals, "KensoDev")
c.Assert(config.Users[0].Restrict, Equals, "")
c.Assert(config.Users[1].Restrict, Equals, "GET")
}
func (s *ConfigurationSuite) GetUserRestrictedMethod(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
method := config.GetRestrictionsForUsername("KensoDev2")
c.Assert(method, Equals, "Get")
method = config.GetRestrictionsForUsername("KensoDev")
c.Assert(method, Equals, "")
}
func (s *ConfigurationSuite) GetUserRestrictedMethodNotAllowed(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
method := config.GetRestrictionsForUsername("KensoDev23234234")
c.Assert(method, Equals, "NotAllowed")
}
func (s *ConfigurationSuite) TestShouldAllowedMethodForUsername(c *C) {
configLocation := "fixtures/testconfig.json"
reader := NewConfigurationReader(configLocation)
data, _ := reader.ReadConfigurationFile()
config, _ := NewConfiguration(data)
should := config.ShouldRestrictUser("KensoDev", "POST")
c.Assert(should, Equals, true)
should = config.ShouldRestrictUser("KensoDev2", "POST")
c.Assert(should, Equals, false)
}