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

Fix #20309 - URL Rewrites redirect loop #26902

Conversation

Bartlomiejsz
Copy link
Contributor

@Bartlomiejsz Bartlomiejsz commented Feb 17, 2020

Description (*)

This is fix for #20309 - as @ihor-sviziev mentioned in #25848 (review) - adding validation for such redirect wouldn't fix the issue for i.e. existing stores. So I added check in url rewrite router, which doesn't allow to redirect if request path is equal to target path.

Related Pull Requests

Fixed Issues (if relevant)

  1. URL Rewrites redirect loop #20309: URL Rewrites redirect loop

Manual testing scenarios (*)

Please check fixed issue for steps to test

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Feb 17, 2020

Hi @Bartlomiejsz. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@Bartlomiejsz Bartlomiejsz linked an issue Feb 17, 2020 that may be closed by this pull request
@Bartlomiejsz Bartlomiejsz force-pushed the feature/fix_20309_url_rewrites_redirect_loop branch from b39059e to b8f43c3 Compare February 17, 2020 22:33
@ihor-sviziev ihor-sviziev self-assigned this Feb 18, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

@Bartlomiejsz,
Your changes looks good, but there is some nitration test failure. Could you fix it?

@Bartlomiejsz Bartlomiejsz force-pushed the feature/fix_20309_url_rewrites_redirect_loop branch from b8f43c3 to 684b951 Compare February 18, 2020 21:52
@Bartlomiejsz
Copy link
Contributor Author

@ihor-sviziev done

@ihor-sviziev ihor-sviziev added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Feb 25, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

@Bartlomiejsz,
URL rewrites it quite complex thing, and there is a lot of potential issues. Thank you so much for covering your changes with unit tests, but I think it's better to cover this change with integration tests. Will you be able to do that?

Recently there were fix for URL rewrites, it was covered by integration tests, I think it's good example. Use cases were defined here:
#18717 (comment)

I've did integration test coverage for such cases:
b1a2a29

Note: seems like there not just one case, there should be also checked cases with get params

@ghost ghost dismissed ihor-sviziev’s stale review February 25, 2020 13:12

Pull Request state was updated. Re-review required.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

See above

@Bartlomiejsz
Copy link
Contributor Author

Hi @ihor-sviziev,
I don't really have experience with writing integration tests, so if that would be possible for you that would be great.
Otherwise it will take some time for me to prepare those but can try - just please let me know

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Feb 25, 2020

@Bartlomiejsz not sure if I'll have free time to help you. But actually integration tests are quire similar to and even maybe simpler than unit tests, let's try.

Please try following instruction:
https://devdocs.magento.com/guides/v2.3/test/integration/integration_test_execution.html

@Bartlomiejsz Bartlomiejsz force-pushed the feature/fix_20309_url_rewrites_redirect_loop branch from 26de9f7 to ec3cdb9 Compare February 26, 2020 22:43
ihor-sviziev
ihor-sviziev previously approved these changes Feb 27, 2020
@ghost ghost removed the Progress: review label Feb 27, 2020
@ihor-sviziev
Copy link
Contributor

@Bartlomiejsz Good job! Approved!

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-6995 has been created to process this Pull Request

@engcom-Delta engcom-Delta self-assigned this Mar 3, 2020
Copy link
Contributor

@engcom-Delta engcom-Delta left a comment

Choose a reason for hiding this comment

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

@Bartlomiejsz , @ihor-sviziev this PR implements only one point from #25848 (review):

  • adjust logic to do NOT perform redirect in case of target path equal to request path

But there is no implemented patch that will find & delete all such incorrect URL and no validation for same request-path and target_path in admin.
Now behavior with PR is next:

  • Url Rewrite with request-path: foo and target_path foo with 301 or 302 redirect is successfully created
  • Getting 404 Page not found error when such url was requested
    image

Is this expected behavior of PR?

@ghost ghost dismissed ihor-sviziev’s stale review March 3, 2020 11:45

Pull Request state was updated. Re-review required.

@Bartlomiejsz
Copy link
Contributor Author

Hi @engcom-Delta, as @ihor-sviziev mentioned there, those two options, and I'm pretty sure the one implemented in current PR makes second not needed. Because even with those rewrites being still in database, no issue should be spotted on FE.
And for your example - I'm pretty sure this is correct. Please verify clean 2.4-develop for same case, you should receive ERR_TOO_MANY_REDIRECTS error. And with the fix, it redirects only if target_path is different then url on which you are currently.
So there is 404 if there is no such page, and if you will add rewrite with existing url (like contact -> contact) this should just show you the contact page

@ihor-sviziev
Copy link
Contributor

@engcom-Delta i totally agree with @Bartlomiejsz . What you’ve shown - expected result. What you said - it could be improved, but main issue is fixed by this PR

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-6995 has been created to process this Pull Request

@engcom-Delta
Copy link
Contributor

✔️ QA passed

@m2-assistant
Copy link

m2-assistant bot commented Mar 12, 2020

Hi @Bartlomiejsz, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@Bartlomiejsz Bartlomiejsz deleted the feature/fix_20309_url_rewrites_redirect_loop branch June 23, 2020 20:41
@sdzhepa sdzhepa mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL Rewrites redirect loop
4 participants