Skip to content

Commit a61a23d

Browse files
authored
Merge pull request #382 from kuzzleio/6.1.0-proposal
# [6.1.0](https://github.com/kuzzleio/sdk-javascript/releases/tag/6.1.0) (2019-03-26) #### New features - [ [#381](#381) ] Add support for the new auth:refreshToken API route ([scottinet](https://github.com/scottinet)) #### Others - [ [#379](#379) ] [bugfix] keep internal errors on PartialErrors ([benoitvidis](https://github.com/benoitvidis)) - [ [#376](#376) ] [ci] Add empty .npmignore to push dist on npmjs ([alexandrebouthinon](https://github.com/alexandrebouthinon)) ---
2 parents 4588b2a + 8f38c6d commit a61a23d

File tree

9 files changed

+2430
-2216
lines changed

9 files changed

+2430
-2216
lines changed

features/features

features/steps/auth.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const {Given, When, Then} = require('cucumber');
2-
const should = require('should');
1+
const
2+
{Given, When, Then} = require('cucumber'),
3+
should = require('should'),
4+
retry = require('retry');
35

46
Given('I log in as {string}:{string}', async function (username, password) {
57
try {
@@ -15,11 +17,44 @@ Given('I log in as {string}:{string}', async function (username, password) {
1517
}
1618
});
1719

18-
1920
When('I logout', async function () {
2021
await this.kuzzle.auth.logout();
2122
});
2223

24+
When('I refresh the JWT', function (cb) {
25+
this.previousJwt = this.jwt;
26+
27+
// we have to wait for at least 1s: if we ask Kuzzle to refresh a JWT that
28+
// has been generated during the same second, then the new JWT will be
29+
// identical to the one being refreshed
30+
setTimeout(async () => {
31+
const token = await this.kuzzle.auth.refreshToken();
32+
this.jwt = token.jwt;
33+
cb();
34+
}, 1000);
35+
});
36+
37+
Then('the previous JWT is now invalid', function (cb) {
38+
// prevent false positives, just in case
39+
should(this.previousJwt).be.a.String().and.not.empty();
40+
should(this.previousJwt).not.eql(this.jwt);
41+
42+
const op = retry.operation({retries: 10, minTimeout: 500, factor: 1});
43+
44+
op.attempt(() => {
45+
this.kuzzle.auth.checkToken(this.previousJwt)
46+
.then(response => {
47+
const err = response.valid ? new Error('Unexpected valid token') : null;
48+
49+
if (op.retry(err)) {
50+
return;
51+
}
52+
53+
cb(err);
54+
})
55+
.catch(err => cb(err));
56+
});
57+
});
2358

2459
Then(/^the JWT is (in)?valid$/, async function (not) {
2560
const response = await this.kuzzle.auth.checkToken(this.jwt);
@@ -32,3 +67,10 @@ Then(/^the JWT is (in)?valid$/, async function (not) {
3267
}
3368
});
3469

70+
Given('I get my rights', async function () {
71+
this.rights = await this.kuzzle.auth.getMyRights();
72+
});
73+
74+
Then('I have a vector with {int} rights', function (nbRights) {
75+
should(this.rights).have.length(nbRights);
76+
});

features/support/world.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class World {
1414
this.ids = [];
1515
this.user = null;
1616
this.jwt = null;
17+
this.rights = null;
18+
this.previousJwt = null;
1719

1820
this.content = null;
1921
this.error = null;

0 commit comments

Comments
 (0)