akka/akka-http
View on GitHubIncorrect behaviour for header parsing with akka-http-testkit
Open
#2,132 opened on Jul 31, 2018
1 - triagedhelp wantedt:coret:modelt:testing
Repository metrics
- Stars
- (1,311 stars)
- PR merge metrics
- (Avg merge 1d 10h) (2 merged PRs in 30d)
Description
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.