silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
721 stars 821 forks source link

[DEV] FunctionalTest SimpleForm double submission bug #2874

Open willmorgan opened 10 years ago

willmorgan commented 10 years ago

When using a standalone Controller, If I run FunctionalTest->submitForm() twice, the second call will erroneously return a 404 because of a malformed form action attribute.

Rough test code:

    // Test a double signup can't happen
    $this->get('MemberModuleTest');
    // $response gives you a SS_HTTPResponse with a form with an action pointing to MemberModuleTestController/LoginGatewayForm
    $response = $this->submitForm('LoginGatewayForm_LoginGatewayForm', 'action_checkEmailAction', array(
        'Email' => $nonExistentEmail,
    ));
    // $response gives you a SS_HTTPResponse with a 404 body
    $response = $this->submitForm('LoginGatewayForm_LoginGatewayForm', 'action_registerAction', array(
        'Email' => $signupEmail,
        'Password' => $signupPassword,
    ));

My custom form doesn't do anything weird with the FormAction attribute, and for now I have worked around the issue by making the MemberModuleTestController provide an absolute Link function return.

As far as I can see there's a problem with the thirdparty SimpleURL->asString method which mangles the URL slightly.

Thanks to @dhensby who worked with me in the role of "rubber duck". :smiling_imp:

dhensby commented 10 years ago

Yep, it looks like the simpleform tester assumes that relative links are absolute so parses them incorrectly and returns them with a leading "http://".

So, it sees a form with action "controller/Form" and returns "http://controller/Form" as the URL.