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

#683 Validate placeholder duplicates in path templates #1927

Merged
merged 14 commits into from
Mar 26, 2024

Conversation

AlyHKafoury
Copy link
Contributor

@AlyHKafoury AlyHKafoury commented Jan 19, 2024

@AlyHKafoury
Copy link
Contributor Author

@raman-m Draft for a better exception handling in upstreamcreator

@raman-m raman-m added the in progress Someone is working on the issue. Could be someone on the team or off. label Jan 19, 2024
@AlyHKafoury AlyHKafoury marked this pull request as ready for review January 19, 2024 11:11
@AlyHKafoury
Copy link
Contributor Author

@raman-m if we agree on the first solution which is failing gracefully, then this PR should do exactly that

@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

@AlyHKafoury
What was/is the line of code which generates original ArgumentOutOfRangeException error?
Have you reproduced the bug?

I'm not sure that simple exception throwing is right... But, yes, technically we provide information about invalid route.
Also, @philproctor recommended on Jan 10, 2019 to update validators. So, having validation error + exception throwing by UpstreamTemplatePatternCreator will be one solid solution.

Let's discuss more with the team...
@RaynaldM @ggnaegi We need your attention here. My design approach is here, please read it.

@raman-m raman-m requested review from RaynaldM and raman-m January 19, 2024 11:31
@AlyHKafoury
Copy link
Contributor Author

@raman-m I reproduced with the included unit test. the line that fails is this line

var indexOfNextForwardSlash = upstreamTemplate.IndexOf("/", indexOfPlaceholder, StringComparison.Ordinal);

the reason is indexOfPlaceholder is -1 because instead of matching the first place holder in the line it matches the last 1 causing a whole set of unexpected behaviors to happen. Even if we like fix this part and allow duplicate placer-holders this will cause alot of issues down the line

@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

Ok, got it! You've reproduced the bug by unit test. Please, postpone work on this. Or review related acceptance tests, if there is no something similar then write a new acceptance test to repro the bug too.

Need to discuss final design with the team.
Therefore, this PR remains a draft.

@AlyHKafoury AlyHKafoury marked this pull request as draft January 19, 2024 12:11
@AlyHKafoury
Copy link
Contributor Author

@raman-m Other issues to work on ?

@raman-m
Copy link
Member

raman-m commented Jan 19, 2024

AlyHKafoury:Fix-683
😃 Instead of free naming convention for feature branch, better to use original issue label which is label: bug
So, feature name could be bug-683 or bug/683.
Finally, it doesn't matter because branch name can have any name 🤣 even 683 and it is correct because I can find the issue in backlog by the number.

Conclusion: So presenting of issue number in branch name is must-have.

@raman-m raman-m added the bug Identified as a potential bug label Jan 19, 2024
@raman-m raman-m changed the title #683 Fix : Ocelot crashes if there are same-named Catch-Alls #683 Validate placeholder duplicates in path templates Jan 20, 2024
@raman-m raman-m marked this pull request as ready for review January 20, 2024 09:51
Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Hi Aly!
I've marked the PR as ready for reviews, so we can continue development, because the author replied to us.
So, please read new requirements of linked issue #683 and let's get started active development once again.

@AlyHKafoury
Copy link
Contributor Author

AlyHKafoury commented Jan 20, 2024

@raman-m since we are going to catch this early during validation should I remove exception handling at the upstreamceator stage ?


Update by Maintainer on Jan 26

Yes, please remove the exception. See my answer above ☝️

@AlyHKafoury
Copy link
Contributor Author

@raman-m this is strange there is already a validator in here :

.Must((_, route) => IsPlaceholderNotDuplicatedIn(route.UpstreamPathTemplate))

and a test for it in here :

public void configuration_is_invalid_when_placeholder_is_used_twice_in_upstream_path_template()

The point is the current rule now checks for upstream only should I add also downstream check for this and a unit test for it or are we good with the only checking the upstream

@AlyHKafoury
Copy link
Contributor Author

@raman-m this is strange there is already a validator in here :

.Must((_, route) => IsPlaceholderNotDuplicatedIn(route.UpstreamPathTemplate))

and a test for it in here :

public void configuration_is_invalid_when_placeholder_is_used_twice_in_upstream_path_template()

The point is the current rule now checks for upstream only should I add also downstream check for this and a unit test for it or are we good with the only checking the upstream

Yes the current problem is with downstream path only being duplicate, so I will add rule for that and add unit test for it

@raman-m
Copy link
Member

raman-m commented Jan 26, 2024

Please, add user scenario of bug #683 into a test.

Also, I'd ask you to check the following...
Are there some tests which check that each upstream placeholder is presented in downstream with the same name?
If Yes, it is fine.
If No, we have to add this validation rule too.

@AlyHKafoury AlyHKafoury requested a review from raman-m January 26, 2024 19:03
Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Please, work more and independently 😉
When you request code review, the build should be passed. Seems your code is not complete.

@raman-m
Copy link
Member

raman-m commented Feb 16, 2024

@AlyHKafoury Please resolve the merge conflict!

@AlyHKafoury
Copy link
Contributor Author

On it

@raman-m
Copy link
Member

raman-m commented Feb 17, 2024

And merge develop to feature branch plz!
But it is better to rebase onto develop

@raman-m
Copy link
Member

raman-m commented Mar 24, 2024

@AlyHKafoury Hi Aly!
How do you do?
What is the rest of the work here?

@raman-m raman-m added Feb'24 February 2024 release and removed in progress Someone is working on the issue. Could be someone on the team or off. labels Mar 24, 2024
@raman-m raman-m added this to the February'24 milestone Mar 24, 2024
@raman-m
Copy link
Member

raman-m commented Mar 24, 2024

@AlyHKafoury The feature branch has been rebased today ❗
Please delete local branch, fetch all, and checkout once again!

TODO: Tomorrow I will continue fixing of failed Acceptance tests...
A common failure is Unable to start Ocelot, errors are: xxx due to missing placeholder in a path template.

@raman-m
Copy link
Member

raman-m commented Mar 25, 2024

Aly, where are you? Seems you live in Egypt... So, your time zone is +2 with 1-2 hours shift.
Ok, if you are not interested in this contribution then just ignore my comments.
I will deliver this bug fix by my own.

@raman-m raman-m self-assigned this Mar 25, 2024
@raman-m
Copy link
Member

raman-m commented Mar 25, 2024

TODO

  • Fix integration tests. Done by b4105c0
  • Release notes. Done by 11916b6

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Ready for delivery ✅

@raman-m raman-m merged commit 4f0e483 into ThreeMammals:develop Mar 26, 2024
2 checks passed
@raman-m raman-m mentioned this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug Feb'24 February 2024 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ocelot crashes if there are same-named Catch-Alls e.g. foo/{bar}/{bar}
3 participants