blob: c46f5bbc84bc2a81f93ab4ab4b7734cb55a47b8e [file] [log] [blame]
Samuel A. Falvo II2dd7d2f2014-06-30 16:18:08 -07001// +build acceptance,old
2
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07003package main
4
5import (
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07006 "flag"
Jon Perritt2be65d12013-12-13 17:21:09 -06007 "fmt"
Max Lincoln28b49562013-12-13 13:23:44 -03008 "github.com/rackspace/gophercloud"
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07009)
10
11var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.")
Samuel A. Falvo IIe4a3e422013-09-13 12:36:37 -070012var rgn = flag.String("r", "", "Datacenter region to interrogate. Leave blank for provider-default region.")
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070013
14func main() {
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070015 flag.Parse()
16
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070017 // Invoke withIdentity such that re-auth is enabled.
18 withIdentity(true, func(auth gophercloud.AccessProvider) {
19 token1 := auth.AuthToken()
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070020
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070021 withServerApi(auth, func(servers gophercloud.CloudServersProvider) {
22 // Just to confirm everything works, we should be able to list images without error.
23 _, err := servers.ListImages()
24 if err != nil {
25 panic(err)
26 }
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070027
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070028 // Revoke our current authentication token.
29 auth.Revoke(auth.AuthToken())
30
31 // Attempt to list images again. This should _succeed_, because we enabled re-authentication.
32 _, err = servers.ListImages()
33 if err != nil {
34 panic(err)
35 }
36
37 // However, our new authentication token should differ.
38 token2 := auth.AuthToken()
39
40 if !*quiet {
41 fmt.Println("Old authentication token: ", token1)
42 fmt.Println("New authentication token: ", token2)
43 }
44
45 if token1 == token2 {
46 panic("Tokens should differ")
47 }
48 })
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070049 })
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070050}