Skip to content

Commit 1c3032d

Browse files
authored
Make this SDK compatible with node6 again (#446)
# Description More and more NPM modules are dropping support for Node.js 6, making it hazardous to not test this SDK against that version of node to guarantee that it stays compatible with Kuzzle v1. Also, `Object.entries` have been added to this SDK, which does not exist in node6, making Kuzzle crash if an attempt is made to use this SDK with Node.js 6. So this PR forces Travis to run tests using Node.js 6, and all other changes are made to make that SDK fully-compatible, tests included. Once Kuzzle v2 is out, we'll release a major version of this SDK dropping support for node 6, allowing us to once again use async/await and other new features. # Other changes * fix documentation snippets tests to make them work with kuzzle 1.10
1 parent 15b77fe commit 1c3032d

File tree

16 files changed

+614
-644
lines changed

16 files changed

+614
-644
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Unit Tests
1313
if: type = pull_request OR type = push AND branch =~ /^master|[0-9]+-(dev|stable)$/ OR type = cron
1414
language: node_js
15-
node_js: 8
15+
node_js: 6
1616

1717
env:
1818
# Codecov token
@@ -43,7 +43,7 @@ jobs:
4343
name: Integration Tests
4444
if: type = pull_request OR type = push AND branch =~ /^master|[0-9]+-(dev|stable)$/ OR type = cron
4545
language: node_js
46-
node_js: 8
46+
node_js: 6
4747

4848
addons:
4949
apt:
@@ -69,7 +69,7 @@ jobs:
6969
name: Documentation Tests
7070
if: type = pull_request OR type = push AND branch =~ /^master|[0-9]+-(dev|stable)$/ OR type = cron
7171
language: node_js
72-
node_js: 8
72+
node_js: 10
7373

7474
before_script:
7575
- sudo apt-get install libgconf-2-4
@@ -158,7 +158,7 @@ jobs:
158158
if: tag IS present AND type != cron
159159
sudo: false
160160
language: node_js
161-
node_js: 8
161+
node_js: 6
162162

163163
addons:
164164
apt:
@@ -191,7 +191,7 @@ jobs:
191191
if: type = push && branch =~ /^[0-9]+-dev$/
192192
sudo: false
193193
language: node_js
194-
node_js: 8
194+
node_js: 6
195195

196196
addons:
197197
apt:
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
name: security#updateProfile
2-
description: update profile
2+
description: updates a security profile definition
33
hooks:
4-
before: >
5-
curl -H "Content-type: application/json" -d '{
6-
"policies": []
7-
}' kuzzle:7512/profiles/myProfile/_create
8-
after: curl -XDELETE kuzzle:7512/profiles/myProfile
4+
before:
5+
- >
6+
curl -H "Content-type: application/json" -d '{
7+
"policies": []
8+
}' kuzzle:7512/profiles/myProfile/_create
9+
- >
10+
curl -H "Content-type: application/json" -d '{
11+
"controllers": {
12+
"*": {
13+
"actions": {
14+
"*": true
15+
}
16+
}
17+
}
18+
}' kuzzle:7512/roles/privileged/_create
19+
after:
20+
- curl -XDELETE kuzzle:7512/profiles/myProfile?refresh=wait_for
21+
- curl -XDELETE kuzzle:7512/roles/privileged
922
template: default
1023
expected: '^ { roleId: ''privileged'', restrictedTo: \[Array\] } \] }$'

doc/6/controllers/security/update-role/snippets/update-role.js

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
try {
2-
const response = await kuzzle.security.updateRole(
3-
'read-only',
4-
{
5-
controllers: {
6-
auth: {
7-
actions: {
8-
getCurrentUser: true,
9-
getMyCredentials: true,
10-
getMyRights: true,
11-
logout: true
12-
}
13-
},
14-
collection: {
15-
actions: {
16-
getMapping: true,
17-
list: true
18-
}
19-
},
20-
document: {
21-
actions: {
22-
count: true,
23-
get: true,
24-
mGet: true,
25-
scroll: true,
26-
search: true
27-
}
28-
},
29-
index: {
30-
actions: {
31-
list: true
32-
}
2+
const response = await kuzzle.security.updateRole('read-only', {
3+
controllers: {
4+
auth: {
5+
actions: {
6+
getCurrentUser: true,
7+
getMyCredentials: true,
8+
getMyRights: true,
9+
logout: true
10+
}
11+
},
12+
collection: {
13+
actions: {
14+
getMapping: true,
15+
list: true
16+
}
17+
},
18+
document: {
19+
actions: {
20+
count: true,
21+
get: true,
22+
mGet: true,
23+
scroll: true,
24+
search: true
25+
}
26+
},
27+
index: {
28+
actions: {
29+
list: true
3330
}
3431
}
3532
}
36-
);
33+
});
3734

3835
console.log(response);
3936
/*

doc/6/controllers/security/update-role/snippets/update-role.test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ hooks:
44
before: >
55
curl -f -H "Content-type: application/json" -d '{
66
"controllers": {
7-
"*": {
7+
"auth": {
88
"actions": {
9-
"*": false
9+
"login": true
1010
}
1111
}
1212
}

doc/6/controllers/server/get-config/snippets/get-config.test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ hooks:
44
before:
55
after:
66
template: default
7-
expected: ^(Kuzzle Server configuration:) {("dump":{.*}),("limits":{.*}),("plugins":{.*}),("queues":{.*}),("repositories":{.*}),("server":{.*}),("services":{.*}),("stats":{.*}),("validation":{.*}),("_":.*),("internal":{.*}),("version":"[0-9]\.[0-9]\.[0-9]")}$
8-
7+
expected: ^(Kuzzle Server configuration:) {("dump":{.*}),("limits":{.*}),("plugins":{.*}),("queues":{.*}),("repositories":{.*}),("server":{.*}),("services":{.*}),("stats":{.*}),("validation":{.*}),("_":.*),("internal":{.*}),("version":"[0-9]+\.[0-9]+\.[0-9]+")}$
98
sdk: js
109
version: 6

doc/6/controllers/server/info/snippets/info.test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ hooks:
44
before:
55
after:
66
template: default
7-
expected: "^Kuzzle Server information: {\"serverInfo\":{\"kuzzle\":{\"version\":\"[0-9]\\.[0-9]\\.[0-9]\",\"api\":{.*"
7+
expected: "^Kuzzle Server information: {\"serverInfo\":{\"kuzzle\":{\"version\":\"[0-9]+\\.[0-9]+\\.[0-9]+\",\"api\":{.*"
88
sdk: js
99
version: 6

features/steps/auth.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ const
33
should = require('should'),
44
retry = require('retry');
55

6-
Given('I log in as {string}:{string}', async function (username, password) {
7-
try {
8-
this.jwt = await this.kuzzle.auth.login('local', {
9-
username,
10-
password
6+
Given('I log in as {string}:{string}', function (username, password) {
7+
return this.kuzzle.auth.login('local', { username, password })
8+
.then(jwt => {
9+
this.jwt = jwt;
10+
})
11+
.catch(error => {
12+
this.jwt = 'invalid';
13+
this.error = error;
1114
});
12-
this.error = null;
13-
}
14-
catch (error) {
15-
this.jwt = 'invalid';
16-
this.error = error;
17-
}
1815
});
1916

20-
When('I logout', async function () {
21-
await this.kuzzle.auth.logout();
17+
When('I logout', function () {
18+
return this.kuzzle.auth.logout();
2219
});
2320

2421
When('I refresh the JWT', function (cb) {
@@ -27,11 +24,16 @@ When('I refresh the JWT', function (cb) {
2724
// we have to wait for at least 1s: if we ask Kuzzle to refresh a JWT that
2825
// has been generated during the same second, then the new JWT will be
2926
// 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);
27+
setTimeout(
28+
() => {
29+
this.kuzzle.auth.refreshToken()
30+
.then(token => {
31+
this.jwt = token.jwt;
32+
cb();
33+
})
34+
.catch(err => cb(err));
35+
},
36+
1000);
3537
});
3638

3739
Then('the previous JWT is now invalid', function (cb) {
@@ -56,19 +58,23 @@ Then('the previous JWT is now invalid', function (cb) {
5658
});
5759
});
5860

59-
Then(/^the JWT is (in)?valid$/, async function (not) {
60-
const response = await this.kuzzle.auth.checkToken(this.jwt);
61-
62-
if (not) {
63-
should(response.valid).be.false();
64-
}
65-
else {
66-
should(response.valid).be.true();
67-
}
61+
Then(/^the JWT is (in)?valid$/, function (not) {
62+
return this.kuzzle.auth.checkToken(this.jwt)
63+
.then(response => {
64+
if (not) {
65+
should(response.valid).be.false();
66+
}
67+
else {
68+
should(response.valid).be.true();
69+
}
70+
});
6871
});
6972

70-
Given('I get my rights', async function () {
71-
this.rights = await this.kuzzle.auth.getMyRights();
73+
Given('I get my rights', function () {
74+
return this.kuzzle.auth.getMyRights()
75+
.then(rights => {
76+
this.rights = rights;
77+
});
7278
});
7379

7480
Then('I have a vector with {int} rights', function (nbRights) {

0 commit comments

Comments
 (0)