I have a controller that is protected by an Authentication trait. The trait looks like this:
def isAuthenticated(f: => AccountDTO => Request[AnyContent] => Result) =
Security.Authenticated(username, onUnauthorized) { user =>
Action.async {
request => {
Future.successful(f(user)(request))
}
}
}
Everything works well when doing a normal request, but when doing unit tests I encounter problems. I create the following fake request:
val goodRequest = FakeRequest("POST", "/platform/api/v1/files")
.withBody(Json.toJson(ScalaMockingUtil.fileValidMetadataJson))
.withHeaders((HeaderNames.AUTHORIZATION, "4322tertf2643t34t34"))
Next, I get my controller object and call the method by applying that FakeRequest:
val result: Iteratee[Array[Byte], Result] = filesController.createFileMetadata()(goodRequest)
The problem that I am facing is that somewhere along the line the FakeReuqest gets down-casted to RequestHeader. The problem seems to be the one described here: Unable to test controller using Action.async where the Action has two apply methods instead of one. however, I can't seem to be able to force the one that I need.
Any help is appreciated.