-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeys_test.go
79 lines (58 loc) · 1.71 KB
/
keys_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 fireauth
import (
"fmt"
"net/http"
"net/http/httptest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Keys", func() {
var (
maxAge int64
err error
serverTokens map[string]interface{}
)
BeforeEach(func() {
if serverTokens == nil {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set(HeaderCacheControl, "..., max-age=19008, ...")
fmt.Fprintln(w, jsonKeys)
}))
defer ts.Close()
serverTokens = make(map[string]interface{})
maxAge, err = GetKeys(serverTokens, ts.URL)
}
})
It("should not throw an error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should extract maxAge from response header", func() {
Expect(maxAge).To(Equal(int64(19008)))
})
It("should populate serverTokens with four keys", func() {
Expect(len(serverTokens)).To(Equal(4))
})
Context("key server response does not contain max-age", func() {
BeforeEach(func() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set(HeaderCacheControl, "something other than max age")
fmt.Fprintln(w, jsonKeys)
}))
defer ts.Close()
serverTokens = make(map[string]interface{})
maxAge, err = GetKeys(serverTokens, ts.URL)
})
It("should return an ErrCacheControlHeaderLacksMaxAge error", func() {
Expect(err).To(Equal(ErrCacheControlHeaderLacksMaxAge))
})
})
Context("no server response", func() {
BeforeEach(func() {
serverTokens = make(map[string]interface{})
maxAge, err = GetKeys(serverTokens, "https://notgonnaresolvem0nkeygirrage.org")
})
It("should return an error", func() {
Expect(err).To(HaveOccurred())
})
})
})