-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1547 from atsign-foundation/apkam_rate_limiter
feat: Implement RateLimiter into enroll_verb_handler and add unit test
- Loading branch information
Showing
11 changed files
with
304 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/at_secondary_server/test/inbound_connection_impl_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:at_secondary/src/connection/inbound/inbound_connection_impl.dart'; | ||
import 'package:at_server_spec/at_server_spec.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main(){ | ||
group('A test to verify the rate limiter on inbound connection', () { | ||
test('A test to verify requests exceeding the limit are rejected', () { | ||
Socket? dummySocket; | ||
AtConnection connection1 = InboundConnectionImpl(dummySocket, 'aaa'); | ||
(connection1 as InboundConnectionImpl).maxRequestsPerTimeFrame = 1; | ||
connection1.timeFrameInMillis = | ||
Duration(milliseconds: 10).inMilliseconds; | ||
expect(connection1.isRequestAllowed(), true); | ||
expect(connection1.isRequestAllowed(), false); | ||
}); | ||
|
||
test('A test to verify requests after the time window are accepted', | ||
() async { | ||
Socket? dummySocket; | ||
AtConnection connection1 = InboundConnectionImpl(dummySocket, 'aaa'); | ||
(connection1 as InboundConnectionImpl).maxRequestsPerTimeFrame = 1; | ||
connection1.timeFrameInMillis = Duration(milliseconds: 2).inMilliseconds; | ||
expect(connection1.isRequestAllowed(), true); | ||
expect(connection1.isRequestAllowed(), false); | ||
await Future.delayed(Duration(milliseconds: 2)); | ||
expect(connection1.isRequestAllowed(), true); | ||
}); | ||
|
||
test('A test to verify request from different connection is allowed', () { | ||
Socket? dummySocket; | ||
AtConnection connection1 = InboundConnectionImpl(dummySocket, 'aaa'); | ||
AtConnection connection2 = InboundConnectionImpl(dummySocket, 'aaa'); | ||
(connection1 as InboundConnectionImpl).maxRequestsPerTimeFrame = 1; | ||
(connection2 as InboundConnectionImpl).maxRequestsPerTimeFrame = 1; | ||
connection1.timeFrameInMillis = | ||
Duration(milliseconds: 10).inMilliseconds; | ||
expect(connection1.isRequestAllowed(), true); | ||
expect(connection1.isRequestAllowed(), false); | ||
expect(connection2.isRequestAllowed(), true); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.