phpinnacle / ridge

Pure asynchronous PHP implementation of the AMQP 0-9-1 protocol.
MIT License
50 stars 13 forks source link

Passing an incorrect vhost does not result in throwing an exception #19

Closed michalzielanski closed 2 years ago

michalzielanski commented 3 years ago

When we pass an invalid vhost, the broker sends a ConnectionCloseFrame and terminates the connection, but Ridge does not capture this frame and does not throw an exception. Example:

use Amp\Loop;
use PHPinnacle\Ridge\Client;

Loop::run(function () {
    $client = Client::create('amqp://guest:guest@localhost:5672/unknown-vhost');

    yield $client->connect();

    echo "Execution will never get here. Nor will an exception be thrown.";

    // (...)
});

This code:

asyncCall(function () {
    yield $this->await(Protocol\ConnectionCloseFrame::class);

    // (...)
});

should be in front of: https://github.com/phpinnacle/ridge/blob/adcced8abecc26ec26c407fb18e3ef59bcb06594/src/Client.php#L122-L124 and should respond appropriately depending on the reason for closing the connection. If we pass the wrong vhost replyCode is 530 (decimal) and replyText "NOT_ALLOWED - vhost unknown-vhost not found".

Additionally, the status change to STATE_DISCONNECTING and STATE_NOT_CONNECTED is missing in the code below. https://github.com/phpinnacle/ridge/blob/adcced8abecc26ec26c407fb18e3ef59bcb06594/src/Client.php#L126-L141

mmasiukevich commented 2 years ago

24