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

[Routing] Unexpected 404 NoConfigurationException #31199

Closed
yceruto opened this issue Apr 22, 2019 · 1 comment
Closed

[Routing] Unexpected 404 NoConfigurationException #31199

yceruto opened this issue Apr 22, 2019 · 1 comment

Comments

@yceruto
Copy link
Member

yceruto commented Apr 22, 2019

Symfony versions affected: 3.4, 4.2, master

Given the following route definition:

api:
    path: /
    schemes: ['https']
    methods: ['POST']
    # ...

this GET http://127.0.0.1:8000/ will return the Symfony welcome page (404) instead of the automatic redirection to https (301) and finally the expected "Method not allowed" (405) exception.

Currently, there is a test case that exactly covers the previous scenario and a pure ResourceNotFoundException is expected due to the https scheme mismatch:

/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testSchemeAndMethodMismatch()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', [], [], [], null, ['https'], ['POST']));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/');
}

now it's working because NoConfigurationException extends from ResourceNotFoundException.

How to reproduce

Just changes ResourceNotFoundException by NoConfigurationException in the test case and look how it pass.

Possible Solution

Still working on it... hints are welcome.

By now, I'm trying to collect $this->allowSchemes as was done in 4.2 and update this line:

if ('/' === $pathinfo && !$this->allow) {
throw new NoConfigurationException();
}

We might need a separate bugfix PR for 4.2+

@yceruto
Copy link
Member Author

yceruto commented Apr 23, 2019

Something else is happening in 4.2 where $allowSchemes is being taken into account:

if ('/' === $pathinfo && !$allow && !$allowSchemes) {
throw new NoConfigurationException();
}

I gonna check this today

nicolas-grekas added a commit that referenced this issue May 9, 2019
…ceruto)

This PR was merged into the 4.2 branch.

Discussion
----------

[Routing] Fixed unexpected 404 NoConfigurationException

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31199
| License       | MIT

This is the patch for 4.2+
We need a different patch for 3.4 that is more complex, I think.

Commits
-------

aa71a42 [Routing] Fixed unexpected 404 NoConfigurationException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants