Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/savage.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala')
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala b/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala
index 87ed804..163c3e2 100644
--- a/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala
@@ -1,6 +1,7 @@
package com.getbootstrap.savage.server
import scala.util.Try
+import akka.event.LoggingAdapter
import spray.http.FormData
import spray.routing.{Directive1, MalformedHeaderRejection, MalformedRequestContentRejection, ValidationRejection}
import spray.routing.directives.{BasicDirectives, HeaderDirectives, RouteDirectives, MarshallingDirectives}
@@ -16,26 +17,33 @@ trait TravisAuthDirectives {
private val authorization = "Authorization"
private val authorizationHeaderValue = headerValueByName(authorization)
- val travisAuthorization: Directive1[Array[Byte]] = authorizationHeaderValue.flatMap { hex =>
+ def travisAuthorization(log: LoggingAdapter): Directive1[Array[Byte]] = authorizationHeaderValue.flatMap { hex =>
Try{ javax.xml.bind.DatatypeConverter.parseHexBinary(hex) }.toOption match {
case Some(bytesFromHex) => provide(bytesFromHex)
- case None => reject(MalformedHeaderRejection(authorization, "Malformed SHA-256 hex digest"))
+ case None => {
+ log.error(s"Received Travis request with malformed hex digest in ${authorization} header!")
+ reject(MalformedHeaderRejection(authorization, "Malformed SHA-256 hex digest"))
+ }
}
}
private val formDataEntity = entity(as[FormData])
- def stringEntityIfTravisAuthValid(travisToken: String, repo: RepositoryId): Directive1[String] = travisAuthorization.flatMap { hash =>
+ def stringEntityIfTravisAuthValid(travisToken: String, repo: RepositoryId, log: LoggingAdapter): Directive1[String] = travisAuthorization(log).flatMap { hash =>
formDataEntity.flatMap { formData =>
val plainText = repo.generateId + travisToken
val auth = new Sha256(hash = hash, plainText = plainText.utf8Bytes)
if (auth.isValid) {
formData.fields.toMap.get("payload") match {
case Some(string) => provide(string)
- case None => reject(MalformedRequestContentRejection("Request body form data lacked required `payload` field"))
+ case None => {
+ log.error("Received Travis request that was missing the `payload` field!")
+ reject(MalformedRequestContentRejection("Request body form data lacked required `payload` field"))
+ }
}
}
else {
+ log.error("Received Travis request with incorrect hash!")
reject(ValidationRejection("Incorrect SHA-256 hash"))
}
}