Testing scala Play (2.2.1) controllers with CSRF protection

前端 未结 6 984
清歌不尽
清歌不尽 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:55

    For those who might be interested, I created a trait for play 2.5.x : https://stackoverflow.com/a/40259536/3894835

    You can then use it in your tests requests like the addToken{} of the controller :

    val fakeRequest = addToken(FakeRequest(/* params */))
    

提交回复
热议问题