Skip to content

Commit

Permalink
Rate limit rules for production config. (dart-lang#7369)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 18, 2024
1 parent 9ff2f31 commit e588d98
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 7 deletions.
84 changes: 78 additions & 6 deletions app/config/dartlang-pub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,83 @@ tools:
rateLimits:
- operation: package-published
scope: package
burst: 10
hourly: 120
daily: 240
burst: 3
hourly: 6
daily: 12
- operation: package-published
scope: user
burst: 100
hourly: 1000
daily: 1250
burst: 10
hourly: 100
daily: 200
- operation: publisher-created
scope: user
daily: 8
- operation: package-transferred
scope: package
burst: 2
hourly: 5
daily: 10
- operation: package-transferred
scope: user
burst: 10
hourly: 100
daily: 200

# Updating options
- operation: package-options-updated
scope: package
burst: 5
hourly: 10
daily: 100
- operation: package-options-updated
scope: user
burst: 20
hourly: 100
daily: 200
- operation: package-publication-automation-updated
scope: package
burst: 5
hourly: 10
daily: 100
- operation: package-publication-automation-updated
scope: user
burst: 20
hourly: 100
daily: 200
- operation: package-version-options-updated
scope: package
burst: 5
hourly: 10
daily: 100
- operation: package-version-options-updated
scope: user
burst: 20
hourly: 100
daily: 200
- operation: publisher-updated
scope: user
burst: 20
hourly: 100
daily: 200

# Invites
- operation: publisher-contact-invited
scope: user
burst: 10
hourly: 100
daily: 200
- operation: publisher-member-invited
scope: user
burst: 10
hourly: 100
daily: 200
- operation: uploader-invited
scope: package
burst: 5
hourly: 10
daily: 48
- operation: uploader-invited
scope: user
burst: 10
hourly: 100
daily: 200
22 changes: 21 additions & 1 deletion app/test/shared/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
throwsA(isArgumentError));
});

test('configuration files serialized', () async {
test('configuration files content', () async {
final files = Directory('config')
.listSync()
.whereType<File>()
Expand All @@ -45,6 +45,7 @@ void main() {
expect(files, hasLength(2));

for (final f in files) {
// serialization
final fileContent = f.readAsStringSync();
final replacedContent = Configuration.replaceEnvVariables(fileContent, {
'GOOGLE_CLOUD_PROJECT': 'test',
Expand All @@ -57,6 +58,25 @@ void main() {
Configuration.fromJson(jsonContent as Map<String, dynamic>);
final serialized = json.decode(json.encode(config.toJson()));
expect(serialized, jsonContent);

// rate limit rules
final modelFileContent =
await File('lib/audit/models.dart').readAsString();
final rateLimits = config.rateLimits ?? <RateLimit>[];
for (final limit in rateLimits) {
expect(
modelFileContent.contains("'${limit.operation}'"),
isTrue,
reason: limit.operation,
);
}
// no duplicate rules
expect(rateLimits.map((e) => '${e.operation}/${e.scope}').toSet().length,
rateLimits.length);
// some rules for prod config
if (config.isProduction) {
expect(rateLimits, hasLength(greaterThan(10)));
}
}
});
}

0 comments on commit e588d98

Please sign in to comment.