Skip to content

Commit

Permalink
TritonDataCenter#91 InternalError exceptions when handling user ids i…
Browse files Browse the repository at this point in the history
…n roles
  • Loading branch information
Marsell Kukuljevic committed May 23, 2021
1 parent 64e367e commit ab5c755
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"kang": "1.1.0",
"keyapi": "git+https://github.com/joyent/keyapi.git#e14b3d582e1d9d338b7082d61f34ba8d1bbc540a",
"krill": "1.0.1",
"mahi": "2.3.0",
"mahi": "2.3.3",
"mime": "^1.4.1",
"mooremachine": "^2.2.0",
"nodemailer": "0.7.1",
Expand Down
37 changes: 28 additions & 9 deletions test/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/*
* Copyright 2020 Joyent, Inc.
* Copyright 2021 Spearhead Systems S.R.L.
*/

/*
Expand Down Expand Up @@ -1230,6 +1231,11 @@ test('create role v9', function (t) {
login: SUB_LOGIN_2,
default: false
},
{
type: 'subuser',
id: SUB_USER.id,
default: false
},
{
type: 'account',
login: OTHER.login,
Expand Down Expand Up @@ -1269,7 +1275,7 @@ test('get role (by UUID)', function (t) {
common.checkHeaders(t, res.headers);
t.ok(body);
t.equal(body.id, ROLE_UUID);
t.deepEqual(body.members, [SUB_LOGIN_2]);
t.deepEqual(body.members.sort(), [SUB_LOGIN_2, SUB_LOGIN].sort());
t.deepEqual(body.default_members, []);
t.deepEqual(body.policies, [POLICY_NAME]);
t.end();
Expand All @@ -1292,19 +1298,32 @@ test('get role v9 (by UUID)', function (t) {
t.ok(Array.isArray(body.members), 'members is an array');
t.strictEqual(typeof (body.members[0]), 'object',
'members[0] is object');
t.strictEqual(body.members.length, 2, '2 members present');
body.members.forEach(function (member) {
if (member.type === 'subuser') {
t.strictEqual(member.login, SUB_LOGIN_2);
} else if (member.type === 'account') {
t.strictEqual(member.login, OTHER.login);
}
});
t.strictEqual(body.members.length, 3, '3 members present');
t.ok(Array.isArray(body.policies), 'policies is an array');
t.strictEqual(typeof (body.policies[0]), 'object',
'policies[0] is object');
t.strictEqual(body.policies[0].id, POLICY_UUID, 'policy uuid');
t.strictEqual(body.policies[0].name, POLICY_NAME, 'policy name');

function memberSorter(a, b) {
return a.login < b.login;
}

var members = body.members.map(function (m) {
return { login: m.login, type: m.type };
});
var expectedMem = [{
login: SUB_LOGIN,
type: 'subuser'
}, {
login: SUB_LOGIN_2,
type: 'subuser'
}, {
login: OTHER.login,
type: 'account'
}];

t.deepEqual(members.sort(memberSorter), expectedMem.sort(memberSorter));
t.end();
});
});
Expand Down

0 comments on commit ab5c755

Please sign in to comment.