Skip to content

Commit

Permalink
Merge pull request #95 from gagarin55/devel
Browse files Browse the repository at this point in the history
/addresses/seed/{address} api method protection by api_key
  • Loading branch information
catena2w committed Jun 3, 2016
2 parents ace6cde + 45c6b61 commit 876bb5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ case class AddressApiRoute(override val application: Application)(implicit val c
))
def seed: Route = {
path("seed" / Segment) { case address =>
getJsonRoute {
//TODO CHECK IF WALLET EXISTS
withPrivateKeyAccount(wallet, address) { account =>
wallet.exportAccountSeed(account.address) match {
case None => WalletSeedExportFailed.json
case Some(seed) => Json.obj("address" -> address, "seed" -> Base58.encode(seed))
withAuth {
getJsonRoute {
//TODO CHECK IF WALLET EXISTS
withPrivateKeyAccount(wallet, address) { account =>
wallet.exportAccountSeed(account.address) match {
case None => WalletSeedExportFailed.json
case Some(seed) => Json.obj("address" -> address, "seed" -> Base58.encode(seed))
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/scorex/lagonaki/TestingCommons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object TestingCommons {
body: String = "",
headers: Map[String, String] = Map.empty,
peer: String = peerUrl(application)): JsValue = {
val request = Http(url(peer + us).GET)
val request = Http(url(peer + us).GET <:< headers)
val response = Await.result(request, 5.seconds)
Json.parse(response.getResponseBody)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class AddressesAPISpecification extends FunSuite with Matchers {
}

test("/addresses/seed/{address} API route") {
val response = GET.request(s"/addresses/seed/${account.address}")
val path = s"/addresses/seed/${account.address}"
GET.incorrectApiKeyTest(path)

val response = GET.request(us = path, headers = Map("api_key" -> "test"))
(response \ "address").as[String] shouldBe account.address
(response \ "seed").as[String] shouldBe Base58.encode(account.seed)
}
Expand Down

0 comments on commit 876bb5d

Please sign in to comment.