Playframework Secure module: how do you “log in” to test a secured controller in a FunctionalTest?

前端 未结 4 840
鱼传尺愫
鱼传尺愫 2020-12-08 08:46

EDIT: I\'m using Play! version 1.2 (production release)

I want to test controller actions that are secured by Secure module class, so I need to log

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 09:02

    Maybe you are seeing https://bugs.launchpad.net/play/+bug/497408

    I think it is supposed to work.

    Update: I did some debugging. I think there are two bugs.

    1. In FunctionalTest, cookies are just discarded if they have no maxAge.
    2. In Scope.java, in Session, the "TS" field is only set if the cookie previously existed. Therefore, the first time the session cookie is set, it gets ignored when it's sent back to the server. If you make 3 requests, it seems to work OK between requests 2 and 3, but not between requests 1 and 2, because on request 2 the cookie sent doesn't have a timestamp.

    So bug 1 breaks it if you don't set maxAge, and bug 2 breaks it if you do set maxAge.

    Update 2: I made some patches that fix it for me: http://play.lighthouseapp.com/projects/57987-play-framework/tickets/775

提交回复
热议问题