Skip to content

Commit

Permalink
Update to use uaa refresh tokens
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Tim Kopp authored and xtreme-debbie-chen committed Oct 18, 2017
1 parent 3f5656e commit ef1eaf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
7 changes: 3 additions & 4 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func (e AuthService) Check() (bool, error) {
}
}

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

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

type AuthBody struct {
Username string `json:"username"`
Password string `json:"password"`
RefreshToken string `json:"refresh_token"`
}
23 changes: 9 additions & 14 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ var _ = Describe("PivnetClient - Auth", func() {
apiAddress string
userAgent string

username string
password string
refresh_token string

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

Describe("FetchUAAToken", func() {
It("returns the UAA token", func() {
username = "some-username"
password = "some-password"
refresh_token = "some-refresh-token"

expectedRequestBody := fmt.Sprintf(
`{"username":"%s","password":"%s"}`,
username,
password,
`{"refresh_token":"%s"}`,
refresh_token,
)

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

tokenResponse, err := client.Auth.FetchUAAToken(username, password)
tokenResponse, err := client.Auth.FetchUAAToken(refresh_token)
Expect(err).NotTo(HaveOccurred())
Expect(tokenResponse.Token).To(Equal("some-token"))
})

Context("When Pivnet returns a 401", func() {
It("returns an error", func() {
username = "some-username"
password = "some-password"
refresh_token = "some-refresh-token"

expectedRequestBody := fmt.Sprintf(
`{"username":"%s","password":"%s"}`,
username,
password,
`{"refresh_token":"%s"}`,
refresh_token,
)

server.AppendHandlers(
Expand All @@ -188,7 +183,7 @@ var _ = Describe("PivnetClient - Auth", func() {
),
)

_, err := client.Auth.FetchUAAToken(username, password)
_, err := client.Auth.FetchUAAToken(refresh_token)
Expect(err).To(HaveOccurred())
})
})
Expand Down

0 comments on commit ef1eaf8

Please sign in to comment.