Skip to content

Commit ef1eaf8

Browse files
Tim Koppxtreme-debbie-chen
authored andcommitted
Update to use uaa refresh tokens
In [#150153665], the go-pivnet code vendored in pivnet-resource was directly modified, instead of updating go-pivnet and re-vendoring the library. This commit makes the changes corresponding to that story, and updates the corresponding tests. This way, when pivnet-resource udpates its version of go-pivnet, the changes are not reverted. [#151761519] Signed-off-by: Debbie Chen <[email protected]>
1 parent 3f5656e commit ef1eaf8

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

auth.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func (e AuthService) Check() (bool, error) {
4646
}
4747
}
4848

49-
func (e AuthService) FetchUAAToken(username, password string) (UAATokenResponse, error) {
49+
func (e AuthService) FetchUAAToken(refresh_token string) (UAATokenResponse, error) {
5050
url := "/authentication"
5151

52-
body := AuthBody{Username: username, Password: password}
52+
body := AuthBody{RefreshToken: refresh_token}
5353
b, err := json.Marshal(body)
5454
if err != nil {
5555
return UAATokenResponse{}, err
@@ -79,6 +79,5 @@ func (e AuthService) FetchUAAToken(username, password string) (UAATokenResponse,
7979
}
8080

8181
type AuthBody struct {
82-
Username string `json:"username"`
83-
Password string `json:"password"`
82+
RefreshToken string `json:"refresh_token"`
8483
}

auth_test.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ var _ = Describe("PivnetClient - Auth", func() {
2121
apiAddress string
2222
userAgent string
2323

24-
username string
25-
password string
24+
refresh_token string
2625

2726
newClientConfig pivnet.ClientConfig
2827
fakeLogger logger.Logger
@@ -137,13 +136,11 @@ var _ = Describe("PivnetClient - Auth", func() {
137136

138137
Describe("FetchUAAToken", func() {
139138
It("returns the UAA token", func() {
140-
username = "some-username"
141-
password = "some-password"
139+
refresh_token = "some-refresh-token"
142140

143141
expectedRequestBody := fmt.Sprintf(
144-
`{"username":"%s","password":"%s"}`,
145-
username,
146-
password,
142+
`{"refresh_token":"%s"}`,
143+
refresh_token,
147144
)
148145

149146
response := pivnet.UAATokenResponse{
@@ -161,20 +158,18 @@ var _ = Describe("PivnetClient - Auth", func() {
161158
),
162159
)
163160

164-
tokenResponse, err := client.Auth.FetchUAAToken(username, password)
161+
tokenResponse, err := client.Auth.FetchUAAToken(refresh_token)
165162
Expect(err).NotTo(HaveOccurred())
166163
Expect(tokenResponse.Token).To(Equal("some-token"))
167164
})
168165

169166
Context("When Pivnet returns a 401", func() {
170167
It("returns an error", func() {
171-
username = "some-username"
172-
password = "some-password"
168+
refresh_token = "some-refresh-token"
173169

174170
expectedRequestBody := fmt.Sprintf(
175-
`{"username":"%s","password":"%s"}`,
176-
username,
177-
password,
171+
`{"refresh_token":"%s"}`,
172+
refresh_token,
178173
)
179174

180175
server.AppendHandlers(
@@ -188,7 +183,7 @@ var _ = Describe("PivnetClient - Auth", func() {
188183
),
189184
)
190185

191-
_, err := client.Auth.FetchUAAToken(username, password)
186+
_, err := client.Auth.FetchUAAToken(refresh_token)
192187
Expect(err).To(HaveOccurred())
193188
})
194189
})

0 commit comments

Comments
 (0)