Skip to content

Commit a09c5af

Browse files
committed
add more tests to cover account level
1 parent c803051 commit a09c5af

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

tests/unit/api/apiUtils/rateLimit/config.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,24 @@ describe('parseRateLimitConfig', () => {
558558
/rateLimiting configuration is invalid.*"bucket.defaultConfig.requestsPerSecond.burstCapacity" must be a number/
559559
);
560560
});
561+
562+
it('should accept float burstCapacity', () => {
563+
const config = {
564+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
565+
bucket: {
566+
defaultConfig: {
567+
requestsPerSecond: {
568+
limit: 100,
569+
burstCapacity: 1.5,
570+
},
571+
},
572+
},
573+
};
574+
575+
const result = parseRateLimitConfig(config, 1);
576+
const bucketSize = result.bucket.defaultConfig.requestsPerSecond.bucketSize;
577+
assert.strictEqual(bucketSize, 1.5 * 1000);
578+
});
561579
});
562580

563581
describe('bucket.configCacheTTL validation', () => {
@@ -941,6 +959,121 @@ describe('parseRateLimitConfig', () => {
941959
});
942960
});
943961

962+
describe('account burstCapacity validation', () => {
963+
it('should use default burstCapacity when not provided', () => {
964+
const config = {
965+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
966+
account: {
967+
defaultConfig: {
968+
requestsPerSecond: {
969+
limit: 100,
970+
},
971+
},
972+
},
973+
};
974+
975+
const result = parseRateLimitConfig(config, 1);
976+
const bucketSize = result.account.defaultConfig.requestsPerSecond.bucketSize;
977+
assert.strictEqual(bucketSize, constants.rateLimitDefaultBurstCapacity * 1000);
978+
});
979+
980+
it('should use custom burstCapacity when provided', () => {
981+
const config = {
982+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
983+
account: {
984+
defaultConfig: {
985+
requestsPerSecond: {
986+
limit: 100,
987+
burstCapacity: 20,
988+
},
989+
},
990+
},
991+
};
992+
993+
const result = parseRateLimitConfig(config, 1);
994+
const bucketSize = result.account.defaultConfig.requestsPerSecond.bucketSize;
995+
assert.strictEqual(bucketSize, 20 * 1000);
996+
});
997+
998+
it('should accept float burstCapacity', () => {
999+
const config = {
1000+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
1001+
account: {
1002+
defaultConfig: {
1003+
requestsPerSecond: {
1004+
limit: 100,
1005+
burstCapacity: 1.5,
1006+
},
1007+
},
1008+
},
1009+
};
1010+
1011+
const result = parseRateLimitConfig(config, 1);
1012+
const bucketSize = result.account.defaultConfig.requestsPerSecond.bucketSize;
1013+
assert.strictEqual(bucketSize, 1.5 * 1000);
1014+
});
1015+
1016+
it('should throw if burstCapacity is negative', () => {
1017+
const config = {
1018+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
1019+
account: {
1020+
defaultConfig: {
1021+
requestsPerSecond: {
1022+
limit: 100,
1023+
burstCapacity: -5,
1024+
},
1025+
},
1026+
},
1027+
};
1028+
1029+
assert.throws(
1030+
() => parseRateLimitConfig(config, 1),
1031+
// eslint-disable-next-line max-len
1032+
/rateLimiting configuration is invalid.*"account.defaultConfig.requestsPerSecond.burstCapacity" must be a positive number/
1033+
);
1034+
});
1035+
1036+
it('should throw if burstCapacity is zero', () => {
1037+
const config = {
1038+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
1039+
account: {
1040+
defaultConfig: {
1041+
requestsPerSecond: {
1042+
limit: 100,
1043+
burstCapacity: 0,
1044+
},
1045+
},
1046+
},
1047+
};
1048+
1049+
assert.throws(
1050+
() => parseRateLimitConfig(config, 1),
1051+
// eslint-disable-next-line max-len
1052+
/rateLimiting configuration is invalid.*"account.defaultConfig.requestsPerSecond.burstCapacity" must be a positive number/
1053+
);
1054+
});
1055+
1056+
it('should throw if burstCapacity is not a number', () => {
1057+
const config = {
1058+
serviceUserArn: 'arn:aws:iam::123456789012:user/rate-limit-service',
1059+
account: {
1060+
defaultConfig: {
1061+
requestsPerSecond: {
1062+
limit: 100,
1063+
burstCapacity: 'ten',
1064+
},
1065+
},
1066+
},
1067+
};
1068+
1069+
assert.throws(
1070+
() => parseRateLimitConfig(config, 1),
1071+
// eslint-disable-next-line max-len
1072+
/rateLimiting configuration is invalid.*"account.defaultConfig.requestsPerSecond.burstCapacity" must be a number/
1073+
);
1074+
});
1075+
});
1076+
9441077
describe('schema validation - unknown fields', () => {
9451078
it('should reject unknown top-level fields', () => {
9461079
const config = {

0 commit comments

Comments
 (0)