Samuel A. Falvo II | 2dd7d2f | 2014-06-30 16:18:08 -0700 | [diff] [blame] | 1 | // +build acceptance,old |
| 2 | |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 3 | package main |
| 4 | |
| 5 | import ( |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 6 | "flag" |
Jon Perritt | 2be65d1 | 2013-12-13 17:21:09 -0600 | [diff] [blame] | 7 | "fmt" |
Max Lincoln | 28b4956 | 2013-12-13 13:23:44 -0300 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.") |
Samuel A. Falvo II | e4a3e42 | 2013-09-13 12:36:37 -0700 | [diff] [blame] | 12 | var rgn = flag.String("r", "", "Datacenter region to interrogate. Leave blank for provider-default region.") |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 13 | |
| 14 | func main() { |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 15 | flag.Parse() |
| 16 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 17 | // Invoke withIdentity such that re-auth is enabled. |
| 18 | withIdentity(true, func(auth gophercloud.AccessProvider) { |
| 19 | token1 := auth.AuthToken() |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 20 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 21 | 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 II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 27 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 28 | // 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 II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 49 | }) |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 50 | } |