akka/akka-http
Incorrect behaviour for header parsing with akka-http-testkit
オープン
#2,132 opened on 2018/07/31
1 - triagedhelp wantedt:coret:modelt:testing
Repository metrics
- Stars
- (1,311 個のスター)
- PR merge metrics
- (平均マージ 1d 10h) (30d で 2 merged PRs)
説明
It seems that header parsing with akka-http-testkit is behaving differently than a real akka HTTP server. I am not sure it is a bug but the behaviour is unexpected. Here is my failing test:
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest._
class Test extends FlatSpec with Matchers with ScalatestRouteTest {
val route =
extractCredentials { creds =>
complete {
creds match {
case Some(c) => "Found: " + c
case _ => "No credentials"
}
}
}
it should "verify headers" in {
RawHeader("Authorization", """Basic dXNlcjpwd2Q=""").toString() shouldBe "Authorization: Basic dXNlcjpwd2Q="
Authorization(BasicHttpCredentials("user", "pwd")).toString() shouldBe "Authorization: Basic dXNlcjpwd2Q="
}
it should "test 1" in {
Get("/") ~> addHeader(RawHeader("Authorization", """Basic dXNlcjpwd2Q=""")) ~>
route ~> check {
responseAs[String] shouldEqual """Found: Basic dXNlcjpwd2Q="""
}
}
it should "test 2" in {
Get("/") ~> addHeader(Authorization(BasicHttpCredentials("user", "pwd"))) ~>
route ~> check {
responseAs[String] shouldEqual """Found: Basic dXNlcjpwd2Q="""
}
}
}
From my understanding, the test test 1 should not fail. If we launch a real server and perform curl -H 'Authorization: Basic dXNlcjpwd2Q=' localhost:8080 then we get the expected result.