Skip to content

[Routing] Unexpected 404 NoConfigurationException #31199

Closed
@yceruto

Description

@yceruto

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+

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions