Skip to content

Commit 8011a71

Browse files
annahasselAVVS
authored andcommitted
fix: add roles to init admins (#391)
1 parent 70e5e61 commit 8011a71

2 files changed

Lines changed: 46 additions & 12 deletions

File tree

src/accounts/init-admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function initAccounts() {
1919
metadata: defaults(account.metadata || {}, {
2020
firstName: account.firstName,
2121
lastName: account.lastName,
22-
roles: [USERS_ADMIN_ROLE],
22+
roles: account.roles === undefined ? [USERS_ADMIN_ROLE] : account.roles,
2323
}),
2424
activate: true,
2525
challengeType: CHALLENGE_TYPE_EMAIL,

test/suites/admins.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,34 @@ describe('#admins', function verifySuite() {
1212

1313
before(async () => {
1414
service = await startService.call(ctx, {
15-
admins: [{
16-
username: 'foobaz@makeomatic.ca',
17-
password: 'megalongsuperpasswordfortest',
18-
metadata: {
19-
firstName: 'Foo',
20-
lastName: 'Baz',
21-
roles: [constants.USERS_ADMIN_ROLE],
15+
admins: [
16+
{
17+
username: 'admin0@test.com',
18+
password: 'megalongsuperpasswordfortest',
19+
metadata: {
20+
firstName: 'Im',
21+
lastName: 'Admin0',
22+
},
2223
},
23-
}],
24+
{
25+
username: 'admin1@test.com',
26+
password: 'megalongsuperpasswordfortest',
27+
metadata: {
28+
firstName: 'Im',
29+
lastName: 'Admin1',
30+
roles: [constants.USERS_ADMIN_ROLE],
31+
},
32+
},
33+
{
34+
username: 'user0@test.com',
35+
password: 'megalongsuperpasswordfortest',
36+
metadata: {
37+
firstName: 'Im',
38+
lastName: 'User0',
39+
roles: [],
40+
},
41+
},
42+
],
2443
logger: {
2544
defaultLogger: true,
2645
debug: true,
@@ -34,12 +53,27 @@ describe('#admins', function verifySuite() {
3453
after(global.clearRedis.bind(ctx));
3554

3655
it('should be able to login an admin', async () => {
37-
const { jwt } = await dispatch('users.login', {
56+
const admin0 = await dispatch('users.login', {
57+
audience: '*.localhost',
58+
password: 'megalongsuperpasswordfortest',
59+
username: 'admin0@test.com',
60+
});
61+
const admin1 = await dispatch('users.login', {
62+
audience: '*.localhost',
63+
password: 'megalongsuperpasswordfortest',
64+
username: 'admin1@test.com',
65+
});
66+
const user0 = await dispatch('users.login', {
3867
audience: '*.localhost',
3968
password: 'megalongsuperpasswordfortest',
40-
username: 'foobaz@makeomatic.ca',
69+
username: 'user0@test.com',
4170
});
4271

43-
assert.ok(jwt);
72+
assert.ok(admin0.jwt);
73+
assert.ok(admin0.user.metadata['*.localhost'].roles.includes('admin'));
74+
assert.ok(admin1.jwt);
75+
assert.ok(admin1.user.metadata['*.localhost'].roles.includes('admin'));
76+
assert.ok(user0.jwt);
77+
assert.equal(user0.user.metadata['*.localhost'].roles.length, 0);
4478
});
4579
});

0 commit comments

Comments
 (0)