Skip to content

Commit ce71e1f

Browse files
committed
impr(VLTCLT-68): Improve validation for get/update/deleteAccountLimits
1 parent a4c3259 commit ce71e1f

4 files changed

Lines changed: 31 additions & 59 deletions

File tree

lib/IAMClient.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,9 @@ class VaultClient {
325325
Version: '2010-05-08',
326326
};
327327

328-
if (accountName) {
329-
assert(!this.parameterValidation || typeof accountName === 'string',
330-
'the account name, if set, should be a string');
331-
data.AccountName = accountName;
332-
}
328+
assert(!this.parameterValidation || typeof accountName === 'string',
329+
'the account name should be a string');
330+
data.AccountName = accountName;
333331
this.request('POST', '/', true, callback, data);
334332
}
335333

@@ -348,12 +346,10 @@ class VaultClient {
348346
limits: JSON.stringify(limits),
349347
};
350348
assert(!this.parameterValidation || (limits && typeof limits === 'object'),
351-
'Limits must be an object');
352-
if (accountName) {
353-
assert(!this.parameterValidation || typeof accountName === 'string',
354-
'the account name, if set, should be a string');
355-
data.AccountName = accountName;
356-
}
349+
'limits must be an object');
350+
assert(!this.parameterValidation || typeof accountName === 'string',
351+
'the account name should be a string');
352+
data.AccountName = accountName;
357353
this.request('POST', '/', true, callback, data);
358354
}
359355

@@ -370,11 +366,9 @@ class VaultClient {
370366
Version: '2010-05-08',
371367
};
372368

373-
if (accountName) {
374-
assert(!this.parameterValidation || typeof accountName === 'string',
375-
'the account name, if set, should be a string');
376-
data.AccountName = accountName;
377-
}
369+
assert(!this.parameterValidation || typeof accountName === 'string',
370+
'the account name should be a string');
371+
data.AccountName = accountName;
378372
this.request('POST', '/', true, callback, data);
379373
}
380374

@@ -391,11 +385,9 @@ class VaultClient {
391385
Version: '2010-05-08',
392386
};
393387

394-
if (accountName) {
395-
assert(!this.parameterValidation || typeof accountName === 'string',
396-
'the account name, if set, should be a string');
397-
data.AccountName = accountName;
398-
}
388+
assert(!this.parameterValidation || typeof accountName === 'string',
389+
'the account name should be a string');
390+
data.AccountName = accountName;
399391
this.request('POST', '/', true, callback, data);
400392
}
401393

tests/unit/deleteAccountLimits.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,19 @@ describe('IAMClient - deleteAccountLimits', () => {
3131
});
3232
});
3333

34-
it('should call the request method with the correct parameters when accountName is not provided', () => {
34+
it('should throw an error when accountName is not provided', () => {
3535
client = createClient(true);
36-
client.deleteAccountLimits(undefined, () => {});
37-
38-
assert.strictEqual(lastRequestData.method, 'POST');
39-
assert.strictEqual(lastRequestData.path, '/');
40-
assert.strictEqual(lastRequestData.iamAuthenticate, true);
41-
assert.deepStrictEqual(lastRequestData.data, {
42-
Action: 'DeleteAccountLimits',
43-
Version: '2010-05-08',
44-
});
36+
assert.throws(() => {
37+
client.deleteAccountLimits(undefined, () => {});
38+
}, /the account name should be a string/);
4539
});
4640

4741
it('should throw an error if accountName is not a string', () => {
4842
client = createClient(true);
4943
const accountName = 123;
5044
assert.throws(() => {
5145
client.deleteAccountLimits(accountName, () => {});
52-
}, /the account name, if set, should be a string/);
46+
}, /the account name should be a string/);
5347
});
5448

5549
it('should call the request method when wrong options are provided and parameterValidation is false', () => {

tests/unit/getAccountLimits.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@ describe('GetAccountLimits', () => {
3232
assert.deepStrictEqual(lastRequestData.data, expectedData);
3333
});
3434

35-
it('should call the request method with default parameters when accountName is not provided', () => {
35+
it('should throw an error when accountName is not provided', () => {
3636
client = createClient(true);
3737
const callback = () => {};
38-
client.getAccountLimits(undefined, callback);
39-
const expectedData = {
40-
Action: 'GetAccountLimits',
41-
Version: '2010-05-08',
42-
};
43-
assert.strictEqual(lastRequestData.method, 'POST');
44-
assert.strictEqual(lastRequestData.path, '/');
45-
assert.strictEqual(lastRequestData.iamAuthenticate, true);
46-
assert.deepStrictEqual(lastRequestData.data, expectedData);
38+
assert.throws(() => {
39+
client.getAccountLimits(undefined, callback);
40+
}, /the account name should be a string/);
4741
});
4842

4943
it('should throw an error if accountName is not a string', () => {
@@ -52,7 +46,7 @@ describe('GetAccountLimits', () => {
5246
const callback = () => {};
5347
assert.throws(() => {
5448
client.getAccountLimits(accountName, callback);
55-
}, /the account name, if set, should be a string/);
49+
}, /the account name should be a string/);
5650
});
5751

5852
it('should not throw an error if accountName is not a string and parameterValidation is false', () => {

tests/unit/updateAccountLimits.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,13 @@ describe('updateAccountLimits', () => {
3535
assert.deepStrictEqual(lastRequestData.data, expectedData);
3636
});
3737

38-
it('should call the request method with the correct parameters when accountName is not provided', () => {
38+
it('should throw when accountName is not provided', () => {
3939
client = createClient(true);
4040
const limits = { rateLimit: 1000 };
41-
42-
const expectedData = {
43-
Action: 'UpdateAccountLimits',
44-
Version: '2010-05-08',
45-
limits: JSON.stringify(limits),
46-
};
47-
48-
client.updateAccountLimits(undefined, limits, () => {});
49-
assert.strictEqual(lastRequestData.method, 'POST');
50-
assert.strictEqual(lastRequestData.path, '/');
51-
assert.strictEqual(lastRequestData.iamAuthenticate, true);
52-
assert.deepStrictEqual(lastRequestData.data, expectedData);
41+
assert.throws(
42+
() => client.updateAccountLimits(undefined, limits, () => {})
43+
, /the account name should be a string/
44+
)
5345
});
5446

5547
it('should handle complex limits object correctly', () => {
@@ -82,7 +74,7 @@ describe('updateAccountLimits', () => {
8274

8375
assert.throws(() => {
8476
client.updateAccountLimits(accountName, limits, () => {});
85-
}, /Limits must be an object/);
77+
}, /limits must be an object/);
8678
});
8779

8880
it('should throw an error if limits is null', () => {
@@ -92,7 +84,7 @@ describe('updateAccountLimits', () => {
9284

9385
assert.throws(() => {
9486
client.updateAccountLimits(accountName, limits, () => {});
95-
}, /Limits must be an object/);
87+
}, /limits must be an object/);
9688
});
9789

9890
it('should not throw an error if limits is not an object and parameterValidation is false', () => {
@@ -121,7 +113,7 @@ describe('updateAccountLimits', () => {
121113

122114
assert.throws(() => {
123115
client.updateAccountLimits(accountName, limits, () => {});
124-
}, /the account name, if set, should be a string/);
116+
}, /the account name should be a string/);
125117
});
126118

127119
it('should not throw an error if accountName is not a string and parameterValidation is false', () => {

0 commit comments

Comments
 (0)