Skip to content

Commit 915163b

Browse files
committed
Merge branch 'improvement/ARSN-555/pass_limits_through_auth_handler' into q/8.2
2 parents da2c049 + 707ddb8 commit 915163b

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed

lib/auth/AuthInfo.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ export type AccountQuota = {
2222
quota: bigint,
2323
};
2424

25+
export type AccountLimits = {
26+
RequestsPerSecond?: {
27+
Limit: number,
28+
},
29+
}
30+
2531
export type AccountInfos = {
2632
accountQuota?: AccountQuota,
33+
limits?: AccountLimits,
2734
};
2835

2936
export type AuthV4Results = {
3037
userInfo: AuthInfoType,
3138
authorizationResults?: AuthorizationResults,
3239
accountQuota: AccountQuota,
40+
limits?: AccountLimits,
3341
};
3442

3543
export type AccountCanonicalInfo = {

lib/auth/Vault.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function vaultSignatureCb(
6666
log.addDefaultFields(auditLog);
6767
return callback(null, userInfo, authorizationResults, streamingV4Params, {
6868
accountQuota: info.accountQuota || {},
69+
limits: info.limits || {},
6970
});
7071
}
7172
export type AuthV2RequestParams = {
@@ -474,13 +475,13 @@ export default class Vault {
474475
/**
475476
* Calls Vault to retrieve the default encryption key id of the account, or creates it if it doesn't exist.
476477
*
477-
* @param {string} canonicalID - The canonical id of the account for which
478+
* @param {string} canonicalID - The canonical id of the account for which
478479
* the encryption key id is being retrieved or created.
479480
* @param {RequestLogger} log - logger
480-
* @param {(err: Error | null, data?: {
481-
* canonicalId: string,
482-
* encryptionKeyId: string,
483-
* action: 'retrieved' | 'created'
481+
* @param {(err: Error | null, data?: {
482+
* canonicalId: string,
483+
* encryptionKeyId: string,
484+
* action: 'retrieved' | 'created'
484485
* }) => void}
485486
* - canonicalId: The canonical id of the account.
486487
* - encryptionKeyId: The retrieved or newly created encryption key id.
@@ -491,10 +492,10 @@ export default class Vault {
491492
getOrCreateEncryptionKeyId(
492493
canonicalID: string,
493494
log: RequestLogger,
494-
callback: (err: Error | null, data?: {
495-
canonicalId: string,
496-
encryptionKeyId: string,
497-
action: 'retrieved' | 'created'
495+
callback: (err: Error | null, data?: {
496+
canonicalId: string,
497+
encryptionKeyId: string,
498+
action: 'retrieved' | 'created'
498499
}) => void
499500
) {
500501
log.trace('sending request context params to vault to get or create encryption key id');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"engines": {
44
"node": ">=20"
55
},
6-
"version": "8.2.46",
6+
"version": "8.2.47",
77
"description": "Common utilities for the S3 project components",
88
"main": "build/index.js",
99
"repository": {

tests/unit/auth/Vault.spec.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,77 @@ describe('Vault class', () => {
349349
done();
350350
});
351351
});
352+
353+
it('should handle successful authentication with account limits', done => {
354+
const limitConfig = {
355+
RequestsPerSecond: {
356+
Limit: 1500,
357+
},
358+
};
359+
const mockResponse = {
360+
message: {
361+
message: 'Success',
362+
body: {
363+
userInfo: mockUserInfo,
364+
authorizationResults: [{
365+
isAllowed: true,
366+
isImplicit: false,
367+
arn: mockUserInfo.arn,
368+
action: 'testAction',
369+
}],
370+
limits: limitConfig,
371+
},
372+
},
373+
};
374+
375+
mockClient.verifySignatureV4.callsFake(
376+
(_stringToSign, _signature, _accessKey, _region, _scopeDate,
377+
_options, callback) => {
378+
callback(null, mockResponse);
379+
},
380+
);
381+
382+
vault.authenticateV4Request(mockParams, [], {}, (err, data, results,
383+
_params, infos) => {
384+
assert.strictEqual(err, null);
385+
assert(data instanceof AuthInfo);
386+
assert.strictEqual(data.getCanonicalID(), mockUserInfo.canonicalID);
387+
assert.deepStrictEqual(infos.limits, limitConfig);
388+
done();
389+
});
390+
});
391+
392+
it('should handle authentication with no account limits', done => {
393+
const mockResponse = {
394+
message: {
395+
message: 'Success',
396+
body: {
397+
userInfo: mockUserInfo,
398+
authorizationResults: [{
399+
isAllowed: true,
400+
isImplicit: false,
401+
arn: mockUserInfo.arn,
402+
action: 'testAction',
403+
}],
404+
},
405+
},
406+
};
407+
408+
mockClient.verifySignatureV4.callsFake(
409+
(_stringToSign, _signature, _accessKey, _region, _scopeDate,
410+
_options, callback) => {
411+
callback(null, mockResponse);
412+
},
413+
);
414+
415+
vault.authenticateV4Request(mockParams, [], {}, (err, data, results,
416+
_params, infos) => {
417+
assert.strictEqual(err, null);
418+
assert(data instanceof AuthInfo);
419+
assert.deepStrictEqual(infos.limits, {});
420+
done();
421+
});
422+
});
352423
});
353424

354425
describe('getCanonicalIds', () => {

0 commit comments

Comments
 (0)