Functional testing with Spring Security plugin in a Grails app

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Functional testing with Spring Security plugin in a Grails app

Fran García
I have a secured grails application with the spring security plugin and right now I am trying to do some tests with the login process with no success till now. Has anybody an idea of what is the problem?

This is my LoginPage.groovy

        package pages.login
       
        import geb.Page
       
       
        class LoginPage extends Page {
                static url = "login/auth"
               
                static at = {
                        title ==~ /Login/
                }
               
                static content = {
                        loginForm { $("form") }
                        username { $("input", type:"text", name:"j_username") }
                        password { $("input", type:"password", name:"j_password") }
                        loginButton{ $("input", type:"submit", value:"Login") }
                }
        }

And this is the test using junit4:

        import geb.junit4.GebReportingTest
       
        import pages.copyright.*
        import pages.login.LoginPage
        import org.junit.Test
       
        class CopyrightCRUDTests extends GebReportingTest {
       
                @Test
                void doSomeCrud() {
               
                        to LoginPage
                        at LoginPage
                        $("form").j_username() << "admin"
                        $("form").j_password() << "XXXXX"
                        loginButton.click()

                        to AuthenticatedPage
                        at AuthenticatedPage
               
                }
        }

The AuthenticatedPage is a page which needs authentication, but in this moment it is imposible to be authenticated using geb. Does anybody know anything about this issue?

Thanks in advance!
What doesn't kill you, makes you stronger
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Jeri Levine
Where exactly is your test failing, do you know?  Does it make it to the login page?  Does it click the login button but then you end up somewhere other than AuthenticatedPage?

--Jeri

On Wed, Oct 10, 2012 at 9:55 AM, Fran García <[hidden email]> wrote:
I have a secured grails application with the spring security plugin and right
now I am trying to do some tests with the login process with no success till
now. Has anybody an idea of what is the problem?

This is my LoginPage.groovy

        package pages.login

        import geb.Page


        class LoginPage extends Page {
                static url = "login/auth"

                static at = {
                        title ==~ /Login/
                }

                static content = {
                        loginForm { $("form") }
                        username { $("input", type:"text", name:"j_username") }
                        password { $("input", type:"password", name:"j_password") }
                        loginButton{ $("input", type:"submit", value:"Login") }
                }
        }

And this is the test using junit4:

        import geb.junit4.GebReportingTest

        import pages.copyright.*
        import pages.login.LoginPage
        import org.junit.Test

        class CopyrightCRUDTests extends GebReportingTest {

                @Test
                void doSomeCrud() {

                        to LoginPage
                        at LoginPage
                        $("form").j_username() << "admin"
                        $("form").j_password() << "XXXXX"
                        loginButton.click()

                        to AuthenticatedPage
                        at AuthenticatedPage

                }
        }

The AuthenticatedPage is a page which needs authentication, but in this
moment it is imposible to be authenticated using geb. Does anybody know
anything about this issue?

Thanks in advance!



-----
What doesn't kill you, makes you stronger
--
View this message in context: http://grails.1312388.n4.nabble.com/Functional-testing-with-Spring-Security-plugin-in-a-Grails-app-tp4636273.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
Jeri Levine
Senior Software Quality Engineer
Chemical Biology Informatics Platform
Broad Institute of Harvard & MIT
7 Cambridge Center
Cambridge, MA 02142
617-714-7385
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Fran García
The test fails after the click event in the loginButton and the user can never login the application.
What doesn't kill you, makes you stronger
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Steve Ronderos-2
I have a very similar use case and it is working.  Our code has a few differences.

Mine (slightly modified because my login page is not exactly the spring security page out of the box): 

class LoginPage extends Page {
    static url = "login"
    static at = { title == "Login" }
    static content = {
        errorMessage { $("div.errors").text() }
        loginForm { $("form") }
        loginButton { $("input", value: "Login") }
    }
}

class OrderGebTests extends GebReportingTest {
    @Before
    void setUp() {
        to (LoginPage)
        loginForm.j_username = 'user'
        loginForm.j_password = 'password'
        loginButton.click()
    }
    @Test
    void testCreatePage() {
        to(CreatePage)
        at(CreatePage)
    }
... 


It has been awhile since I wrote these tests, I'm pretty sure that I had problems using '$' in the actual tests.  Instead in all of my tests I declare the form in the static content block of the Page class and use that as a base for my searches.

Hope this helps!
Steve


On Thu, Oct 11, 2012 at 2:26 PM, Fran García <[hidden email]> wrote:
The test fails after the click event in the loginButton and the user can
never login the application.



-----
What doesn't kill you, makes you stronger
--
View this message in context: http://grails.1312388.n4.nabble.com/Functional-testing-with-Spring-Security-plugin-in-a-Grails-app-tp4636273p4636392.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Fran García
So, you are not using Spring Security plugin? Because I think this is the problem. I think it is something due to https requests but I am not quite sure. I have another tests sending posts without problems but the login process using Spring Security plugin is not posible.

Has anybody an idea of what is happening? I have been reading something about mocking out authentication with SSP (http://forum.springsource.org/showthread.php?108101-Mocking-out-authentication-for-functional-tests-when-using-Spring-Security) but I don't know how to deal with that.
What doesn't kill you, makes you stronger
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Steve Ronderos-2
I am using the Spring Security plugin, I am however using a custom RequestHolderAuthenticationFilter.  I don't think that should have any effect.  

What version of Grails and Geb are you using.  Also, what is your Geb configuration?  

Finally, are you certain that the user is created during test bootstrap?  If you add "errorMessage { $("div.errors").text() }" to the content on your page then you can assert the contents after the login button is hit.  That may help by giving you a better error message.

Good luck,
Steve

On Fri, Oct 12, 2012 at 10:06 AM, Fran García <[hidden email]> wrote:
So, you are not using Spring Security plugin? Because I think this is the
problem. I think it is something due to https requests but I am not quite
sure. I have another tests sending posts without problems but the login
process using Spring Security plugin is not posible.

Has anybody an idea of what is happening? I have been reading something
about mocking out authentication with SSP (
http://forum.springsource.org/showthread.php?108101-Mocking-out-authentication-for-functional-tests-when-using-Spring-Security
<http://forum.springsource.org/showthread.php?108101-Mocking-out-authentication-for-functional-tests-when-using-Spring-Security>
) but I don't know how to deal with that.



-----
What doesn't kill you, makes you stronger
--
View this message in context: http://grails.1312388.n4.nabble.com/Functional-testing-with-Spring-Security-plugin-in-a-Grails-app-tp4636273p4636473.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Jeri Levine
I agree with getting the error message that is actually coming up.  Another thing you can do, if you haven't already, is to have a look at the report coming back from Geb for your test -- it should have captured the application state at the end of the test.  Then you can see what happened after the loginButton was clicked.

--Jeri

On Fri, Oct 12, 2012 at 12:30 PM, Steve Ronderos <[hidden email]> wrote:
I am using the Spring Security plugin, I am however using a custom RequestHolderAuthenticationFilter.  I don't think that should have any effect.  

What version of Grails and Geb are you using.  Also, what is your Geb configuration?  

Finally, are you certain that the user is created during test bootstrap?  If you add "errorMessage { $("div.errors").text() }" to the content on your page then you can assert the contents after the login button is hit.  That may help by giving you a better error message.

Good luck,
Steve

On Fri, Oct 12, 2012 at 10:06 AM, Fran García <[hidden email]> wrote:
So, you are not using Spring Security plugin? Because I think this is the
problem. I think it is something due to https requests but I am not quite
sure. I have another tests sending posts without problems but the login
process using Spring Security plugin is not posible.

Has anybody an idea of what is happening? I have been reading something
about mocking out authentication with SSP (
http://forum.springsource.org/showthread.php?108101-Mocking-out-authentication-for-functional-tests-when-using-Spring-Security
<http://forum.springsource.org/showthread.php?108101-Mocking-out-authentication-for-functional-tests-when-using-Spring-Security>
) but I don't know how to deal with that.



-----
What doesn't kill you, makes you stronger
--
View this message in context: http://grails.1312388.n4.nabble.com/Functional-testing-with-Spring-Security-plugin-in-a-Grails-app-tp4636273p4636473.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email






--
Jeri Levine
Senior Software Quality Engineer
Chemical Biology Informatics Platform
Broad Institute of Harvard & MIT
7 Cambridge Center
Cambridge, MA 02142
617-714-7385
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

bond_
In reply to this post by Fran García
I think your syntax is not correct IMHO

As per documentation http://www.gebish.org/manual/current/navigator.html#form_control_shortcuts

Even in our application I have not tried using

$('form').method() << 'value'

As per the syntax it should be:

$('form').propertyName << 'value'

where property name is:
<form>
<input name='propertyName' id='something' type='text'/>
</form>

Even if that works please do the following checks:
  • Does the user exist in database
  • For the environment in which you are running functional tests is the below config variable true:
    • grails.plugins.springsecurity.active = true
  • If there are two applications on the machine which runs these tests does the serverUrl point to the expected server
    • grails.serverURL = "<a href="http://localhost:8080/${appName}">http://localhost:8080/${appName}"

On Wed, Oct 10, 2012 at 7:25 PM, Fran García <[hidden email]> wrote:
I have a secured grails application with the spring security plugin and right
now I am trying to do some tests with the login process with no success till
now. Has anybody an idea of what is the problem?

This is my LoginPage.groovy

        package pages.login

        import geb.Page


        class LoginPage extends Page {
                static url = "login/auth"

                static at = {
                        title ==~ /Login/
                }

                static content = {
                        loginForm { $("form") }
                        username { $("input", type:"text", name:"j_username") }
                        password { $("input", type:"password", name:"j_password") }
                        loginButton{ $("input", type:"submit", value:"Login") }
                }
        }

And this is the test using junit4:

        import geb.junit4.GebReportingTest

        import pages.copyright.*
        import pages.login.LoginPage
        import org.junit.Test

        class CopyrightCRUDTests extends GebReportingTest {

                @Test
                void doSomeCrud() {

                        to LoginPage
                        at LoginPage
                        $("form").j_username() << "admin"
                        $("form").j_password() << "XXXXX"
                        loginButton.click()

                        to AuthenticatedPage
                        at AuthenticatedPage

                }
        }

The AuthenticatedPage is a page which needs authentication, but in this
moment it is imposible to be authenticated using geb. Does anybody know
anything about this issue?

Thanks in advance!



-----
What doesn't kill you, makes you stronger
--
View this message in context: http://grails.1312388.n4.nabble.com/Functional-testing-with-Spring-Security-plugin-in-a-Grails-app-tp4636273.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
Ravi Teja Lokineni | Software Engineer
SemanticBits India Pvt. Ltd.



Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Fran García
Hi,

thanks for your suggestions but I think I have tried all of them. In any case, I'm gonna check again everything. I just wanted to check that somebody has been able to do any functional test with geb in any application with the Spring Security plugin.

Regards

Fran García
What doesn't kill you, makes you stronger
Reply | Threaded
Open this post in threaded view
|

Re: Functional testing with Spring Security plugin in a Grails app

Fran García
There is nothing better that having a relaxed time to view things differently. It was a problem with the password but nothing to do with the spring security core and the geb functional tests. Thank you very much for your help!
What doesn't kill you, makes you stronger