Testing scala Play (2.2.1) controllers with CSRF protection

前端 未结 6 928
清歌不尽
清歌不尽 2021-01-13 17:21

I\'ve been having some problems testing controllers that use Play\'s CSRF protection. To demonstrate this, I\'ve created a very simple Play application that minimally exhibi

6条回答
  •  北海茫月
    2021-01-13 17:42

    Bonus answer for those interested in Java: I got this to work in the Java version of Play Framework 2.2 by adding

    .withSession(CSRF.TokenName(), CSRFFilter.apply$default$5().generateToken())
    

    to fakeRequest()

提交回复
热议问题