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 lib/IAMClient.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 19 additions & 22 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,15 @@ class VaultClient {
if (key === undefined) {
assert(false, 'key needs to be specified');
}
assert((accountArn, typeof accountArn === 'string'
|| 'arn should be a string'));
assert((accountName, typeof accountName === 'string'
|| 'name should be a string'));
assert((accountId, typeof accountId === 'string'
|| 'id should be a string'));
assert((canonicalId, typeof canonicalId === 'string'
|| 'canonicalId should be a string'));
assert((key, typeof key === 'string'
|| 'key should be a string'));
assert(accountArn === undefined || typeof accountArn === 'string',
'arn should be a string');
assert(accountName === undefined || typeof accountName === 'string',
'name should be a string');
assert(accountId === undefined || typeof accountId === 'string',
'id should be a string');
assert(canonicalId === undefined || typeof canonicalId === 'string',
'canonicalId should be a string');
assert(typeof key === 'string', 'key should be a string');
const data = {
Action: 'AddAccountAttribute',
Version: '2010-05-08',
Expand All @@ -526,8 +525,7 @@ class VaultClient {
data.canonicalId = canonicalId;
}
if (value) {
assert((value, typeof value === 'string'
|| 'value should be a string'));
assert(typeof value === 'string', 'value should be a string');
data.value = value;
}
this.request('POST', '/', true, callback, data);
Expand Down Expand Up @@ -563,16 +561,15 @@ class VaultClient {
if (key === undefined) {
assert(false, 'key needs to be specified');
}
assert((accountArn, typeof accountArn === 'string'
|| 'arn should be a string'));
assert((accountName, typeof accountName === 'string'
|| 'name should be a string'));
assert((accountId, typeof accountId === 'string'
|| 'id should be a string'));
assert((canonicalId, typeof canonicalId === 'string'
|| 'canonicalId should be a string'));
assert((key, typeof key === 'string'
|| 'key should be a string'));
assert(accountArn === undefined || typeof accountArn === 'string',
'arn should be a string');
assert(accountName === undefined || typeof accountName === 'string',
'name should be a string');
assert(accountId === undefined || typeof accountId === 'string',
'id should be a string');
assert(canonicalId === undefined || typeof canonicalId === 'string',
'canonicalId should be a string');
assert(typeof key === 'string', 'key should be a string');
const data = {
Action: 'DeleteAccountAttribute',
Version: '2010-05-08',
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": ">=20"
},
"version": "8.5.7",
"version": "8.5.8",
"description": "Client library and binary for Vault, the user directory and key management service",
"main": "index.js",
"repository": "scality/vaultclient",
Expand Down
112 changes: 112 additions & 0 deletions tests/unit/addAccountAttribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
const assert = require('assert');
const IAMClient = require('../../lib/IAMClient');

describe('IAMClient - addAccountAttribute', () => {
let client;
let lastRequestData;

beforeEach('stub the request method', () => {
client = new IAMClient('127.0.0.1', 8500);
lastRequestData = null;
client.request = (method, path, iamAuthenticate, callback, data) => {
lastRequestData = { method, path, iamAuthenticate, data };
callback();
};
});

it('should call the request method with the correct parameters', () => {
client.addAccountAttribute({
accountName: 'exampleAccount',
key: 'exampleKey',
value: 'exampleValue',
}, () => {});

assert.strictEqual(lastRequestData.method, 'POST');
assert.strictEqual(lastRequestData.path, '/');
assert.strictEqual(lastRequestData.iamAuthenticate, true);
assert.deepStrictEqual(lastRequestData.data, {
Action: 'AddAccountAttribute',
Version: '2010-05-08',
key: 'exampleKey',
accountName: 'exampleAccount',
value: 'exampleValue',
});
});

it('should not send the value when it is not provided', () => {
client.addAccountAttribute({
accountName: 'exampleAccount',
key: 'exampleKey',
}, () => {});

assert.deepStrictEqual(lastRequestData.data, {
Action: 'AddAccountAttribute',
Version: '2010-05-08',
key: 'exampleKey',
accountName: 'exampleAccount',
});
});

['accountArn', 'accountName', 'accountId', 'canonicalId'].forEach(identifier => {
it(`should accept ${identifier} on its own`, () => {
client.addAccountAttribute({
[identifier]: 'exampleIdentifier',
key: 'exampleKey',
}, () => {});

assert.deepStrictEqual(lastRequestData.data, {
Action: 'AddAccountAttribute',
Version: '2010-05-08',
key: 'exampleKey',
[identifier]: 'exampleIdentifier',
});
});
});

it('should throw an error if no account identifier is specified', () => {
assert.throws(() => {
client.addAccountAttribute({ key: 'exampleKey' }, () => {});
}, /account-name, account-id, account-arn or canonical-id need to be specified/);
});

it('should throw an error if key is not specified', () => {
assert.throws(() => {
client.addAccountAttribute({ accountName: 'exampleAccount' }, () => {});
}, /key needs to be specified/);
});

[
{ identifier: 'accountArn', message: /arn should be a string/ },
{ identifier: 'accountName', message: /name should be a string/ },
{ identifier: 'accountId', message: /id should be a string/ },
{ identifier: 'canonicalId', message: /canonicalId should be a string/ },
].forEach(({ identifier, message }) => {
it(`should throw an error if ${identifier} is not a string`, () => {
assert.throws(() => {
client.addAccountAttribute({
[identifier]: 123,
key: 'exampleKey',
}, () => {});
}, message);
});
});

it('should throw an error if key is not a string', () => {
assert.throws(() => {
client.addAccountAttribute({
accountName: 'exampleAccount',
key: 123,
}, () => {});
}, /key should be a string/);
});

it('should throw an error if value is not a string', () => {
assert.throws(() => {
client.addAccountAttribute({
accountName: 'exampleAccount',
key: 'exampleKey',
value: 123,
}, () => {});
}, /value should be a string/);
});
});
86 changes: 86 additions & 0 deletions tests/unit/deleteAccountAttribute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const assert = require('assert');
const IAMClient = require('../../lib/IAMClient');

describe('IAMClient - deleteAccountAttribute', () => {
let client;
let lastRequestData;

beforeEach('stub the request method', () => {
client = new IAMClient('127.0.0.1', 8500);
lastRequestData = null;
client.request = (method, path, iamAuthenticate, callback, data) => {
lastRequestData = { method, path, iamAuthenticate, data };
callback();
};
});

it('should call the request method with the correct parameters', () => {
client.deleteAccountAttribute({
accountName: 'exampleAccount',
key: 'exampleKey',
}, () => {});

assert.strictEqual(lastRequestData.method, 'POST');
assert.strictEqual(lastRequestData.path, '/');
assert.strictEqual(lastRequestData.iamAuthenticate, true);
assert.deepStrictEqual(lastRequestData.data, {
Action: 'DeleteAccountAttribute',
Version: '2010-05-08',
key: 'exampleKey',
accountName: 'exampleAccount',
});
});

['accountArn', 'accountName', 'accountId', 'canonicalId'].forEach(identifier => {
it(`should accept ${identifier} on its own`, () => {
client.deleteAccountAttribute({
[identifier]: 'exampleIdentifier',
key: 'exampleKey',
}, () => {});

assert.deepStrictEqual(lastRequestData.data, {
Action: 'DeleteAccountAttribute',
Version: '2010-05-08',
key: 'exampleKey',
[identifier]: 'exampleIdentifier',
});
});
});

it('should throw an error if no account identifier is specified', () => {
assert.throws(() => {
client.deleteAccountAttribute({ key: 'exampleKey' }, () => {});
}, /account-name, account-id, account-arn or canonical-id need to be specified/);
});

it('should throw an error if key is not specified', () => {
assert.throws(() => {
client.deleteAccountAttribute({ accountName: 'exampleAccount' }, () => {});
}, /key needs to be specified/);
});

[
{ identifier: 'accountArn', message: /arn should be a string/ },
{ identifier: 'accountName', message: /name should be a string/ },
{ identifier: 'accountId', message: /id should be a string/ },
{ identifier: 'canonicalId', message: /canonicalId should be a string/ },
].forEach(({ identifier, message }) => {
it(`should throw an error if ${identifier} is not a string`, () => {
assert.throws(() => {
client.deleteAccountAttribute({
[identifier]: 123,
key: 'exampleKey',
}, () => {});
}, message);
});
});

it('should throw an error if key is not a string', () => {
assert.throws(() => {
client.deleteAccountAttribute({
accountName: 'exampleAccount',
key: 123,
}, () => {});
}, /key should be a string/);
});
});
Loading