Added tokenInfo() method to Keystone API

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

Change-Id: Ia2f0def84d45616eb8c3464b7ba4f47fadfda50d
This commit is contained in:
Vitaly Kramskikh 2016-10-04 13:37:13 +03:00 committed by Corentin Ardeois
parent 8828ec6382
commit 9dabaecf11
4 changed files with 409 additions and 455 deletions

View File

@ -168,6 +168,25 @@ export default class Keystone extends AbstractService {
.then(([url, headers]) => this.http.httpRequest('DELETE', `${url}auth/tokens`, headers)); .then(([url, headers]) => this.http.httpRequest('DELETE', `${url}auth/tokens`, headers));
} }
/**
* Get information about a token.
*
* @param {String} token The authorization token.
* @returns {Promise.<T>} 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. * List the service catalog for the configured cloud.
* *

View File

@ -194,38 +194,71 @@ describe("Keystone", () => {
done(); done();
}); });
}); });
});
describe("catalogList()", () => { describe("tokenInfo()", () => {
let keystone = null; let keystone = null;
beforeEach(() => { beforeEach(() => {
keystone = new Keystone(config.clouds.devstack); keystone = new Keystone(config.clouds.devstack);
}); });
it("should list a catalog.", (done) => { it("should retrieve info about a token.", (done) => {
keystone keystone
.tokenIssue() .tokenIssue()
.then((token) => { .then((token) => {
return keystone.catalogList(token); return keystone.tokenInfo(token);
}) })
.then((catalog) => { .then((info) => {
expect(catalog.length).not.toBe(0); expect('token' in info).toBe(true);
done(); done();
}) })
.catch((response) => response.json() .catch((response) => response.json()
.then((body) => done.fail(JSON.stringify(body))) .then((body) => done.fail(JSON.stringify(body)))
); );
}); });
it("should error if not authenticated.", (done) => { it("should throw an exception if invalid token is provided.", (done) => {
keystone keystone
.catalogList() .tokenRevoke('not_a_valid_token')
.then((response) => done.fail(response)) .then((response) => done.fail(response))
.catch((error) => { .catch((error) => {
expect(error).not.toBeNull(); expect(error).not.toBeNull();
done(); 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();
});
}); });
}); });
}); });

View File

@ -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. * Build a new FetchMock configuration for the root endpoint.
* *
@ -106,270 +373,7 @@ function tokenIssue() {
'X-Subject-Token': 'test_token' 'X-Subject-Token': 'test_token'
}, },
body: { body: {
token: { token: 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: [
{
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"
}
} }
} }
}; };
@ -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) { function catalogList(token) {
return { return {
method: 'GET', method: 'GET',
@ -397,167 +417,7 @@ function catalogList(token) {
'X-Auth-Token': token 'X-Auth-Token': token
}, },
response: { response: {
catalog: [{ catalog: 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"
}]
} }
}; };
} }
@ -565,7 +425,8 @@ function catalogList(token) {
export { export {
cloudConfig as config, cloudConfig as config,
rootResponse as root, rootResponse as root,
tokenIssue as tokenIssue, tokenIssue,
tokenRevoke as tokenRevoke, tokenRevoke,
tokenInfo,
catalogList, catalogList,
}; };

View File

@ -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()", () => { describe("catalogList()", () => {
let keystone = null; let keystone = null;