Add early acceptance test for reauthentication.
diff --git a/acceptance/08-reauthentication.go b/acceptance/08-reauthentication.go
new file mode 100644
index 0000000..31c1fe8
--- /dev/null
+++ b/acceptance/08-reauthentication.go
@@ -0,0 +1,64 @@
+package main
+
+import (
+ "fmt"
+ "flag"
+ "github.com/rackspace/gophercloud"
+)
+
+var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.")
+var rgn = flag.String("r", "DFW", "Datacenter region to interrogate.")
+
+func main() {
+ provider, username, password := getCredentials()
+ flag.Parse()
+
+ // Authenticate initially against the service.
+ auth, err := gophercloud.Authenticate(
+ provider,
+ gophercloud.AuthOptions{
+ Username: username,
+ Password: password,
+ },
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ // Cache our initial authentication token.
+ token1 := auth.AuthToken()
+
+ // Acquire access to the cloud servers API.
+ servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
+ Name: "cloudServersOpenStack",
+ Region: *rgn,
+ VersionId: "2",
+ UrlChoice: gophercloud.PublicURL,
+ })
+ if err != nil {
+ panic(err)
+ }
+
+ // Just to confirm everything works, we should be able to list images without error.
+ _, err = servers.ListImages()
+ if err != nil {
+ panic(err)
+ }
+
+ // Revoke our current authentication token.
+ auth.Revoke(auth.AuthToken())
+
+ // Attempt to list images again. This should _succeed_, because we enabled re-authentication.
+ _, err = servers.ListImages()
+ if err != nil {
+ panic(err)
+ }
+
+ // However, our new authentication token should differ.
+ token2 := auth.AuthToken()
+
+ if !*quiet {
+ fmt.Println("Old authentication token: ", token1)
+ fmt.Println("New authentication token: ", token2)
+ }
+}
diff --git a/authenticate.go b/authenticate.go
index 8b87e44..7665304 100644
--- a/authenticate.go
+++ b/authenticate.go
@@ -139,3 +139,8 @@
func (a *Access) AuthToken() string {
return a.Token.Id
}
+
+// See AccessProvider interface definition for details.
+func (a *Access) Revoke(tok string) error {
+ return nil
+}
diff --git a/interfaces.go b/interfaces.go
index 6d9b3c7..ed16afe 100644
--- a/interfaces.go
+++ b/interfaces.go
@@ -9,10 +9,12 @@
// field.
FirstEndpointUrlByCriteria(ApiCriteria) string
- // TODO(sfalvo): get Token() to automatically renew the authentication token if it's near expiry.
-
// AuthToken provides a copy of the current authentication token for the user's credentials.
+ // Note that AuthToken() will not automatically refresh an expired token.
AuthToken() string
+
+ // Revoke allows you to terminate any program's access to the OpenStack API by token ID.
+ Revoke(string) error
}
// CloudServersProvider instances encapsulate a Cloud Servers API, should one exist in the service catalog