Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Secure module: how do you "log in" in a FunctionalTest?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Schaake  
View profile  
 More options Apr 24 2011, 10:04 am
From: Mark Schaake <mark.scha...@gmail.com>
Date: Sun, 24 Apr 2011 07:04:36 -0700 (PDT)
Local: Sun, Apr 24 2011 10:04 am
Subject: Re: Secure module: how do you "log in" in a FunctionalTest?
I've found a workaround to this issue. To preserve the cookies from a
previous request in a FunctionalTest, you have to manually build the
request. There is a helper method in FunctionTest to get you started:

    // Make the login request
    Map<String, String> loginUserParams = new HashMap<String,
String>();
    loginUserParams.put("username", "admin");
    loginUserParams.put("password", "admin");
    Response loginResponse = POST("/login", loginUserParams);

    Request request = newRequest(); // helper method from
FunctionalTest superclass
    request.cookies = loginResponse.cookies; // this makes the request
authenticated for secure module
    request.url = "/some/secured/action";
    request.method = "POST";
    request.params.put("someparam", "somevalue");
    Response response = makeRequest(request);
    assertIsOk(response); // Passes!

On Apr 23, 1:50 pm, Mark Schaake <mark.scha...@gmail.com> wrote:

> Yes, I know about the org.junit.Before annotation. This doesn't work
> in that cookies from previous call are not being placed in subsequent
> calls (even though looking at FunctionalTest this is what is supposed
> to happen). Looks like bughttps://bugs.launchpad.net/play/+bug/497408
> as pointed out by Havoc P on stackoverflow.comhttp://stackoverflow.com/questions/5762246/playframework-secure-modul...

> On Apr 22, 10:22 pm, Sam Liu <worldwin...@gmail.com> wrote:

> > There is an annotation like @Before. You can try it...

> > @Before
> > public static void loginFirst(){
> > ...

> > }

> > public static void testYourAction(){
> > ...

> > }

> > 2011/4/23 Mark Schaake <mark.scha...@gmail.com>

> > > I want to test controller actions that are secured by Secure module
> > > class, so I need to log in prior to testing my controller.

> > > How do you do this? I've tried the following:

> > > ========== code snipet ===================
> > > Map<String, String> loginUserParams = new HashMap<String, String>();
> > > loginUserParams.put("username", "admin");
> > > loginUserParams.put("password", "admin");
> > > Response response = POST("/login", loginUserParams);
> > > ========== end code snipet ===================

> > > Which returns the expected response (redirect to home page). But then
> > > in subsequent call to a secured action, I am always redirected to the
> > > "/login" page. Is there a way to "fool" the Secure module into
> > > believing you're authenticated?

> > > I absolutely do not want to have to write a Selenium test for every
> > > secured action - since almost all will be secured.

> > > Thanks in advance,

> > > Mark

> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "play-framework" group.
> > > To post to this group, send email to play-framework@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > play-framework+unsubscribe@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/play-framework?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.