-
Notifications
You must be signed in to change notification settings - Fork 16
/
client_test.go
146 lines (122 loc) · 3.59 KB
/
client_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package gogobosh_test
import (
. "github.com/cloudfoundry-community/gogobosh"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Client", func() {
Describe("Test Default Config", func() {
config := DefaultConfig()
It("returns default config", func() {
Expect(config.BOSHAddress).Should(Equal("https://192.168.50.4:25555"))
Expect(config.Username).Should(Equal("admin"))
Expect(config.Password).Should(Equal("admin"))
})
})
Describe("Test Creating basic auth client", func() {
var client *Client
BeforeEach(func() {
setup("basic")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Password: "admin",
}
client, _ = NewClient(config)
})
AfterEach(func() {
teardown()
})
It("can get bosh info", func() {
info, err := client.GetInfo()
Expect(info.Name).Should(Equal("bosh-lite"))
Expect(info.UUID).Should(Equal("2daf673a-9755-4b4f-aa6d-3632fbed8019"))
Expect(info.Version).Should(Equal("1.3126.0 (00000000)"))
Expect(info.User).Should(Equal("admin"))
Expect(info.CPI).Should(Equal("warden_cpi"))
Expect(err).Should(BeNil())
})
})
Describe("Test Creating uaa auth client", func() {
var client *Client
BeforeEach(func() {
setup("uaa")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Password: "admin",
}
client, _ = NewClient(config)
})
AfterEach(func() {
teardown()
})
It("can get bosh info", func() {
info, err := client.GetInfo()
Expect(info.Name).Should(Equal("bosh-lite"))
Expect(info.UUID).Should(Equal("2daf673a-9755-4b4f-aa6d-3632fbed8012"))
Expect(info.Version).Should(Equal("1.3126.0 (00000000)"))
Expect(info.User).Should(Equal("admin"))
Expect(info.CPI).Should(Equal("warden_cpi"))
Expect(err).Should(BeNil())
})
})
Describe("Test uaa auth", func() {
var client *Client
Context("when the refresh token has expired", func() {
BeforeEach(func() {
setupMockRoute(MockRoute{"GET", "/stemcells", `[]`, ""}, "uaa")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Password: "admin",
}
client, _ = NewClient(config)
})
AfterEach(func() {
teardown()
})
Context("and a clientRefresh occurs", func() {
It("can get brand new uaa token", func() {
token, err := client.GetToken()
Expect(err).Should(BeNil())
Expect(token).Should(Equal("bearer foobar2"))
_, err = client.GetStemcells()
Expect(err).Should(BeNil())
token, err = client.GetToken()
Expect(err).Should(BeNil())
Expect(token).Should(Equal("bearer foobar6"))
})
})
Context("and a clientRefresh does not occur", func() {
It("can get brand new uaa token", func() {
token, err := client.GetToken()
Expect(err).Should(BeNil())
Expect(token).Should(Equal("bearer foobar2"))
token, err = client.GetToken()
Expect(err).Should(MatchError("error getting bearer token: oauth2: cannot fetch token: 401 Unauthorized\nResponse: {\"error\":\"invalid_token\",\"error_description\":\"Invalid refresh token (expired)\"}"))
Expect(token).Should(Equal(""))
})
})
})
Context("when the refresh token is valid", func() {
BeforeEach(func() {
setup("uaa")
config := &Config{
BOSHAddress: server.URL,
Username: "admin",
Password: "admin",
}
client, _ = NewClient(config)
})
AfterEach(func() {
teardown()
})
It("can refresh its uaa token", func() {
token, err := client.GetToken()
Expect(err).Should(BeNil())
Expect(token).Should(Equal("bearer foobar2"))
})
})
})
})