blob: b4106a31f433163c40a83bd469d85f3d63ed3f23 [file] [log] [blame]
jrperritt0bc55782016-07-27 13:50:14 -05001package testing
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
jrperrittc8834c12016-08-03 16:06:16 -05007 "time"
jrperritt0bc55782016-07-27 13:50:14 -05008
9 "github.com/gophercloud/gophercloud"
jrperrittc8834c12016-08-03 16:06:16 -050010 "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts"
jrperritt0bc55782016-07-27 13:50:14 -050011 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
12 "github.com/gophercloud/gophercloud/testhelper"
13)
14
15// HandleCreateTokenWithTrustID verifies that providing certain AuthOptions and Scope results in an expected JSON structure.
16func HandleCreateTokenWithTrustID(t *testing.T, options tokens.AuthOptionsBuilder, requestJSON string) {
17 testhelper.SetupHTTP()
18 defer testhelper.TeardownHTTP()
19
20 client := gophercloud.ServiceClient{
21 ProviderClient: &gophercloud.ProviderClient{},
22 Endpoint: testhelper.Endpoint(),
23 }
24
25 testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
26 testhelper.TestMethod(t, r, "POST")
27 testhelper.TestHeader(t, r, "Content-Type", "application/json")
28 testhelper.TestHeader(t, r, "Accept", "application/json")
29 testhelper.TestJSONRequest(t, r, requestJSON)
30
31 w.WriteHeader(http.StatusCreated)
32 fmt.Fprintf(w, `{
jrperrittc8834c12016-08-03 16:06:16 -050033 "token": {
34 "expires_at": "2013-02-27T18:30:59.999999Z",
35 "issued_at": "2013-02-27T16:30:59.999999Z",
36 "methods": [
37 "password"
38 ],
39 "OS-TRUST:trust": {
40 "id": "fe0aef",
41 "impersonation": false,
42 "redelegated_trust_id": "3ba234",
43 "redelegation_count": 2,
44 "links": {
45 "self": "http://example.com/identity/v3/trusts/fe0aef"
46 },
47 "trustee_user": {
48 "id": "0ca8f6",
49 "links": {
50 "self": "http://example.com/identity/v3/users/0ca8f6"
51 }
52 },
53 "trustor_user": {
54 "id": "bd263c",
55 "links": {
56 "self": "http://example.com/identity/v3/users/bd263c"
57 }
58 }
59 },
60 "user": {
61 "domain": {
62 "id": "1789d1",
63 "links": {
64 "self": "http://example.com/identity/v3/domains/1789d1"
65 },
66 "name": "example.com"
67 },
68 "email": "joe@example.com",
69 "id": "0ca8f6",
70 "links": {
71 "self": "http://example.com/identity/v3/users/0ca8f6"
72 },
73 "name": "Joe"
74 }
75 }
76}`)
jrperritt0bc55782016-07-27 13:50:14 -050077 })
78
jrperrittc8834c12016-08-03 16:06:16 -050079 var actual trusts.TokenExt
80 err := tokens.Create(&client, options).ExtractInto(&actual)
jrperritt0bc55782016-07-27 13:50:14 -050081 if err != nil {
82 t.Errorf("Create returned an error: %v", err)
83 }
jrperrittc8834c12016-08-03 16:06:16 -050084 expected := trusts.TokenExt{
85 Token: trusts.Token{
86 Token: tokens.Token{
87 ExpiresAt: gophercloud.JSONRFC3339Milli(time.Date(2013, 02, 27, 18, 30, 59, 999999000, time.UTC)),
88 },
89 Trust: trusts.Trust{
90 ID: "fe0aef",
91 Impersonation: false,
92 TrusteeUser: trusts.TrusteeUser{
93 ID: "0ca8f6",
94 },
95 TrustorUser: trusts.TrustorUser{
96 ID: "bd263c",
97 },
98 RedelegatedTrustID: "3ba234",
99 RedelegationCount: 2,
100 },
101 },
102 }
103 testhelper.AssertDeepEquals(t, expected, actual)
jrperritt0bc55782016-07-27 13:50:14 -0500104}