forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_test.go
122 lines (101 loc) · 2.61 KB
/
security_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package design_test
import (
"fmt"
. "github.com/goadesign/goa/design"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("SecuritySchemeDefinition", func() {
var scheme, host, tokenURL, authorizationURL string
var def *SecuritySchemeDefinition
BeforeEach(func() {
def = nil
tokenURL = ""
authorizationURL = ""
scheme = ""
host = ""
})
JustBeforeEach(func() {
Design.Schemes = []string{scheme}
Design.Host = host
def = &SecuritySchemeDefinition{
TokenURL: tokenURL,
AuthorizationURL: authorizationURL,
}
})
Context("with valid token and authorization URLs", func() {
BeforeEach(func() {
tokenURL = "http://valid.com/token"
authorizationURL = "http://valid.com/auth"
})
It("validates", func() {
Ω(def.Validate()).ShouldNot(HaveOccurred())
})
})
Context("with an invalid token URL", func() {
BeforeEach(func() {
tokenURL = ":"
authorizationURL = "http://valid.com/auth"
})
It("does not validate", func() {
err := def.Validate()
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(ContainSubstring(tokenURL))
})
})
Context("with an absolute token URL", func() {
BeforeEach(func() {
tokenURL = "http://valid.com/auth"
})
It("Finalize does not modify it", func() {
priorURL := def.TokenURL
def.Finalize()
Ω(def.TokenURL).Should(Equal(priorURL))
})
})
Context("with a relative token URL", func() {
BeforeEach(func() {
scheme = "http"
host = "foo.com"
tokenURL = "/auth"
})
It("Finalize makes it absolute", func() {
priorURL := def.TokenURL
def.Finalize()
Ω(def.TokenURL).Should(Equal(fmt.Sprintf("%s://%s%s", scheme, host, priorURL)))
})
})
Context("with an invalid authorization URL", func() {
BeforeEach(func() {
tokenURL = "http://valid.com/auth"
authorizationURL = ":"
})
It("does not validate", func() {
err := def.Validate()
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(ContainSubstring(authorizationURL))
})
})
Context("with an absolute authorization URL", func() {
BeforeEach(func() {
authorizationURL = "http://valid.com/auth"
})
It("Finalize does not modify it", func() {
priorURL := def.AuthorizationURL
def.Finalize()
Ω(def.AuthorizationURL).Should(Equal(priorURL))
})
})
Context("with a relative authorization URL", func() {
BeforeEach(func() {
scheme = "http"
host = "foo.com"
authorizationURL = "/auth"
})
It("Finalize makes it absolute", func() {
priorURL := def.AuthorizationURL
def.Finalize()
Ω(def.AuthorizationURL).Should(Equal(fmt.Sprintf("%s://%s%s", scheme, host, priorURL)))
})
})
})