Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTEGRATION [PR#432 > development/8.2] VLTCLT-39: Update getAccounts to search by name #439

Merged
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
30 changes: 16 additions & 14 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,39 +454,41 @@ class VaultClient {
}

/**
* Get accounts using account ids, canonical ids or email addresses
* Get accounts using account ids or names, canonical ids or email addresses
*
* @param {array|undefined} accountIds - Account ids, exclusive with
* emailAddresses and canonicalIds
* @param {array|undefined} accounts - Account ids or names (depending on options.accountNames),
* exclusive with emailAddresses and canonicalIds
* @param {array|undefined} emailAddresses - Email addresses, exclusive
* with account ids and canonicalIds
* with account ids or names and canonicalIds
* @param {array|undefined} canonicalIds - Canonical ids, exclusive with
* account ids and emailAddresses
* account ids or names and emailAddresses
* @param {object} options - Options
* @param {string} [options.reqUid] - Request uid
* @param {boolean} [options.accountNames] - Flag to consider first arg `accounts`
* as `accountNames` instead of `accountIds`
* @param {function} callback - Callback(err, result)
* @return {undefined}
*/
getAccounts(accountIds, emailAddresses, canonicalIds, options, callback) {
assert((accountIds && Array.isArray(accountIds)) || !accountIds,
'accountIds should be an array');
getAccounts(accounts, emailAddresses, canonicalIds, options, callback) {
assert((accounts && Array.isArray(accounts)) || !accounts,
'accounts should be an array');
assert((emailAddresses && Array.isArray(emailAddresses))
|| !emailAddresses, 'emailAddresses should be an array');
assert((canonicalIds && Array.isArray(canonicalIds)) || !canonicalIds,
'canonicalIds should be an array');
if (
(accountIds && (emailAddresses || canonicalIds))
|| (emailAddresses && (accountIds || canonicalIds))
|| (canonicalIds && (accountIds || emailAddresses))) {
assert(false, 'accountIds, emailAddresses and canonicalIds '
(accounts && (emailAddresses || canonicalIds))
|| (emailAddresses && (accounts || canonicalIds))
|| (canonicalIds && (accounts || emailAddresses))) {
assert(false, 'accounts, emailAddresses and canonicalIds '
+ 'ids are exclusive');
}
const data = {
Action: 'GetAccounts',
Version: '2010-05-08',
};
if (accountIds) {
data.accountIds = accountIds;
if (accounts) {
data[options.accountNames ? 'accountNames' : 'accountIds'] = accounts;
}
if (canonicalIds) {
data.canonicalIds = canonicalIds;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "8.2.8",
"version": "8.2.9",
"description": "Client library and binary for Vault, the user directory and key management service",
"main": "index.js",
"repository": "scality/vaultclient",
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/getAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-disable operator-linebreak */
'use strict'; // eslint-disable-line

const assert = require('assert');
const IAMClient = require('../../lib/IAMClient');

const accountIds = ['accountId1', 'accountId2'];
const canonicalIds = ['canId1', 'canId2'];
const emailAddresses = ['email1', 'email2'];
const accountNames = ['name1', 'name2'];
const opt = { reqUid: 'test.getAccounts.reqUid' };
const optAccountNames = Object.assign({}, opt, { accountNames: true });
const mockCB = () => {};

const expectedData = {
Action: 'GetAccounts',
Version: '2010-05-08',
};

describe('getAccounts', () => {
let client;
let spyArg = null;

beforeEach('spy on request', done => {
client = new IAMClient('127.0.0.1', 8500);
client.request = function spy(...args) {
spyArg = args;
};
done();
});

afterEach('reset spyArg', () => { spyArg = null; });

describe('should send request with correct arguments', () => {
[
{ name: 'accountIds', args: [accountIds, null, null, opt, mockCB] },
{ name: 'emailAddresses', args: [null, emailAddresses, null, opt, mockCB] },
{ name: 'canonicalIds', args: [null, null, canonicalIds, opt, mockCB] },
{ name: 'accountNames', args: [accountNames, null, null, optAccountNames, mockCB] },
].forEach(({ name, args }) => it(`for ${name}`, () => {
client.getAccounts(...args);
const [method, path, auth, cb, data, reqUid, contentType] = spyArg;
assert.strictEqual(method, 'GET');
assert.strictEqual(path, '/');
assert.strictEqual(auth, false);
assert.strictEqual(cb, mockCB);
assert.strictEqual(reqUid, opt.reqUid);
assert.strictEqual(contentType, null);
assert.deepStrictEqual(
data,
Object.assign({}, expectedData, { [name]: args[0] || args[1] || args[2] }),
);
}));
});

describe('should throw with invalid arguments', () => {
it('for all values set', () => {
assert.throws(() => client.getAccounts(accountIds, emailAddresses, canonicalIds, opt, mockCB),
assert.AssertionError);
});
});
});
Loading