Ensure authenticate never re-auths.
Other API functions will support re-auth as a matter of course.
If an auth token expires, we need to re-authenticate to acquire a new
token. If re-authentication were itself to attempt re-auth, we
would end up in an endless loop.
If after authenticating gophercloud receives a 401 Unauthorized
response, then we must assume that the provided credentials are
incorrect.
diff --git a/authenticate_test.go b/authenticate_test.go
index a19fec4..e08a0a6 100644
--- a/authenticate_test.go
+++ b/authenticate_test.go
@@ -212,3 +212,28 @@
return
}
}
+
+func TestAuthenticationNeverReauths(t *testing.T) {
+ tt := newTransport().WithError(401)
+ c := TestContext().
+ UseCustomClient(&http.Client{Transport: tt}).
+ WithProvider("provider", Provider{AuthEndpoint: "http://localhost"})
+
+ _, err := c.Authenticate("provider", AuthOptions{Username: "u", Password: "p"})
+ if err == nil {
+ t.Error("Expected an error from a 401 Unauthorized response")
+ return
+ }
+
+ rc, _ := ActualResponseCode(err)
+ if rc != 401 {
+ t.Error("Expected a 401 error code")
+ return
+ }
+
+ err = tt.VerifyCalls(t, 1)
+ if err != nil {
+ // Test object already flagged.
+ return
+ }
+}