diff --git a/src/keystone.js b/src/keystone.js index 8790097..f678f7c 100644 --- a/src/keystone.js +++ b/src/keystone.js @@ -168,6 +168,25 @@ export default class Keystone extends AbstractService { .then(([url, headers]) => this.http.httpRequest('DELETE', `${url}auth/tokens`, headers)); } + /** + * Get information about a token. + * + * @param {String} token The authorization token. + * @returns {Promise.} A promise which will resolve with information about the token. + */ + tokenInfo(token) { + return Promise + .all([this.serviceEndpoint(), token]) + .then(([url, token]) => { + return [url, { + 'X-Subject-Token': token, + 'X-Auth-Token': token + }]; + }) + .then(([url, headers]) => this.http.httpRequest('GET', `${url}auth/tokens`, headers)) + .then((response) => response.json()); + } + /** * List the service catalog for the configured cloud. * diff --git a/test/functional/keystoneTest.js b/test/functional/keystoneTest.js index 11a5e92..93ac168 100644 --- a/test/functional/keystoneTest.js +++ b/test/functional/keystoneTest.js @@ -194,38 +194,71 @@ describe("Keystone", () => { done(); }); }); + }); - describe("catalogList()", () => { - let keystone = null; + describe("tokenInfo()", () => { + let keystone = null; - beforeEach(() => { - keystone = new Keystone(config.clouds.devstack); - }); + beforeEach(() => { + keystone = new Keystone(config.clouds.devstack); + }); - it("should list a catalog.", (done) => { - keystone - .tokenIssue() - .then((token) => { - return keystone.catalogList(token); - }) - .then((catalog) => { - expect(catalog.length).not.toBe(0); - done(); - }) - .catch((response) => response.json() - .then((body) => done.fail(JSON.stringify(body))) - ); - }); + it("should retrieve info about a token.", (done) => { + keystone + .tokenIssue() + .then((token) => { + return keystone.tokenInfo(token); + }) + .then((info) => { + expect('token' in info).toBe(true); + done(); + }) + .catch((response) => response.json() + .then((body) => done.fail(JSON.stringify(body))) + ); + }); - it("should error if not authenticated.", (done) => { - keystone - .catalogList() - .then((response) => done.fail(response)) - .catch((error) => { - expect(error).not.toBeNull(); - done(); - }); - }); + it("should throw an exception if invalid token is provided.", (done) => { + keystone + .tokenRevoke('not_a_valid_token') + .then((response) => done.fail(response)) + .catch((error) => { + expect(error).not.toBeNull(); + done(); + }); + }); + }); + + describe("catalogList()", () => { + let keystone = null; + + beforeEach(() => { + keystone = new Keystone(config.clouds.devstack); + }); + + it("should list a catalog.", (done) => { + keystone + .tokenIssue() + .then((token) => { + return keystone.catalogList(token); + }) + .then((catalog) => { + expect(catalog.length).not.toBe(0); + done(); + }) + .catch((response) => response.json() + .then((body) => done.fail(JSON.stringify(body))) + ); + }); + + it("should error if not authenticated.", (done) => { + keystone + .catalogList() + .then((response) => done.fail(response)) + .catch((error) => { + expect(error).not.toBeNull(); + done(); + }); }); }); }); diff --git a/test/unit/helpers/data/keystone.js b/test/unit/helpers/data/keystone.js index e10d082..12eedb3 100644 --- a/test/unit/helpers/data/keystone.js +++ b/test/unit/helpers/data/keystone.js @@ -34,6 +34,273 @@ const cloudConfig = { } }; +const catalogListData = [ + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99/identity_v2_admin", + region: "RegionOne", + interface: "admin", + id: "940664e070864b638dfafc53cfcbe887" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99/identity", + region: "RegionOne", + interface: "internal", + id: "c3707565bccb407c888040fa9b7e77b0" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99/identity", + region: "RegionOne", + interface: "public", + id: "fb28f261810449ea98b2df646b847a74" + } + ], + type: "identity", + id: "0599684d07a145659fa858c1deb4e885", + name: "keystone" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "internal", + id: "611a5108ef0b4f999ad439b0e1abd9da" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "public", + id: "ae08047e33d848c8b1c77f99bc572e22" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "admin", + id: "e26c6757baa549469772e16e03c051b8" + } + ], + type: "volumev3", + id: "1092f88a41c64fc7b0331fce96e7df6c", + name: "cinderv3" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "public", + id: "14ad1642b0874816a7ff08eb0e24be87" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "internal", + id: "8bb7b28802d44e9d80fbb358a3e133af" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "admin", + id: "c271745ff29c4c9d829ab3187d41cab7" + } + ], + type: "volume", + id: "5067360b6f264558945b7d2c312dd126", + name: "cinder" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:9292", + region: "RegionOne", + interface: "admin", + id: "0b8b5f0f14904136ab5a4f83f27ec49a" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:9292", + region: "RegionOne", + interface: "internal", + id: "97c90e43e1fe473b85ef47627006dcdd" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:9292", + region: "RegionOne", + interface: "public", + id: "ee114418c77a45d2a3cc28240dc4281d" + } + ], + type: "image", + id: "6512ca68fbd543928768201198cd7e42", + name: "glance" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:8774/v2.1", + region: "RegionOne", + interface: "internal", + id: "14129d81da0e44abae0c082c535b58cc" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8774/v2.1", + region: "RegionOne", + interface: "public", + id: "be681632633d4a62a781148c2fedd6aa" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8774/v2.1", + region: "RegionOne", + interface: "admin", + id: "f8979efb0903442a9068d57fce4eafb2" + } + ], + type: "compute", + id: "6d3dd68ae2224fd39503342220b5d2c2", + name: "nova" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "admin", + id: "308f5ed663a7417db3f078f7e3b66db8" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "public", + id: "9f08e41e8156498ba01b5cc83cc9e1da" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "internal", + id: "b855d4c048f1468f9df5a9950ae811c6" + } + ], + type: "compute_legacy", + id: "8ca07a04d03145a094c404b5edf70c18", + name: "nova_legacy" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "internal", + id: "2b6e28e0aade41b5b80baa9012e54ca4" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "admin", + id: "79c96252a8ab4c7181ef4fe97237c314" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", + region: "RegionOne", + interface: "public", + id: "8d4cbc86845a4ecb90f19903636205a7" + } + ], + type: "volumev2", + id: "a7967e90d1044b1fa6d80b033f1da510", + name: "cinderv2" + }, + { + endpoints: [ + { + region_id: "RegionOne", + url: "http://192.168.99.99:9696/", + region: "RegionOne", + interface: "public", + id: "7033fa4ebed74e3fa51753162150a1f2" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:9696/", + region: "RegionOne", + interface: "internal", + id: "7aa942d402a34d4c90454b9d84285855" + }, + { + region_id: "RegionOne", + url: "http://192.168.99.99:9696/", + region: "RegionOne", + interface: "admin", + id: "bd8db1bafe41489bbbc45641e525ee7d" + } + ], + type: "network", + id: "f36b9e68ef114769b85024513ee61047", + name: "neutron" + } +]; + +const tokenInfoData = { + is_domain: false, + methods: [ + "password" + ], + roles: [ + { + id: "cfa75a8719f544e2903e5899785b0cf0", + name: "anotherrole" + }, + { + id: "5f8126fad6704a999a3651955c7d8219", + name: "Member" + } + ], + is_admin_project: false, + project: { + domain: { + id: "default", + name: "Default" + }, + id: "8b2aa635109f4d0ab355e18a269d341f", + name: "demo" + }, + catalog: catalogListData, + expires_at: "2016-08-19T18:04:11.157434Z", + user: { + domain: { + id: "default", + name: "Default" + }, + id: "d56a64f45da0450a826ede637be64304", + name: "demo" + }, + audit_ids: [ + "FtgqCjtuR2-V36loBJ8mxQ" + ], + issued_at: "2016-08-19T17:04:11.157456Z" +}; + /** * Build a new FetchMock configuration for the root endpoint. * @@ -106,270 +373,7 @@ function tokenIssue() { 'X-Subject-Token': 'test_token' }, body: { - token: { - is_domain: false, - methods: [ - "password" - ], - roles: [ - { - id: "cfa75a8719f544e2903e5899785b0cf0", - name: "anotherrole" - }, - { - id: "5f8126fad6704a999a3651955c7d8219", - name: "Member" - } - ], - is_admin_project: false, - project: { - domain: { - id: "default", - name: "Default" - }, - id: "8b2aa635109f4d0ab355e18a269d341f", - name: "demo" - }, - catalog: [ - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99/identity_v2_admin", - region: "RegionOne", - interface: "admin", - id: "940664e070864b638dfafc53cfcbe887" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99/identity", - region: "RegionOne", - interface: "internal", - id: "c3707565bccb407c888040fa9b7e77b0" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99/identity", - region: "RegionOne", - interface: "public", - id: "fb28f261810449ea98b2df646b847a74" - } - ], - type: "identity", - id: "0599684d07a145659fa858c1deb4e885", - name: "keystone" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "611a5108ef0b4f999ad439b0e1abd9da" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "ae08047e33d848c8b1c77f99bc572e22" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "e26c6757baa549469772e16e03c051b8" - } - ], - type: "volumev3", - id: "1092f88a41c64fc7b0331fce96e7df6c", - name: "cinderv3" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "14ad1642b0874816a7ff08eb0e24be87" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "8bb7b28802d44e9d80fbb358a3e133af" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "c271745ff29c4c9d829ab3187d41cab7" - } - ], - type: "volume", - id: "5067360b6f264558945b7d2c312dd126", - name: "cinder" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:9292", - region: "RegionOne", - interface: "admin", - id: "0b8b5f0f14904136ab5a4f83f27ec49a" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:9292", - region: "RegionOne", - interface: "internal", - id: "97c90e43e1fe473b85ef47627006dcdd" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:9292", - region: "RegionOne", - interface: "public", - id: "ee114418c77a45d2a3cc28240dc4281d" - } - ], - type: "image", - id: "6512ca68fbd543928768201198cd7e42", - name: "glance" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2.1", - region: "RegionOne", - interface: "internal", - id: "14129d81da0e44abae0c082c535b58cc" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2.1", - region: "RegionOne", - interface: "public", - id: "be681632633d4a62a781148c2fedd6aa" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2.1", - region: "RegionOne", - interface: "admin", - id: "f8979efb0903442a9068d57fce4eafb2" - } - ], - type: "compute", - id: "6d3dd68ae2224fd39503342220b5d2c2", - name: "nova" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "308f5ed663a7417db3f078f7e3b66db8" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "9f08e41e8156498ba01b5cc83cc9e1da" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "b855d4c048f1468f9df5a9950ae811c6" - } - ], - type: "compute_legacy", - id: "8ca07a04d03145a094c404b5edf70c18", - name: "nova_legacy" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "2b6e28e0aade41b5b80baa9012e54ca4" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "79c96252a8ab4c7181ef4fe97237c314" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "8d4cbc86845a4ecb90f19903636205a7" - } - ], - type: "volumev2", - id: "a7967e90d1044b1fa6d80b033f1da510", - name: "cinderv2" - }, - { - endpoints: [ - { - region_id: "RegionOne", - url: "http://192.168.99.99:9696/", - region: "RegionOne", - interface: "public", - id: "7033fa4ebed74e3fa51753162150a1f2" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:9696/", - region: "RegionOne", - interface: "internal", - id: "7aa942d402a34d4c90454b9d84285855" - }, - { - region_id: "RegionOne", - url: "http://192.168.99.99:9696/", - region: "RegionOne", - interface: "admin", - id: "bd8db1bafe41489bbbc45641e525ee7d" - } - ], - type: "network", - id: "f36b9e68ef114769b85024513ee61047", - name: "neutron" - } - ], - expires_at: "2016-08-19T18:04:11.157434Z", - user: { - domain: { - id: "default", - name: "Default" - }, - id: "d56a64f45da0450a826ede637be64304", - name: "demo" - }, - audit_ids: [ - "FtgqCjtuR2-V36loBJ8mxQ" - ], - issued_at: "2016-08-19T17:04:11.157456Z" - } + token: tokenInfoData } } }; @@ -389,6 +393,22 @@ function tokenRevoke(token, adminToken = null) { }; } +function tokenInfo(token) { + return { + method: 'GET', + matcher: 'http://192.168.99.99/identity_v2_admin/v3/auth/tokens', + response: { + status: 200, + headers: { + 'X-Subject-Token': token + }, + body: { + token: tokenInfoData + } + } + }; +} + function catalogList(token) { return { method: 'GET', @@ -397,167 +417,7 @@ function catalogList(token) { 'X-Auth-Token': token }, response: { - catalog: [{ - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99/identity_v2_admin", - region: "RegionOne", - interface: "admin", - id: "940664e070864b638dfafc53cfcbe887" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99/identity", - region: "RegionOne", - interface: "internal", - id: "c3707565bccb407c888040fa9b7e77b0" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99/identity", - region: "RegionOne", - interface: "public", - id: "fb28f261810449ea98b2df646b847a74" - }], type: "identity", id: "0599684d07a145659fa858c1deb4e885", name: "keystone" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "611a5108ef0b4f999ad439b0e1abd9da" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "ae08047e33d848c8b1c77f99bc572e22" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v3/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "e26c6757baa549469772e16e03c051b8" - }], type: "volumev3", id: "1092f88a41c64fc7b0331fce96e7df6c", name: "cinderv3" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "14ad1642b0874816a7ff08eb0e24be87" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "8bb7b28802d44e9d80fbb358a3e133af" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v1/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "c271745ff29c4c9d829ab3187d41cab7" - }], type: "volume", id: "5067360b6f264558945b7d2c312dd126", name: "cinder" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:9292", - region: "RegionOne", - interface: "admin", - id: "0b8b5f0f14904136ab5a4f83f27ec49a" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:9292", - region: "RegionOne", - interface: "internal", - id: "97c90e43e1fe473b85ef47627006dcdd" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:9292", - region: "RegionOne", - interface: "public", - id: "ee114418c77a45d2a3cc28240dc4281d" - }], type: "image", id: "6512ca68fbd543928768201198cd7e42", name: "glance" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2.1", - region: "RegionOne", - interface: "internal", - id: "14129d81da0e44abae0c082c535b58cc" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2.1", - region: "RegionOne", - interface: "public", - id: "be681632633d4a62a781148c2fedd6aa" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2.1", - region: "RegionOne", - interface: "admin", - id: "f8979efb0903442a9068d57fce4eafb2" - }], type: "compute", id: "6d3dd68ae2224fd39503342220b5d2c2", name: "nova" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "308f5ed663a7417db3f078f7e3b66db8" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "9f08e41e8156498ba01b5cc83cc9e1da" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8774/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "b855d4c048f1468f9df5a9950ae811c6" - }], type: "compute_legacy", id: "8ca07a04d03145a094c404b5edf70c18", name: "nova_legacy" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "internal", - id: "2b6e28e0aade41b5b80baa9012e54ca4" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "admin", - id: "79c96252a8ab4c7181ef4fe97237c314" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:8776/v2/8b2aa635109f4d0ab355e18a269d341f", - region: "RegionOne", - interface: "public", - id: "8d4cbc86845a4ecb90f19903636205a7" - }], type: "volumev2", id: "a7967e90d1044b1fa6d80b033f1da510", name: "cinderv2" - }, { - endpoints: [{ - region_id: "RegionOne", - url: "http://192.168.99.99:9696/", - region: "RegionOne", - interface: "public", - id: "7033fa4ebed74e3fa51753162150a1f2" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:9696/", - region: "RegionOne", - interface: "internal", - id: "7aa942d402a34d4c90454b9d84285855" - }, { - region_id: "RegionOne", - url: "http://192.168.99.99:9696/", - region: "RegionOne", - interface: "admin", - id: "bd8db1bafe41489bbbc45641e525ee7d" - }], type: "network", id: "f36b9e68ef114769b85024513ee61047", name: "neutron" - }] + catalog: catalogListData } }; } @@ -565,7 +425,8 @@ function catalogList(token) { export { cloudConfig as config, rootResponse as root, - tokenIssue as tokenIssue, - tokenRevoke as tokenRevoke, + tokenIssue, + tokenRevoke, + tokenInfo, catalogList, }; diff --git a/test/unit/keystoneTest.js b/test/unit/keystoneTest.js index e5cc610..647cd61 100644 --- a/test/unit/keystoneTest.js +++ b/test/unit/keystoneTest.js @@ -285,6 +285,47 @@ describe('Keystone', () => { }); }); + describe("tokenInfo()", () => { + let keystone = null; + + beforeEach(() => { + fetchMock.mock(mockData.root()); + keystone = new Keystone(mockData.config); + }); + + const token = 'test_token'; + + it("should return information about a token", (done) => { + fetchMock.mock(mockData.tokenInfo(token)); + keystone + .tokenInfo(token) + .then((info) => { + expect(info.token).toBeDefined(); + done(); + }) + .catch((error) => done.fail(error)); + }); + + it("Should not cache its results", (done) => { + let mockOptions = mockData.tokenInfo(token); + fetchMock.mock(mockOptions); + + keystone + .tokenInfo(token) + .then((info) => { + expect(info.token).toBeDefined(); + expect(fetchMock.calls(mockOptions.matcher).length).toEqual(1); + return keystone.tokenInfo(token); + }) + .then((info) => { + expect(info.token).toBeDefined(); + expect(fetchMock.calls(mockOptions.matcher).length).toEqual(2); + done(); + }) + .catch((error) => done.fail(error)); + }); + }); + describe("catalogList()", () => { let keystone = null;