認証を行い、特定のトークンをセッションに保存するためのscalaメソッドを次のように作成しました。
def logIn = Action(parse.json) { request =>
request.body.validate.map { entity =>
Authentication.authenticate(entity.username, entity.password) match {
case "" => NotFound(RestResponses.toJson(RestResponse(NOT_FOUND, "Invalid username or password.")))
case token: String => Ok(RestResponses.toJson(RestResponse(OK, "Username %s has been succesfully logged in".format(entity.username)))).withSession(TokenKey -> token)
}
}
.recover { Result =>
BadRequest(RestResponses.toJson(RestResponse(BAD_REQUEST, "Unable to parse content type for user authentication.")))
}
}
メソッドをテストするためlogIn
に、テストメソッドを作成しました:
"A POST request to login a user" should "return OK " in {
running(FakeApplication()) {
val node = Json.toJson(AuthenticationUser("cristi", "cristi-password"))(controllers.AuthenticationService.authUserWrites);
val result = AuthenticationService.logIn(new FakeRequest(Helpers.POST, "/", FakeHeaders(), node))
status(result) should equal(OK)
contentType(result) should be(Some("application/json"))
contentAsString(result) should include("succesfully logged in")
}
}
このエラーが表示される理由がわかりません。
[info] - should return OK *** FAILED ***
[info] play.api.PlayException: Configuration error[Missing application.secret]
[info] at play.api.libs.Crypto$$anonfun$sign$2.apply(Crypto.scala:30)
[info] at play.api.libs.Crypto$$anonfun$sign$2.apply(Crypto.scala:30)
それはセッションに関するものだと確信しています...しかし、何ですか?