-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
FIX IntegrationTestTrait failing with FormProtector when debug disabled #17490
base: 5.x
Are you sure you want to change the base?
Conversation
Is there a use case of running tests without debug mode? I wasnt aware of that. |
In my case, I want to test the production error page, yes I could make a hidden page that is somehow disabling FormProtector on that request and/or manually trigger showing error page then test it that way. For example if the FormProtection kicks in, I was thinking of making a test to verify that it looks correct and show what's expected, especially not the debug page. I'm also reviewing the currently failing test, in \Cake\TestSuite\IntegrationTestTrait::_addTokens the code adds those fields essentially unlocking all provided data, so I'm thinking how it was failing before if I only removed the debug from the request that was not supposed to be there in the first place based on the FormProtector |
And also all my tests in CI/CD run with debug set to false (probably by accident, but that reflects more the way it's going to run in production) |
Do I understand it correctly, that the cakephp CI/testsuite also run with debug mode not enabled? Or I'm missing something in those test cases? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good to me. It would be good to have a test added so that we don't regress this in the future.
I can add test for that case over the weekend. |
There's also a failing test which seems related to this change. |
The failing test is also very strange, as I don't understand how that test could pass in the first place, by the logic if you don't provide unlocked field, the logic automatically is unlocking all fields provided as input, because in Can look more into it over weekend. |
Ping @kolorafa |
When doing a test post request to a endpoint with enabled form protector while having debug disabled, then the form protector will always fail.
Example of failing test:
The test result:
The culprit code that is failing the request:
If the debug is disabled then the debug field should not be set.
But not only FormProtector::buildTokenData is always setting the debug, but on top of it the IntegrationTestTrait doesn't care about debug and always additionally set/override this variable.
When printing the form, this field in FormHelper is skipped/not included if not in debug.