github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v3/tokens/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/huaweicloud/golangsdk" 10 "github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens" 11 "github.com/huaweicloud/golangsdk/testhelper" 12 ) 13 14 const testTokenID = "130f6c17-420e-4a0b-97b0-0c9cf2a05f30" 15 16 // TokenOutput is a sample response to a Token call. 17 const TokenOutput = ` 18 { 19 "token":{ 20 "is_domain":false, 21 "methods":[ 22 "password" 23 ], 24 "roles":[ 25 { 26 "id":"434426788d5a451faf763b0e6db5aefb", 27 "name":"admin" 28 } 29 ], 30 "expires_at":"2017-06-03T02:19:49.000000Z", 31 "project":{ 32 "domain":{ 33 "id":"default", 34 "name":"Default" 35 }, 36 "id":"a99e9b4e620e4db09a2dfb6e42a01e66", 37 "name":"admin" 38 }, 39 "catalog":[ 40 { 41 "endpoints":[ 42 { 43 "url":"http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", 44 "interface":"admin", 45 "region":"RegionOne", 46 "region_id":"RegionOne", 47 "id":"3eac9e7588eb4eb2a4650cf5e079505f" 48 }, 49 { 50 "url":"http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", 51 "interface":"internal", 52 "region":"RegionOne", 53 "region_id":"RegionOne", 54 "id":"6b33fabc69c34ea782a3f6282582b59f" 55 }, 56 { 57 "url":"http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", 58 "interface":"public", 59 "region":"RegionOne", 60 "region_id":"RegionOne", 61 "id":"dae63c71bee24070a71f5425e7a916b5" 62 } 63 ], 64 "type":"compute", 65 "id":"17e0fa04647d4155a7933ee624dd66da", 66 "name":"nova" 67 }, 68 { 69 "endpoints":[ 70 { 71 "url":"http://127.0.0.1:35357/v3", 72 "interface":"admin", 73 "region":"RegionOne", 74 "region_id":"RegionOne", 75 "id":"0539aeff80954a0bb756cec496768d3d" 76 }, 77 { 78 "url":"http://127.0.0.1:5000/v3", 79 "interface":"public", 80 "region":"RegionOne", 81 "region_id":"RegionOne", 82 "id":"15bdf2d0853e4c939993d29548b1b56f" 83 }, 84 { 85 "url":"http://127.0.0.1:5000/v3", 86 "interface":"internal", 87 "region":"RegionOne", 88 "region_id":"RegionOne", 89 "id":"3b4423c54ba343c58226bc424cb11c4b" 90 } 91 ], 92 "type":"identity", 93 "id":"1cde0ea8cb3c49d8928cb172ca825ca5", 94 "name":"keystone" 95 } 96 ], 97 "user":{ 98 "domain":{ 99 "id":"default", 100 "name":"Default" 101 }, 102 "password_expires_at":null, 103 "name":"admin", 104 "id":"0fe36e73809d46aeae6705c39077b1b3" 105 }, 106 "audit_ids":[ 107 "ysSI0bEWR0Gmrp4LHL9LFw" 108 ], 109 "issued_at":"2017-06-03T01:19:49.000000Z" 110 } 111 }` 112 113 var expectedTokenTime, _ = time.Parse(golangsdk.RFC3339Milli, 114 "2017-06-03T02:19:49.000000Z") 115 var ExpectedToken = tokens.Token{ 116 ID: testTokenID, 117 ExpiresAt: expectedTokenTime, 118 } 119 120 var catalogEntry1 = tokens.CatalogEntry{ 121 ID: "17e0fa04647d4155a7933ee624dd66da", 122 Name: "nova", 123 Type: "compute", 124 Endpoints: []tokens.Endpoint{ 125 { 126 ID: "3eac9e7588eb4eb2a4650cf5e079505f", 127 Region: "RegionOne", 128 Interface: "admin", 129 URL: "http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", 130 }, 131 { 132 ID: "6b33fabc69c34ea782a3f6282582b59f", 133 Region: "RegionOne", 134 Interface: "internal", 135 URL: "http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", 136 }, 137 { 138 ID: "dae63c71bee24070a71f5425e7a916b5", 139 Region: "RegionOne", 140 Interface: "public", 141 URL: "http://127.0.0.1:8774/v2.1/a99e9b4e620e4db09a2dfb6e42a01e66", 142 }, 143 }, 144 } 145 var catalogEntry2 = tokens.CatalogEntry{ 146 ID: "1cde0ea8cb3c49d8928cb172ca825ca5", 147 Name: "keystone", 148 Type: "identity", 149 Endpoints: []tokens.Endpoint{ 150 { 151 ID: "0539aeff80954a0bb756cec496768d3d", 152 Region: "RegionOne", 153 Interface: "admin", 154 URL: "http://127.0.0.1:35357/v3", 155 }, 156 { 157 ID: "15bdf2d0853e4c939993d29548b1b56f", 158 Region: "RegionOne", 159 Interface: "public", 160 URL: "http://127.0.0.1:5000/v3", 161 }, 162 { 163 ID: "3b4423c54ba343c58226bc424cb11c4b", 164 Region: "RegionOne", 165 Interface: "internal", 166 URL: "http://127.0.0.1:5000/v3", 167 }, 168 }, 169 } 170 171 // ExpectedServiceCatalog contains expected service extracted from token response. 172 var ExpectedServiceCatalog = tokens.ServiceCatalog{ 173 Entries: []tokens.CatalogEntry{catalogEntry1, catalogEntry2}, 174 } 175 176 var domain = tokens.Domain{ 177 ID: "default", 178 Name: "Default", 179 } 180 181 // ExpectedUser contains expected user extracted from token response. 182 var ExpectedUser = tokens.User{ 183 Domain: domain, 184 ID: "0fe36e73809d46aeae6705c39077b1b3", 185 Name: "admin", 186 } 187 188 var role = tokens.Role{ 189 ID: "434426788d5a451faf763b0e6db5aefb", 190 Name: "admin", 191 } 192 193 // ExpectedRoles contains expected roles extracted from token response. 194 var ExpectedRoles = []tokens.Role{role} 195 196 // ExpectedProject contains expected project extracted from token response. 197 var ExpectedProject = tokens.Project{ 198 Domain: domain, 199 ID: "a99e9b4e620e4db09a2dfb6e42a01e66", 200 Name: "admin", 201 } 202 203 func getGetResult(t *testing.T) tokens.GetResult { 204 result := tokens.GetResult{} 205 result.Header = http.Header{ 206 "X-Subject-Token": []string{testTokenID}, 207 } 208 err := json.Unmarshal([]byte(TokenOutput), &result.Body) 209 testhelper.AssertNoErr(t, err) 210 return result 211 }