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

failing tests for rate limiter policy validation when 'default' or 'disable' used #2283

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

jakebanks
Copy link
Contributor

@jakebanks jakebanks commented Oct 19, 2023

Debugging during a test run I can see that _rateLimiterPolicyProvider.GetPolicyAsync(rateLimiterPolicyName) always returns null for the values default or disable, and the reason seems to be that the collection the method is reading from is empty - should it contain some default policies?

@jakebanks jakebanks changed the title failing tests for rate limiter policy validation failing tests for rate limiter policy validation when 'default' or 'disable' used Oct 19, 2023
Comment on lines 316 to 317
if (string.Equals(RateLimitingConstants.Default, rateLimiterPolicyName, StringComparison.OrdinalIgnoreCase)
|| string.Equals(RateLimitingConstants.Disable, rateLimiterPolicyName, StringComparison.OrdinalIgnoreCase))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the policy is not null then this line will throw, even if I haven't defined a custom RateLimiter policy with a conflicting name

Copy link
Member

Choose a reason for hiding this comment

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

The current logic looks like it will report an error for a policy with such a name no matter if that policy exists or not, which is unfortunate.

I think this check (name is Default or Disable) should be moved up to before we call GetPolicyAsync, and just early-exit without reporting an error.

The logic that is acting on these policy names looks correct though.
https://github.com/mburumaxwell/reverse-proxy/blob/1be98d88cd42340d67e40fb352bd3431677e6b71/src/ReverseProxy/Routing/ProxyEndpointFactory.cs#L121-L132

Copy link
Member

Choose a reason for hiding this comment

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

I think this check (name is Default or Disable) should be moved up to before we call GetPolicyAsync, and just early-exit without reporting an error.

We do want to report a name conflict though. This check is correct for doing that.

What's missing is that if the policy is null, we should not produce an error for the names Default or Disable. That goes on line 311.

Copy link
Member

Choose a reason for hiding this comment

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

Compare with ValidateCorsPolicyAsync

Copy link
Member

Choose a reason for hiding this comment

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

I adjusted this to match how we validate the auth policy in the prior method.

@Tratcher
Copy link
Member

There should not be policies in the collection with these names, ever, that's what the check is for. However, we need to allow for a null result in that case.

@Tratcher Tratcher marked this pull request as ready for review November 7, 2023 23:39
@Tratcher Tratcher added this to the YARP 2.1 milestone Nov 7, 2023
@Tratcher
Copy link
Member

Tratcher commented Nov 9, 2023

@jakebanks please ack the CLA.

@jakebanks
Copy link
Contributor Author

jakebanks commented Nov 12, 2023

@microsoft-github-policy-service agree company="PageUpPeople"

@jakebanks
Copy link
Contributor Author

jakebanks commented Nov 12, 2023

@jakebanks please ack the CLA.

sorry @Tratcher I only just caught up with your changes, done now

(changes LGTM btw)

@Tratcher Tratcher merged commit 1d18b77 into microsoft:main Nov 13, 2023
7 checks passed
@Tratcher
Copy link
Member

Thanks

@jakebanks jakebanks deleted the jakebanks/ratelimiter branch November 16, 2023 23:02
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.

3 participants