I am working on the the securing the http routes created with akka-http 
using the authentication token, which is passed as header and on 
authenticated the route is rejected or accepted .

val routes: Route = corsHandler(route)

  lazy val route: Route =
    pathPrefix(HttpConstants.PathPerfix / HttpConstants.Version) {
      optionalHeaderValueByName("token") {
        case Some(userId) =>
          authAPI.authenticate(userId) {
            case Some("Authenticated") =>
              JobRouter.route ~
                AuthRouter.route
            case Some("Rejected") =>
              complete(StatusCodes.custom(401, "Wrong Password Provided"))
          }
        case None => complete(StatusCodes.custom(403, "token header not 
provided"))
      }
    }

Now the above code works fine the problem arises when I am trying to write 
the test cases for the same

"Create user Api" should {
    "Posting to /user should create template" in {
      val entity = HttpEntity(MediaTypes.`application/json`, json.toString())
      Post(Paths.get("/", HttpConstants.CreateUser).toString, entity) ~>
      RawHeader("token","aDmineyJ0eXAiOiJKV1QiLCJhbG") ~>
        httpService.JobRouter.route ~> check {
          status.isSuccess() shouldEqual true
      }
    }
  }

Now while I pass the token as header all I get is Error during processing 
of request: 'null'. Completing with 500 Internal Server Error response. I 
even tried using addHeader option of akka but still the issue remains.

Reference : 
https://doc.akka.io/docs/akka-http/10.0.0/scala/http/routing-dsl/directives/header-directives/optionalHeaderValueByName.html

-- 

*DISCLAIMER:*
All the content in email is intended for the recipient and not to be 
published elsewhere without Exadatum consent. And attachments shall be send 
only if required and with ownership of the sender. This message contains 
confidential information and is intended only for the individual named. If 
you are not the named addressee, you should not disseminate, distribute or 
copy this email. Please notify the sender immediately by email if you have 
received this email by mistake and delete this email from your system. 
Email transmission cannot be guaranteed to be secure or error-free, as 
information could be intercepted, corrupted, lost, destroyed, arrive late 
or incomplete, or contain viruses. The sender, therefore, does not accept 
liability for any errors or omissions in the contents of this message which 
arise as a result of email transmission. If verification is required, 
please request a hard-copy version.

-- 
*****************************************************************************************************
** New discussion forum: https://discuss.akka.io/ replacing akka-user 
google-group soon.
** This group will soon be put into read-only mode, and replaced by 
discuss.akka.io
** More details: https://akka.io/blog/news/2018/03/13/discuss.akka.io-announced
*****************************************************************************************************
>>>>>>>>>> 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to