-
Notifications
You must be signed in to change notification settings - Fork 3
Named rule support; v1.4.0 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ describe('src/config', function () { | |
| creditLimit: 100, | ||
| resetSeconds: 60, | ||
| actorField: 'ip', | ||
| label: null, | ||
| comment: '100 rpm for /ping for authenticated users, by ip', | ||
| }, rule); | ||
|
|
||
|
|
@@ -47,6 +48,7 @@ describe('src/config', function () { | |
| creditLimit: 10, | ||
| resetSeconds: 60, | ||
| actorField: 'ip', | ||
| label: 'get-ping-by-ip', | ||
| comment: '10 rpm for /ping for non-authenticated users, by ip', | ||
| }, rule); | ||
|
|
||
|
|
@@ -64,6 +66,7 @@ describe('src/config', function () { | |
| creditLimit: 5, | ||
| resetSeconds: 60, | ||
| actorField: 'ip', | ||
| label: 'post-by-ip', | ||
| comment: '5 rpm for any POST, by ip', | ||
| }, rule); | ||
|
|
||
|
|
@@ -75,6 +78,7 @@ describe('src/config', function () { | |
| creditLimit: 1, | ||
| resetSeconds: 60, | ||
| actorField: '', | ||
| label: null, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most configs won't explicitly set |
||
| comment: 'Default quota', | ||
| }, rule); | ||
| }); | ||
|
|
@@ -102,6 +106,22 @@ describe('src/config', function () { | |
| }, /Invalid creditLimit/); | ||
| }); | ||
|
|
||
| it('with a rule containing an invalid label', function () { | ||
| const config = new Config(); | ||
| config.addRule({ service: 'myservice', method: 'GET' }, 0, 60, null, 'nice-rule'); | ||
| assert.throws(() => { | ||
| config.addRule({ service: 'myservice', method: 'POST' }, 0, 60, null, 'this is fine'); | ||
| }, /Invalid rule label "this is fine"/); | ||
| }); | ||
|
|
||
| it('with a rule containing a duplicate label', function () { | ||
| const config = new Config(); | ||
| config.addRule({ service: 'myservice', method: 'GET' }, 0, 60, null, 'nice-rule'); | ||
| assert.throws(() => { | ||
| config.addRule({ service: 'myservice', method: 'POST' }, 0, 60, null, 'nice-rule'); | ||
| }, /A rule with label "nice-rule" already exists/); | ||
| }); | ||
|
|
||
| it('with a rule where resetSeconds < 1', function () { | ||
| const config = new Config(); | ||
| config.addRule({ service: 'myservice', method: 'GET' }, 20, 1); | ||
|
|
@@ -119,8 +139,8 @@ describe('src/config', function () { | |
| it('handles simple glob keys', function () { | ||
| const config = new Config(); | ||
|
|
||
| config.addRule({ service: 'my*', method: 'GET' }, 100, 60, 'actor', 'a'); | ||
| config.addRule({ service: 'your*', method: 'GET' }, 200, 40, 'jim', 'b'); | ||
| config.addRule({ service: 'my*', method: 'GET' }, 100, 60, 'actor', 'rule-a', 'a'); | ||
| config.addRule({ service: 'your*', method: 'GET' }, 200, 40, 'jim', 'rule-b', 'b'); | ||
|
|
||
| const rule = config.findRule({ service: 'myget', method: 'GET' }); | ||
| assert.deepEqual({ | ||
|
|
@@ -131,6 +151,7 @@ describe('src/config', function () { | |
| creditLimit: 100, | ||
| resetSeconds: 60, | ||
| actorField: 'actor', | ||
| label: 'rule-a', | ||
| comment: 'a', | ||
| }, rule); | ||
|
|
||
|
|
@@ -143,6 +164,7 @@ describe('src/config', function () { | |
| creditLimit: 200, | ||
| resetSeconds: 40, | ||
| actorField: 'jim', | ||
| label: 'rule-b', | ||
| comment: 'b', | ||
| }, other); | ||
| }); | ||
|
|
@@ -164,6 +186,7 @@ describe('src/config', function () { | |
| creditLimit: 1, | ||
| resetSeconds: 60, | ||
| actorField: 'ip', | ||
| label: null, | ||
| comment: '1 rpm for POST /account*, by ip', | ||
| }, rule); | ||
|
|
||
|
|
@@ -181,6 +204,7 @@ describe('src/config', function () { | |
| creditLimit: 5, | ||
| resetSeconds: 60, | ||
| actorField: 'ip', | ||
| label: 'post-by-ip', | ||
| comment: '5 rpm for any POST, by ip', | ||
| }, rule); | ||
| }); | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since label is an optional argument, why position it second to last?
there's a bunch of places in
tests/config-test.jsthat will need to be updated to reflect this positional change.alternatively, since the cardinality of this function is getting big, what are your thoughts on having it accept an arguments object instead of positional arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since both
labelandcommentare optional, am guessing I somewhat arbitrarily decided labels will be more common than comments.I like it, that'd definitely make it a bunch more readable! May sheepishly defer this suggestion as am running into limited cycles to iterate further. OK with you to land as is?