In my akka-http application I am returning a response from another security service that responds with a WWW-Authenticate
header: When akka-http parses this header and then renders the WWW-Authenticate
value to a string the quotes on one of the parameters are missing. Am I missing something in the rendering or could this be an akka-http bug?
Here's a test case:
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.HttpHeader.ParsingResult
import akka.http.scaladsl.model.headers.{`WWW-Authenticate`, HttpChallenge}
import org.scalatest.{Matchers, WordSpec}
class wwwAuthenticateParserTest extends WordSpec with Matchers {
"WWW-Authenticate header" should {
"have correctly-quoted strings" in {
val rawHeader = HttpHeader.parse("WWW-Authenticate",
"Bearer error=\"invalid_request\", error_description=\"Access token is not found\"")
val expectedHeader = `WWW-Authenticate`(HttpChallenge("Bearer",
"",
Map("error" -> "invalid_request", "error_description" -> "Access token is not found")))
rawHeader match {
case ParsingResult.Ok(`WWW-Authenticate`(challenges), _) =>
challenges.head should be(expectedHeader.challenges.head)
challenges.head.params("error") should be("invalid_request")
challenges.head.toString should be("Bearer realm=\"\",error=\"invalid_request\",error_description=\"Access token is not found\"")
case _ => ???
}
}
The third assertion fails, with the quotation marks around invalid_request
missing. The quotation marks are also missing from the header on the response the akka-http app sends.