Check for token not being returned in JSON response (#91)
This avoid a potential nil pointer dereference since
JSON decoding can succeed with missing fields.
diff --git a/openstack/identity/v3/tokens/results.go b/openstack/identity/v3/tokens/results.go
index 4b362cc..36c9ce6 100644
--- a/openstack/identity/v3/tokens/results.go
+++ b/openstack/identity/v3/tokens/results.go
@@ -1,5 +1,6 @@
package tokens
+import "errors"
import "github.com/gophercloud/gophercloud"
// Endpoint represents a single API endpoint offered by a service.
@@ -59,6 +60,10 @@
return nil, err
}
+ if s.Token == nil {
+ return nil, errors.New("'token' missing in JSON response")
+ }
+
// Parse the token itself from the stored headers.
s.Token.ID = r.Header.Get("X-Subject-Token")