Browse Source

Added tokenInfo() method to Keystone API

Also fixed nesting in keystone functional tests and deduplicated
mock data for Keystone.

Change-Id: Ia2f0def84d45616eb8c3464b7ba4f47fadfda50d
Vitaly Kramskikh 2 years ago
parent
commit
9dabaecf11
4 changed files with 412 additions and 458 deletions
  1. 19
    0
      src/keystone.js
  2. 64
    31
      test/functional/keystoneTest.js
  3. 288
    427
      test/unit/helpers/data/keystone.js
  4. 41
    0
      test/unit/keystoneTest.js

+ 19
- 0
src/keystone.js View File

@@ -168,6 +168,25 @@ export default class Keystone extends AbstractService {
168 168
       .then(([url, headers]) => this.http.httpRequest('DELETE', `${url}auth/tokens`, headers));
169 169
   }
170 170
 
171
+  /**
172
+   * Get information about a token.
173
+   *
174
+   * @param {String} token The authorization token.
175
+   * @returns {Promise.<T>} A promise which will resolve with information about the token.
176
+   */
177
+  tokenInfo(token) {
178
+    return Promise
179
+      .all([this.serviceEndpoint(), token])
180
+      .then(([url, token]) => {
181
+        return [url, {
182
+          'X-Subject-Token': token,
183
+          'X-Auth-Token': token
184
+        }];
185
+      })
186
+      .then(([url, headers]) => this.http.httpRequest('GET', `${url}auth/tokens`, headers))
187
+      .then((response) => response.json());
188
+  }
189
+
171 190
   /**
172 191
    * List the service catalog for the configured cloud.
173 192
    *

+ 64
- 31
test/functional/keystoneTest.js View File

@@ -194,38 +194,71 @@ describe("Keystone", () => {
194 194
           done();
195 195
         });
196 196
     });
197
+  });
198
+
199
+  describe("tokenInfo()", () => {
200
+    let keystone = null;
201
+
202
+    beforeEach(() => {
203
+      keystone = new Keystone(config.clouds.devstack);
204
+    });
205
+
206
+    it("should retrieve info about a token.", (done) => {
207
+      keystone
208
+        .tokenIssue()
209
+        .then((token) => {
210
+          return keystone.tokenInfo(token);
211
+        })
212
+        .then((info) => {
213
+          expect('token' in info).toBe(true);
214
+          done();
215
+        })
216
+        .catch((response) => response.json()
217
+          .then((body) => done.fail(JSON.stringify(body)))
218
+        );
219
+    });
220
+
221
+    it("should throw an exception if invalid token is provided.", (done) => {
222
+      keystone
223
+        .tokenRevoke('not_a_valid_token')
224
+        .then((response) => done.fail(response))
225
+        .catch((error) => {
226
+          expect(error).not.toBeNull();
227
+          done();
228
+        });
229
+    });
230
+  });
231
+
232
+  describe("catalogList()", () => {
233
+    let keystone = null;
234
+
235
+    beforeEach(() => {
236
+      keystone = new Keystone(config.clouds.devstack);
237
+    });
238
+
239
+    it("should list a catalog.", (done) => {
240
+      keystone
241
+        .tokenIssue()
242
+        .then((token) => {
243
+          return keystone.catalogList(token);
244
+        })
245
+        .then((catalog) => {
246
+          expect(catalog.length).not.toBe(0);
247
+          done();
248
+        })
249
+        .catch((response) => response.json()
250
+          .then((body) => done.fail(JSON.stringify(body)))
251
+        );
252
+    });
197 253
 
198
-    describe("catalogList()", () => {
199
-      let keystone = null;
200
-
201
-      beforeEach(() => {
202
-        keystone = new Keystone(config.clouds.devstack);
203
-      });
204
-
205
-      it("should list a catalog.", (done) => {
206
-        keystone
207
-          .tokenIssue()
208
-          .then((token) => {
209
-            return keystone.catalogList(token);
210
-          })
211
-          .then((catalog) => {
212
-            expect(catalog.length).not.toBe(0);
213
-            done();
214
-          })
215
-          .catch((response) => response.json()
216
-            .then((body) => done.fail(JSON.stringify(body)))
217
-          );
218
-      });
219
-
220
-      it("should error if not authenticated.", (done) => {
221
-        keystone
222
-          .catalogList()
223
-          .then((response) => done.fail(response))
224
-          .catch((error) => {
225
-            expect(error).not.toBeNull();
226
-            done();
227
-          });
228
-      });
254
+    it("should error if not authenticated.", (done) => {
255
+      keystone
256
+        .catalogList()
257
+        .then((response) => done.fail(response))
258
+        .catch((error) => {
259
+          expect(error).not.toBeNull();
260
+          done();
261
+        });
229 262
     });
230 263
   });
231 264
 });

+ 288
- 427
test/unit/helpers/data/keystone.js View File

@@ -34,6 +34,273 @@ const cloudConfig = {
34 34
   }
35 35
 };
36 36
 
37
+const catalogListData = [
38
+  {
39
+    endpoints: [
40
+      {
41
+        region_id: "RegionOne",
42
+        url: "http://192.168.99.99/identity_v2_admin",
43
+        region: "RegionOne",
44
+        interface: "admin",
45
+        id: "940664e070864b638dfafc53cfcbe887"
46
+      },
47
+      {
48
+        region_id: "RegionOne",
49
+        url: "http://192.168.99.99/identity",
50
+        region: "RegionOne",
51
+        interface: "internal",
52
+        id: "c3707565bccb407c888040fa9b7e77b0"
53
+      },
54
+      {
55
+        region_id: "RegionOne",
56
+        url: "http://192.168.99.99/identity",
57
+        region: "RegionOne",
58
+        interface: "public",
59
+        id: "fb28f261810449ea98b2df646b847a74"
60
+      }
61
+    ],
62
+    type: "identity",
63
+    id: "0599684d07a145659fa858c1deb4e885",
64
+    name: "keystone"
65
+  },
66
+  {
67
+    endpoints: [
68
+      {
69
+        region_id: "RegionOne",
70
+        url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
71
+        region: "RegionOne",
72
+        interface: "internal",
73
+        id: "611a5108ef0b4f999ad439b0e1abd9da"
74
+      },
75
+      {
76
+        region_id: "RegionOne",
77
+        url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
78
+        region: "RegionOne",
79
+        interface: "public",
80
+        id: "ae08047e33d848c8b1c77f99bc572e22"
81
+      },
82
+      {
83
+        region_id: "RegionOne",
84
+        url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
85
+        region: "RegionOne",
86
+        interface: "admin",
87
+        id: "e26c6757baa549469772e16e03c051b8"
88
+      }
89
+    ],
90
+    type: "volumev3",
91
+    id: "1092f88a41c64fc7b0331fce96e7df6c",
92
+    name: "cinderv3"
93
+  },
94
+  {
95
+    endpoints: [
96
+      {
97
+        region_id: "RegionOne",
98
+        url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
99
+        region: "RegionOne",
100
+        interface: "public",
101
+        id: "14ad1642b0874816a7ff08eb0e24be87"
102
+      },
103
+      {
104
+        region_id: "RegionOne",
105
+        url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
106
+        region: "RegionOne",
107
+        interface: "internal",
108
+        id: "8bb7b28802d44e9d80fbb358a3e133af"
109
+      },
110
+      {
111
+        region_id: "RegionOne",
112
+        url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
113
+        region: "RegionOne",
114
+        interface: "admin",
115
+        id: "c271745ff29c4c9d829ab3187d41cab7"
116
+      }
117
+    ],
118
+    type: "volume",
119
+    id: "5067360b6f264558945b7d2c312dd126",
120
+    name: "cinder"
121
+  },
122
+  {
123
+    endpoints: [
124
+      {
125
+        region_id: "RegionOne",
126
+        url: "http://192.168.99.99:9292",
127
+        region: "RegionOne",
128
+        interface: "admin",
129
+        id: "0b8b5f0f14904136ab5a4f83f27ec49a"
130
+      },
131
+      {
132
+        region_id: "RegionOne",
133
+        url: "http://192.168.99.99:9292",
134
+        region: "RegionOne",
135
+        interface: "internal",
136
+        id: "97c90e43e1fe473b85ef47627006dcdd"
137
+      },
138
+      {
139
+        region_id: "RegionOne",
140
+        url: "http://192.168.99.99:9292",
141
+        region: "RegionOne",
142
+        interface: "public",
143
+        id: "ee114418c77a45d2a3cc28240dc4281d"
144
+      }
145
+    ],
146
+    type: "image",
147
+    id: "6512ca68fbd543928768201198cd7e42",
148
+    name: "glance"
149
+  },
150
+  {
151
+    endpoints: [
152
+      {
153
+        region_id: "RegionOne",
154
+        url: "http://192.168.99.99:8774/v2.1",
155
+        region: "RegionOne",
156
+        interface: "internal",
157
+        id: "14129d81da0e44abae0c082c535b58cc"
158
+      },
159
+      {
160
+        region_id: "RegionOne",
161
+        url: "http://192.168.99.99:8774/v2.1",
162
+        region: "RegionOne",
163
+        interface: "public",
164
+        id: "be681632633d4a62a781148c2fedd6aa"
165
+      },
166
+      {
167
+        region_id: "RegionOne",
168
+        url: "http://192.168.99.99:8774/v2.1",
169
+        region: "RegionOne",
170
+        interface: "admin",
171
+        id: "f8979efb0903442a9068d57fce4eafb2"
172
+      }
173
+    ],
174
+    type: "compute",
175
+    id: "6d3dd68ae2224fd39503342220b5d2c2",
176
+    name: "nova"
177
+  },
178
+  {
179
+    endpoints: [
180
+      {
181
+        region_id: "RegionOne",
182
+        url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
183
+        region: "RegionOne",
184
+        interface: "admin",
185
+        id: "308f5ed663a7417db3f078f7e3b66db8"
186
+      },
187
+      {
188
+        region_id: "RegionOne",
189
+        url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
190
+        region: "RegionOne",
191
+        interface: "public",
192
+        id: "9f08e41e8156498ba01b5cc83cc9e1da"
193
+      },
194
+      {
195
+        region_id: "RegionOne",
196
+        url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
197
+        region: "RegionOne",
198
+        interface: "internal",
199
+        id: "b855d4c048f1468f9df5a9950ae811c6"
200
+      }
201
+    ],
202
+    type: "compute_legacy",
203
+    id: "8ca07a04d03145a094c404b5edf70c18",
204
+    name: "nova_legacy"
205
+  },
206
+  {
207
+    endpoints: [
208
+      {
209
+        region_id: "RegionOne",
210
+        url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
211
+        region: "RegionOne",
212
+        interface: "internal",
213
+        id: "2b6e28e0aade41b5b80baa9012e54ca4"
214
+      },
215
+      {
216
+        region_id: "RegionOne",
217
+        url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
218
+        region: "RegionOne",
219
+        interface: "admin",
220
+        id: "79c96252a8ab4c7181ef4fe97237c314"
221
+      },
222
+      {
223
+        region_id: "RegionOne",
224
+        url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
225
+        region: "RegionOne",
226
+        interface: "public",
227
+        id: "8d4cbc86845a4ecb90f19903636205a7"
228
+      }
229
+    ],
230
+    type: "volumev2",
231
+    id: "a7967e90d1044b1fa6d80b033f1da510",
232
+    name: "cinderv2"
233
+  },
234
+  {
235
+    endpoints: [
236
+      {
237
+        region_id: "RegionOne",
238
+        url: "http://192.168.99.99:9696/",
239
+        region: "RegionOne",
240
+        interface: "public",
241
+        id: "7033fa4ebed74e3fa51753162150a1f2"
242
+      },
243
+      {
244
+        region_id: "RegionOne",
245
+        url: "http://192.168.99.99:9696/",
246
+        region: "RegionOne",
247
+        interface: "internal",
248
+        id: "7aa942d402a34d4c90454b9d84285855"
249
+      },
250
+      {
251
+        region_id: "RegionOne",
252
+        url: "http://192.168.99.99:9696/",
253
+        region: "RegionOne",
254
+        interface: "admin",
255
+        id: "bd8db1bafe41489bbbc45641e525ee7d"
256
+      }
257
+    ],
258
+    type: "network",
259
+    id: "f36b9e68ef114769b85024513ee61047",
260
+    name: "neutron"
261
+  }
262
+];
263
+
264
+const tokenInfoData = {
265
+  is_domain: false,
266
+  methods: [
267
+    "password"
268
+  ],
269
+  roles: [
270
+    {
271
+      id: "cfa75a8719f544e2903e5899785b0cf0",
272
+      name: "anotherrole"
273
+    },
274
+    {
275
+      id: "5f8126fad6704a999a3651955c7d8219",
276
+      name: "Member"
277
+    }
278
+  ],
279
+  is_admin_project: false,
280
+  project: {
281
+    domain: {
282
+      id: "default",
283
+      name: "Default"
284
+    },
285
+    id: "8b2aa635109f4d0ab355e18a269d341f",
286
+    name: "demo"
287
+  },
288
+  catalog: catalogListData,
289
+  expires_at: "2016-08-19T18:04:11.157434Z",
290
+  user: {
291
+    domain: {
292
+      id: "default",
293
+      name: "Default"
294
+    },
295
+    id: "d56a64f45da0450a826ede637be64304",
296
+    name: "demo"
297
+  },
298
+  audit_ids: [
299
+    "FtgqCjtuR2-V36loBJ8mxQ"
300
+  ],
301
+  issued_at: "2016-08-19T17:04:11.157456Z"
302
+};
303
+
37 304
 /**
38 305
  * Build a new FetchMock configuration for the root endpoint.
39 306
  *
@@ -106,270 +373,7 @@ function tokenIssue() {
106 373
         'X-Subject-Token': 'test_token'
107 374
       },
108 375
       body: {
109
-        token: {
110
-          is_domain: false,
111
-          methods: [
112
-            "password"
113
-          ],
114
-          roles: [
115
-            {
116
-              id: "cfa75a8719f544e2903e5899785b0cf0",
117
-              name: "anotherrole"
118
-            },
119
-            {
120
-              id: "5f8126fad6704a999a3651955c7d8219",
121
-              name: "Member"
122
-            }
123
-          ],
124
-          is_admin_project: false,
125
-          project: {
126
-            domain: {
127
-              id: "default",
128
-              name: "Default"
129
-            },
130
-            id: "8b2aa635109f4d0ab355e18a269d341f",
131
-            name: "demo"
132
-          },
133
-          catalog: [
134
-            {
135
-              endpoints: [
136
-                {
137
-                  region_id: "RegionOne",
138
-                  url: "http://192.168.99.99/identity_v2_admin",
139
-                  region: "RegionOne",
140
-                  interface: "admin",
141
-                  id: "940664e070864b638dfafc53cfcbe887"
142
-                },
143
-                {
144
-                  region_id: "RegionOne",
145
-                  url: "http://192.168.99.99/identity",
146
-                  region: "RegionOne",
147
-                  interface: "internal",
148
-                  id: "c3707565bccb407c888040fa9b7e77b0"
149
-                },
150
-                {
151
-                  region_id: "RegionOne",
152
-                  url: "http://192.168.99.99/identity",
153
-                  region: "RegionOne",
154
-                  interface: "public",
155
-                  id: "fb28f261810449ea98b2df646b847a74"
156
-                }
157
-              ],
158
-              type: "identity",
159
-              id: "0599684d07a145659fa858c1deb4e885",
160
-              name: "keystone"
161
-            },
162
-            {
163
-              endpoints: [
164
-                {
165
-                  region_id: "RegionOne",
166
-                  url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
167
-                  region: "RegionOne",
168
-                  interface: "internal",
169
-                  id: "611a5108ef0b4f999ad439b0e1abd9da"
170
-                },
171
-                {
172
-                  region_id: "RegionOne",
173
-                  url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
174
-                  region: "RegionOne",
175
-                  interface: "public",
176
-                  id: "ae08047e33d848c8b1c77f99bc572e22"
177
-                },
178
-                {
179
-                  region_id: "RegionOne",
180
-                  url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
181
-                  region: "RegionOne",
182
-                  interface: "admin",
183
-                  id: "e26c6757baa549469772e16e03c051b8"
184
-                }
185
-              ],
186
-              type: "volumev3",
187
-              id: "1092f88a41c64fc7b0331fce96e7df6c",
188
-              name: "cinderv3"
189
-            },
190
-            {
191
-              endpoints: [
192
-                {
193
-                  region_id: "RegionOne",
194
-                  url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
195
-                  region: "RegionOne",
196
-                  interface: "public",
197
-                  id: "14ad1642b0874816a7ff08eb0e24be87"
198
-                },
199
-                {
200
-                  region_id: "RegionOne",
201
-                  url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
202
-                  region: "RegionOne",
203
-                  interface: "internal",
204
-                  id: "8bb7b28802d44e9d80fbb358a3e133af"
205
-                },
206
-                {
207
-                  region_id: "RegionOne",
208
-                  url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
209
-                  region: "RegionOne",
210
-                  interface: "admin",
211
-                  id: "c271745ff29c4c9d829ab3187d41cab7"
212
-                }
213
-              ],
214
-              type: "volume",
215
-              id: "5067360b6f264558945b7d2c312dd126",
216
-              name: "cinder"
217
-            },
218
-            {
219
-              endpoints: [
220
-                {
221
-                  region_id: "RegionOne",
222
-                  url: "http://192.168.99.99:9292",
223
-                  region: "RegionOne",
224
-                  interface: "admin",
225
-                  id: "0b8b5f0f14904136ab5a4f83f27ec49a"
226
-                },
227
-                {
228
-                  region_id: "RegionOne",
229
-                  url: "http://192.168.99.99:9292",
230
-                  region: "RegionOne",
231
-                  interface: "internal",
232
-                  id: "97c90e43e1fe473b85ef47627006dcdd"
233
-                },
234
-                {
235
-                  region_id: "RegionOne",
236
-                  url: "http://192.168.99.99:9292",
237
-                  region: "RegionOne",
238
-                  interface: "public",
239
-                  id: "ee114418c77a45d2a3cc28240dc4281d"
240
-                }
241
-              ],
242
-              type: "image",
243
-              id: "6512ca68fbd543928768201198cd7e42",
244
-              name: "glance"
245
-            },
246
-            {
247
-              endpoints: [
248
-                {
249
-                  region_id: "RegionOne",
250
-                  url: "http://192.168.99.99:8774/v2.1",
251
-                  region: "RegionOne",
252
-                  interface: "internal",
253
-                  id: "14129d81da0e44abae0c082c535b58cc"
254
-                },
255
-                {
256
-                  region_id: "RegionOne",
257
-                  url: "http://192.168.99.99:8774/v2.1",
258
-                  region: "RegionOne",
259
-                  interface: "public",
260
-                  id: "be681632633d4a62a781148c2fedd6aa"
261
-                },
262
-                {
263
-                  region_id: "RegionOne",
264
-                  url: "http://192.168.99.99:8774/v2.1",
265
-                  region: "RegionOne",
266
-                  interface: "admin",
267
-                  id: "f8979efb0903442a9068d57fce4eafb2"
268
-                }
269
-              ],
270
-              type: "compute",
271
-              id: "6d3dd68ae2224fd39503342220b5d2c2",
272
-              name: "nova"
273
-            },
274
-            {
275
-              endpoints: [
276
-                {
277
-                  region_id: "RegionOne",
278
-                  url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
279
-                  region: "RegionOne",
280
-                  interface: "admin",
281
-                  id: "308f5ed663a7417db3f078f7e3b66db8"
282
-                },
283
-                {
284
-                  region_id: "RegionOne",
285
-                  url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
286
-                  region: "RegionOne",
287
-                  interface: "public",
288
-                  id: "9f08e41e8156498ba01b5cc83cc9e1da"
289
-                },
290
-                {
291
-                  region_id: "RegionOne",
292
-                  url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
293
-                  region: "RegionOne",
294
-                  interface: "internal",
295
-                  id: "b855d4c048f1468f9df5a9950ae811c6"
296
-                }
297
-              ],
298
-              type: "compute_legacy",
299
-              id: "8ca07a04d03145a094c404b5edf70c18",
300
-              name: "nova_legacy"
301
-            },
302
-            {
303
-              endpoints: [
304
-                {
305
-                  region_id: "RegionOne",
306
-                  url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
307
-                  region: "RegionOne",
308
-                  interface: "internal",
309
-                  id: "2b6e28e0aade41b5b80baa9012e54ca4"
310
-                },
311
-                {
312
-                  region_id: "RegionOne",
313
-                  url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
314
-                  region: "RegionOne",
315
-                  interface: "admin",
316
-                  id: "79c96252a8ab4c7181ef4fe97237c314"
317
-                },
318
-                {
319
-                  region_id: "RegionOne",
320
-                  url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
321
-                  region: "RegionOne",
322
-                  interface: "public",
323
-                  id: "8d4cbc86845a4ecb90f19903636205a7"
324
-                }
325
-              ],
326
-              type: "volumev2",
327
-              id: "a7967e90d1044b1fa6d80b033f1da510",
328
-              name: "cinderv2"
329
-            },
330
-            {
331
-              endpoints: [
332
-                {
333
-                  region_id: "RegionOne",
334
-                  url: "http://192.168.99.99:9696/",
335
-                  region: "RegionOne",
336
-                  interface: "public",
337
-                  id: "7033fa4ebed74e3fa51753162150a1f2"
338
-                },
339
-                {
340
-                  region_id: "RegionOne",
341
-                  url: "http://192.168.99.99:9696/",
342
-                  region: "RegionOne",
343
-                  interface: "internal",
344
-                  id: "7aa942d402a34d4c90454b9d84285855"
345
-                },
346
-                {
347
-                  region_id: "RegionOne",
348
-                  url: "http://192.168.99.99:9696/",
349
-                  region: "RegionOne",
350
-                  interface: "admin",
351
-                  id: "bd8db1bafe41489bbbc45641e525ee7d"
352
-                }
353
-              ],
354
-              type: "network",
355
-              id: "f36b9e68ef114769b85024513ee61047",
356
-              name: "neutron"
357
-            }
358
-          ],
359
-          expires_at: "2016-08-19T18:04:11.157434Z",
360
-          user: {
361
-            domain: {
362
-              id: "default",
363
-              name: "Default"
364
-            },
365
-            id: "d56a64f45da0450a826ede637be64304",
366
-            name: "demo"
367
-          },
368
-          audit_ids: [
369
-            "FtgqCjtuR2-V36loBJ8mxQ"
370
-          ],
371
-          issued_at: "2016-08-19T17:04:11.157456Z"
372
-        }
376
+        token: tokenInfoData
373 377
       }
374 378
     }
375 379
   };
@@ -389,6 +393,22 @@ function tokenRevoke(token, adminToken = null) {
389 393
   };
390 394
 }
391 395
 
396
+function tokenInfo(token) {
397
+  return {
398
+    method: 'GET',
399
+    matcher: 'http://192.168.99.99/identity_v2_admin/v3/auth/tokens',
400
+    response: {
401
+      status: 200,
402
+      headers: {
403
+        'X-Subject-Token': token
404
+      },
405
+      body: {
406
+        token: tokenInfoData
407
+      }
408
+    }
409
+  };
410
+}
411
+
392 412
 function catalogList(token) {
393 413
   return {
394 414
     method: 'GET',
@@ -397,167 +417,7 @@ function catalogList(token) {
397 417
       'X-Auth-Token': token
398 418
     },
399 419
     response: {
400
-      catalog: [{
401
-        endpoints: [{
402
-          region_id: "RegionOne",
403
-          url: "http://192.168.99.99/identity_v2_admin",
404
-          region: "RegionOne",
405
-          interface: "admin",
406
-          id: "940664e070864b638dfafc53cfcbe887"
407
-        }, {
408
-          region_id: "RegionOne",
409
-          url: "http://192.168.99.99/identity",
410
-          region: "RegionOne",
411
-          interface: "internal",
412
-          id: "c3707565bccb407c888040fa9b7e77b0"
413
-        }, {
414
-          region_id: "RegionOne",
415
-          url: "http://192.168.99.99/identity",
416
-          region: "RegionOne",
417
-          interface: "public",
418
-          id: "fb28f261810449ea98b2df646b847a74"
419
-        }], type: "identity", id: "0599684d07a145659fa858c1deb4e885", name: "keystone"
420
-      }, {
421
-        endpoints: [{
422
-          region_id: "RegionOne",
423
-          url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
424
-          region: "RegionOne",
425
-          interface: "internal",
426
-          id: "611a5108ef0b4f999ad439b0e1abd9da"
427
-        }, {
428
-          region_id: "RegionOne",
429
-          url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
430
-          region: "RegionOne",
431
-          interface: "public",
432
-          id: "ae08047e33d848c8b1c77f99bc572e22"
433
-        }, {
434
-          region_id: "RegionOne",
435
-          url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f",
436
-          region: "RegionOne",
437
-          interface: "admin",
438
-          id: "e26c6757baa549469772e16e03c051b8"
439
-        }], type: "volumev3", id: "1092f88a41c64fc7b0331fce96e7df6c", name: "cinderv3"
440
-      }, {
441
-        endpoints: [{
442
-          region_id: "RegionOne",
443
-          url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
444
-          region: "RegionOne",
445
-          interface: "public",
446
-          id: "14ad1642b0874816a7ff08eb0e24be87"
447
-        }, {
448
-          region_id: "RegionOne",
449
-          url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
450
-          region: "RegionOne",
451
-          interface: "internal",
452
-          id: "8bb7b28802d44e9d80fbb358a3e133af"
453
-        }, {
454
-          region_id: "RegionOne",
455
-          url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f",
456
-          region: "RegionOne",
457
-          interface: "admin",
458
-          id: "c271745ff29c4c9d829ab3187d41cab7"
459
-        }], type: "volume", id: "5067360b6f264558945b7d2c312dd126", name: "cinder"
460
-      }, {
461
-        endpoints: [{
462
-          region_id: "RegionOne",
463
-          url: "http://192.168.99.99:9292",
464
-          region: "RegionOne",
465
-          interface: "admin",
466
-          id: "0b8b5f0f14904136ab5a4f83f27ec49a"
467
-        }, {
468
-          region_id: "RegionOne",
469
-          url: "http://192.168.99.99:9292",
470
-          region: "RegionOne",
471
-          interface: "internal",
472
-          id: "97c90e43e1fe473b85ef47627006dcdd"
473
-        }, {
474
-          region_id: "RegionOne",
475
-          url: "http://192.168.99.99:9292",
476
-          region: "RegionOne",
477
-          interface: "public",
478
-          id: "ee114418c77a45d2a3cc28240dc4281d"
479
-        }], type: "image", id: "6512ca68fbd543928768201198cd7e42", name: "glance"
480
-      }, {
481
-        endpoints: [{
482
-          region_id: "RegionOne",
483
-          url: "http://192.168.99.99:8774/v2.1",
484
-          region: "RegionOne",
485
-          interface: "internal",
486
-          id: "14129d81da0e44abae0c082c535b58cc"
487
-        }, {
488
-          region_id: "RegionOne",
489
-          url: "http://192.168.99.99:8774/v2.1",
490
-          region: "RegionOne",
491
-          interface: "public",
492
-          id: "be681632633d4a62a781148c2fedd6aa"
493
-        }, {
494
-          region_id: "RegionOne",
495
-          url: "http://192.168.99.99:8774/v2.1",
496
-          region: "RegionOne",
497
-          interface: "admin",
498
-          id: "f8979efb0903442a9068d57fce4eafb2"
499
-        }], type: "compute", id: "6d3dd68ae2224fd39503342220b5d2c2", name: "nova"
500
-      }, {
501
-        endpoints: [{
502
-          region_id: "RegionOne",
503
-          url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
504
-          region: "RegionOne",
505
-          interface: "admin",
506
-          id: "308f5ed663a7417db3f078f7e3b66db8"
507
-        }, {
508
-          region_id: "RegionOne",
509
-          url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
510
-          region: "RegionOne",
511
-          interface: "public",
512
-          id: "9f08e41e8156498ba01b5cc83cc9e1da"
513
-        }, {
514
-          region_id: "RegionOne",
515
-          url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f",
516
-          region: "RegionOne",
517
-          interface: "internal",
518
-          id: "b855d4c048f1468f9df5a9950ae811c6"
519
-        }], type: "compute_legacy", id: "8ca07a04d03145a094c404b5edf70c18", name: "nova_legacy"
520
-      }, {
521
-        endpoints: [{
522
-          region_id: "RegionOne",
523
-          url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
524
-          region: "RegionOne",
525
-          interface: "internal",
526
-          id: "2b6e28e0aade41b5b80baa9012e54ca4"
527
-        }, {
528
-          region_id: "RegionOne",
529
-          url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
530
-          region: "RegionOne",
531
-          interface: "admin",
532
-          id: "79c96252a8ab4c7181ef4fe97237c314"
533
-        }, {
534
-          region_id: "RegionOne",
535
-          url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f",
536
-          region: "RegionOne",
537
-          interface: "public",
538
-          id: "8d4cbc86845a4ecb90f19903636205a7"
539
-        }], type: "volumev2", id: "a7967e90d1044b1fa6d80b033f1da510", name: "cinderv2"
540
-      }, {
541
-        endpoints: [{
542
-          region_id: "RegionOne",
543
-          url: "http://192.168.99.99:9696/",
544
-          region: "RegionOne",
545
-          interface: "public",
546
-          id: "7033fa4ebed74e3fa51753162150a1f2"
547
-        }, {
548
-          region_id: "RegionOne",
549
-          url: "http://192.168.99.99:9696/",
550
-          region: "RegionOne",
551
-          interface: "internal",
552
-          id: "7aa942d402a34d4c90454b9d84285855"
553
-        }, {
554
-          region_id: "RegionOne",
555
-          url: "http://192.168.99.99:9696/",
556
-          region: "RegionOne",
557
-          interface: "admin",
558
-          id: "bd8db1bafe41489bbbc45641e525ee7d"
559
-        }], type: "network", id: "f36b9e68ef114769b85024513ee61047", name: "neutron"
560
-      }]
420
+      catalog: catalogListData
561 421
     }
562 422
   };
563 423
 }
@@ -565,7 +425,8 @@ function catalogList(token) {
565 425
 export {
566 426
   cloudConfig as config,
567 427
   rootResponse as root,
568
-  tokenIssue as tokenIssue,
569
-  tokenRevoke as tokenRevoke,
428
+  tokenIssue,
429
+  tokenRevoke,
430
+  tokenInfo,
570 431
   catalogList,
571 432
 };

+ 41
- 0
test/unit/keystoneTest.js View File

@@ -285,6 +285,47 @@ describe('Keystone', () => {
285 285
     });
286 286
   });
287 287
 
288
+  describe("tokenInfo()", () => {
289
+    let keystone = null;
290
+
291
+    beforeEach(() => {
292
+      fetchMock.mock(mockData.root());
293
+      keystone = new Keystone(mockData.config);
294
+    });
295
+
296
+    const token = 'test_token';
297
+
298
+    it("should return information about a token", (done) => {
299
+      fetchMock.mock(mockData.tokenInfo(token));
300
+      keystone
301
+        .tokenInfo(token)
302
+        .then((info) => {
303
+          expect(info.token).toBeDefined();
304
+          done();
305
+        })
306
+        .catch((error) => done.fail(error));
307
+    });
308
+
309
+    it("Should not cache its results", (done) => {
310
+      let mockOptions = mockData.tokenInfo(token);
311
+      fetchMock.mock(mockOptions);
312
+
313
+      keystone
314
+        .tokenInfo(token)
315
+        .then((info) => {
316
+          expect(info.token).toBeDefined();
317
+          expect(fetchMock.calls(mockOptions.matcher).length).toEqual(1);
318
+          return keystone.tokenInfo(token);
319
+        })
320
+        .then((info) => {
321
+          expect(info.token).toBeDefined();
322
+          expect(fetchMock.calls(mockOptions.matcher).length).toEqual(2);
323
+          done();
324
+        })
325
+        .catch((error) => done.fail(error));
326
+    });
327
+  });
328
+
288 329
   describe("catalogList()", () => {
289 330
     let keystone = null;
290 331
 

Loading…
Cancel
Save