我从这里遵循喷雾手册。所以我收集了非常简单的测试
class AtoImportServiceApiTest extends WordSpecLike with MustMatchers with ScalatestRouteTest {
"AtoImportService" must {
"return HTTP status 401 Unauhorized when accessing withou basic auth" in {
Post("/ato/v1/orders/updateStatus") ~>new AtoImportServiceApi().route ~> check {
handled must be(false)
rejections must have size 1
status === StatusCodes.Unauthorized
}
}
}
}
我正在调用包含授权指令的路线。所以我希望拒绝将转换为 HTTP 状态代码。但这并没有发生在这里,测试失败了。
Request was rejected with List(AuthenticationFailedRejection(CredentialsMissing,List(WWW-Authenticate: Basic realm="bd ato import api")))
ScalaTestFailureLocation: spray.testkit.RouteTest$class at (RouteTest.scala:74)
org.scalatest.exceptions.TestFailedException: Request was rejected with List(AuthenticationFailedRejection(CredentialsMissing,List(WWW-Authenticate: Basic realm="bd ato import api")))
at spray.testkit.ScalatestInterface$class.failTest(ScalatestInterface.scala:25)
我在这里错过了一些重要的概念吗?