Skip to content
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

Policy: Rate-limit fix window exception #1113

Merged
merged 1 commit into from
Sep 12, 2019

Conversation

eloycoto
Copy link
Contributor

@eloycoto eloycoto commented Sep 4, 2019

On rate-limit window can be set as 0 so the division that happens on
resty will fail due to division by 0 is not allowed.

This commit fixes that and validates that window value is bigger than 0,
if not set the default to 1. Also, add an integration test to prove this
scenario and update the JSON schema to verify that the number is a valid
integer.

FIX: THREESCALE-3382

JSONSchema changes:
https://mozilla-services.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJmaXJzdE5hbWUiOiJDaHVjayIsImxhc3ROYW1lIjoiTm9ycmlzIiwiYWdlIjo3NSwiYmlvIjoiUm91bmRob3VzZSBraWNraW5nIGFzc2VzIHNpbmNlIDE5NDAiLCJwYXNzd29yZCI6Im5vbmVlZCJ9LCJzY2hlbWEiOnt9LCJ1aVNjaGVtYSI6e319

Signed-off-by: Eloy Coto [email protected]

@eloycoto eloycoto requested a review from a team as a code owner September 4, 2019 16:07
@@ -181,6 +181,7 @@
"type": "array",
"items": {
"type": "object",
"required": ["key", "count", "window"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that in the other kind of limiters, the number used to limit is not required. I think it's the same case as window here. Have you checked them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, tested the others and no division happens.

Copy link
Contributor

@davidor davidor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good 👍
I just added some minor comments.

@@ -196,7 +197,8 @@
"window": {
"type": "integer",
"description": "The time window in seconds before the request count is reset",
"exclusiveMinimum": 0
"exclusiveMinimum": 0,
"default": 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default needed? It's required and there's a minimum value.

Also, this made me think about the limit in count (I know it's not part of the PR), but it's also exclusiveMinimum: 0. Not sure if that's correct. Should we allow 0 to reject always?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1313,3 +1313,62 @@ limit. The limit is set to 2. Only the third one should fail.
[200, 200, 429]
--- no_error_log
[error]


=== TEST 22: Window is not set and default to 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title does not seem to be correct. In the config, window is set to 0.

window = 0
}
},
redis_url = "redis://$TEST_NGINX_REDIS_HOST:$TEST_NGINX_REDIS_PORT/1",
Copy link
Contributor

@davidor davidor Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: if you don't define this limit as global, you will not need redis, and you'll be able to simplify a bit the test. You'll be able to delete this line, and also the /flush_redis location and the first request in the test.

@eloycoto eloycoto force-pushed the RateLimitIssue branch 3 times, most recently from be91f44 to 9374110 Compare September 9, 2019 08:57
On rate-limit window can be set as 0 so the division that happens on
resty will fail due to division by 0 is not allowed.

This commit fixes that and validates that window value is bigger than 0,
if not set the default to 1. Also, add an integration test to prove this
scenario and update the JSON schema to verify that the number is a valid
integer.

FIX: THREESCALE-3382

Signed-off-by: Eloy Coto <[email protected]>
@eloycoto eloycoto merged commit d818e1a into 3scale:master Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants