Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/features
Submodule features updated 1 files
+18 −0 auth.feature
48 changes: 45 additions & 3 deletions features/steps/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const {Given, When, Then} = require('cucumber');
const should = require('should');
const
{Given, When, Then} = require('cucumber'),
should = require('should'),
retry = require('retry');

Given('I log in as {string}:{string}', async function (username, password) {
try {
Expand All @@ -15,11 +17,44 @@ Given('I log in as {string}:{string}', async function (username, password) {
}
});


When('I logout', async function () {
await this.kuzzle.auth.logout();
});

When('I refresh the JWT', function (cb) {
this.previousJwt = this.jwt;

// we have to wait for at least 1s: if we ask Kuzzle to refresh a JWT that
// has been generated during the same second, then the new JWT will be
// identical to the one being refreshed
setTimeout(async () => {
const token = await this.kuzzle.auth.refreshToken();
this.jwt = token.jwt;
cb();
}, 1000);
});

Then('the previous JWT is now invalid', function (cb) {
// prevent false positives, just in case
should(this.previousJwt).be.a.String().and.not.empty();
should(this.previousJwt).not.eql(this.jwt);

const op = retry.operation({retries: 10, minTimeout: 500, factor: 1});

op.attempt(() => {
this.kuzzle.auth.checkToken(this.previousJwt)
.then(response => {
const err = response.valid ? new Error('Unexpected valid token') : null;

if (op.retry(err)) {
return;
}

cb(err);
})
.catch(err => cb(err));
});
});

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

Given('I get my rights', async function () {
this.rights = await this.kuzzle.auth.getMyRights();
});

Then('I have a vector with {int} rights', function (nbRights) {
should(this.rights).have.length(nbRights);
});
2 changes: 2 additions & 0 deletions features/support/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class World {
this.ids = [];
this.user = null;
this.jwt = null;
this.rights = null;
this.previousJwt = null;

this.content = null;
this.error = null;
Expand Down
Loading