-
Notifications
You must be signed in to change notification settings - Fork 27
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
PHPBrowser module: Wrong url sent and request does not match codeception debug output #50
Comments
How about making sure that your URL starts with '/' if you don't want it appended to previous URL? |
Sure, but why even have a previous url appended anyway..? Seems counter-intuitive. |
Because that is how relative URLs work. |
No, relative URLs are relative to a specific base path, not random based on your previous history. In the output I've posted above it shows how random the creation is. My previous request was "/me/avatar" and the next one was "me/web/storage..". So it decided to only keep the "/me" part while according to your argument it should have been "/me/avatar/web/storage...". It just doesnt make sense. |
It is absolutelly correct, you just don't get it. Since there is no |
I'm sorry, is this issue about the definition of relative/absolute urls or an unexpected behavior of codeception that is not documented anywhere..? Are you going to focus on that or not..? In the documentation https://codeception.com/docs/modules/REST under sendGET/HEAD sections it clearly says:
It does not talk about any relative uri, and I even would accept it if it was relative to the base url you provide in the configuration of the REST module, which in my case is These are the issues, not the definitions. |
Discovered this feature also, while sending multiple delete requests, one after another. //delete as reader - no access to delete
$I->amBearerAuthenticated(self::VALID_BEARER_READER);
$I->sendDelete('tasks/86');
$I->canSeeResponseCodeIs(HttpCode::NOT_FOUND);
//delete as assigner - no access to delete
$I->amBearerAuthenticated(self::VALID_BEARER_ASSIGNER);
$I->sendDelete('tasks/86');
$I->canSeeResponseCodeIs(HttpCode::NOT_FOUND); Second delete would be a And the test is false positive. While i understand the relative/absolute url argumentation, it should be at least documented for security. |
What are you trying to achieve?
Assert that a file can be retrieved from a webserver using the REST module with PHPBrowser, by checking if the status code is equal to 200. The file exists on the server and can be retrieved using CURL with the same url as shown in the debug output of codeception.
What do you get instead?
Failed asserting that 404 matches expected 200 and wrong debug output of codeception.
Root cause
I've managed to successfully reproduce it and I think I've tracked down the issue:
My setup consists of docker images (nginx image proxying to php-fpm image) defined in a docker-compose.yml file as service web and app respectively. Codeception is run in separate docker image attached to the same network.
The problem seems to be the PHPBrowser
url
parameter as defined in the suite config file shown below. When there is no port defined and the url ishttp://web
(the name of the nginx host since it listens to port 80) it sends a completely wrong url to the webserver. Instead of sendingweb/storage/avatars/...
as described in the debug output of codeception the actual url received by nginx isme/web/storage/avatars/..
. You can see nginx logs below for more details. Now where did thatme
came from..??It turns out that if you define a port in the PHPBrowser url variable, such as
http://web:80
everything works as expected and the test passes. If you don't, like described above and for the specific test case I have posted below the url gets messed up and looks to be resolved from History urls.Looking at the codeception src code the offending method seems to be in vendors symfony/browser-kit: https://github.com/symfony/browser-kit/blob/c55fe9257003b2d95c0211b3f6941e8dfd26dffd/Client.php#L322.
Looking at that method, specifically here: https://github.com/symfony/browser-kit/blob/c55fe9257003b2d95c0211b3f6941e8dfd26dffd/Client.php#L593 it seems that it tries to resolve the url based on History urls and since for my specific testcase I already have a previous http request sent in the same test, the url gets wrongly constructed.
Workaround
The workaround is, as shown above, to always define the port even if it is 80 or 443. I don't understand why the url needs to be constructed using previous history and I cannot say I agree with that approach but I also cannot suggest a fix at the moment.
Details
Codeception output:
Nginx access log:
Details
The text was updated successfully, but these errors were encountered: