Skip to content

[spiral/testing] fakeHttp do not work with custom auth transport #1231

@shanginn

Description

@shanginn

Description

In tests the withActor method in fakeHttp do not work with custom auth transport (like header) giving the error:

Received response status code [500 : ] but expected 200. Body: {
    "type": "Spiral\\Auth\\Exception\\TransportException",
    "message": "Undefined auth transport header",
    "code": 0,
    "file": "/app/vendor/spiral/framework/src/AuthHttp/src/TransportRegistry.php",
    "line": 34,
    "trace": [
        {
            "file": "/app/vendor/spiral/framework/src/AuthHttp/src/Middleware/AuthTransportMiddleware.php",
            "line": 58,
            "function": "getTransport",
            "class": "Spiral\\Auth\\TransportRegistry",
            "type": "->",
            "args": [
                "header"
            ]
        },
        {
...

How To Reproduce

I created a repo with spiral skeleton and single test to reproduce the issue (no docker or anything, minimal setup): https://github.com/shanginn/spiral-with-actor-tests-bug

Additional Info

Q A
Framework Version ^3.15
PHP version 8.4
spiral/testing 2.9.1

Probably this is due the code in the FakeHttp::handleRequest() that register only one transport and disregard any existing ones.

if ($this->actor) {
    $request = $request->withHeader(static::AUTH_TOKEN_HEADER_KEY, \spl_object_hash($this->actor));

    $bindings[ActorProviderInterface::class] = new FakeActorProvider($this->actor);
    $bindings[TokenStorageInterface::class] = new FakeTokenStorage();

    $transport = new TransportRegistry();
    $transport->setTransport('testing', new HeaderTransport(static::AUTH_TOKEN_HEADER_KEY));
    $bindings[TransportRegistry::class] = $transport;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions