summaryrefslogtreecommitdiff
path: root/nexus/src/test/kotlin/WireGatewayApiTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'nexus/src/test/kotlin/WireGatewayApiTest.kt')
-rw-r--r--nexus/src/test/kotlin/WireGatewayApiTest.kt166
1 files changed, 79 insertions, 87 deletions
diff --git a/nexus/src/test/kotlin/WireGatewayApiTest.kt b/nexus/src/test/kotlin/WireGatewayApiTest.kt
index a8d94b2f..d7b11536 100644
--- a/nexus/src/test/kotlin/WireGatewayApiTest.kt
+++ b/nexus/src/test/kotlin/WireGatewayApiTest.kt
@@ -24,47 +24,42 @@ import io.ktor.http.*
import io.ktor.server.testing.*
import org.junit.Test
import tech.libeufin.common.*
+import tech.libeufin.nexus.*
class WireGatewayApiTest {
- // GET /accounts/{USERNAME}/taler-wire-gateway/config
+ // GET /taler-wire-gateway/config
@Test
fun config() = serverSetup { _ ->
- //authRoutine(HttpMethod.Get, "/accounts/merchant/taler-wire-gateway/config")
+ authRoutine(HttpMethod.Get, "/taler-wire-gateway/config")
- client.get("/taler-wire-gateway/config").assertOk()
+ client.getA("/taler-wire-gateway/config").assertOk()
}
- // Testing the POST /transfer call from the TWG API.
- /*@Test
- fun transfer() = bankSetup { _ ->
+ // POST /taler-wire-gateway/transfer
+ @Test
+ fun transfer() = serverSetup { _ ->
val valid_req = obj {
"request_uid" to HashCode.rand()
- "amount" to "KUDOS:55"
+ "amount" to "CHF:55"
"exchange_base_url" to "http://exchange.example.com/"
"wtid" to ShortHashCode.rand()
- "credit_account" to merchantPayto.canonical
+ "credit_account" to grothoffPayto
}
- authRoutine(HttpMethod.Post, "/accounts/merchant/taler-wire-gateway/transfer", valid_req)
-
- // Checking exchange debt constraint.
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
- json(valid_req)
- }.assertConflict(TalerErrorCode.BANK_UNALLOWED_DEBIT)
+ authRoutine(HttpMethod.Post, "/taler-wire-gateway/transfer")
- // Giving debt allowance and checking the OK case.
- setMaxDebt("exchange", "KUDOS:1000")
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ // Check OK
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req)
}.assertOk()
// check idempotency
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req)
}.assertOk()
// Trigger conflict due to reused request_uid
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req) {
"wtid" to ShortHashCode.rand()
"exchange_base_url" to "http://different-exchange.example.com/"
@@ -72,132 +67,117 @@ class WireGatewayApiTest {
}.assertConflict(TalerErrorCode.BANK_TRANSFER_REQUEST_UID_REUSED)
// Currency mismatch
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req) {
"amount" to "EUR:33"
}
}.assertBadRequest(TalerErrorCode.GENERIC_CURRENCY_MISMATCH)
- // Unknown account
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
- json(valid_req) {
- "request_uid" to HashCode.rand()
- "wtid" to ShortHashCode.rand()
- "credit_account" to unknownPayto
- }
- }.assertConflict(TalerErrorCode.BANK_UNKNOWN_CREDITOR)
-
- // Same account
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
- json(valid_req) {
- "request_uid" to HashCode.rand()
- "wtid" to ShortHashCode.rand()
- "credit_account" to exchangePayto
- }
- }.assertConflict(TalerErrorCode.BANK_ACCOUNT_IS_EXCHANGE)
-
// Bad BASE32 wtid
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req) {
"wtid" to "I love chocolate"
}
}.assertBadRequest()
// Bad BASE32 len wtid
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req) {
- "wtid" to randBase32Crockford(31)
+ "wtid" to Base32Crockford.encode(ByteArray(31).rand())
}
}.assertBadRequest()
// Bad BASE32 request_uid
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req) {
"request_uid" to "I love chocolate"
}
}.assertBadRequest()
// Bad BASE32 len wtid
- client.postA("/accounts/exchange/taler-wire-gateway/transfer") {
+ client.postA("/taler-wire-gateway/transfer") {
+ json(valid_req) {
+ "request_uid" to Base32Crockford.encode(ByteArray(65).rand())
+ }
+ }.assertBadRequest()
+
+ // Bad payto kind
+ client.postA("/taler-wire-gateway/transfer") {
json(valid_req) {
- "request_uid" to randBase32Crockford(65)
+ "credit_account" to "payto://x-taler-bank/bank.hostname.test/bar"
}
}.assertBadRequest()
- }*/
- /*
- /**
- * Testing the /history/incoming call from the TWG API.
- */
+ }
+
+ // GET /taler-wire-gateway/history/incoming
@Test
- fun historyIncoming() = serverSetup {
- // Give Foo reasonable debt allowance:
- setMaxDebt("merchant", "KUDOS:1000")
- authRoutine(HttpMethod.Get, "/accounts/merchant/taler-wire-gateway/history/incoming")
+ fun historyIncoming() = serverSetup { db ->
+ authRoutine(HttpMethod.Get, "/taler-wire-gateway/history/incoming")
historyRoutine<IncomingHistory>(
- url = "/accounts/exchange/taler-wire-gateway/history/incoming",
+ url = "/taler-wire-gateway/history/incoming",
ids = { it.incoming_transactions.map { it.row_id } },
registered = listOf(
{
- // Transactions using clean add incoming logic
- addIncoming("KUDOS:10")
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
+ json {
+ "amount" to "CHF:12"
+ "reserve_pub" to EddsaPublicKey.rand()
+ "debit_account" to grothoffPayto
+ }
+ }.assertOk()
},
{
// Transactions using raw bank transaction logic
- tx("merchant", "KUDOS:10", "exchange", "history test with ${ShortHashCode.rand()} reserve pub")
- },
- {
- // Transaction using withdraw logic
- withdrawal("KUDOS:9")
+ talerableIn(db)
}
),
ignored = listOf(
{
// Ignore malformed incoming transaction
- tx("merchant", "KUDOS:10", "exchange", "ignored")
+ ingestIn(db)
},
{
- // Ignore malformed outgoing transaction
- tx("exchange", "KUDOS:10", "merchant", "ignored")
+ // Ignore outgoing transaction
+ talerableOut(db)
}
)
)
}
-
- /**
- * Testing the /history/outgoing call from the TWG API.
- */
+ // GET /taler-wire-gateway/history/outgoing
@Test
- fun historyOutgoing() = serverSetup {
- setMaxDebt("exchange", "KUDOS:1000000")
- authRoutine(HttpMethod.Get, "/accounts/merchant/taler-wire-gateway/history/outgoing")
+ fun historyOutgoing() = serverSetup { db ->
+ authRoutine(HttpMethod.Get, "/taler-wire-gateway/history/outgoing")
historyRoutine<OutgoingHistory>(
- url = "/accounts/exchange/taler-wire-gateway/history/outgoing",
+ url = "/taler-wire-gateway/history/outgoing",
ids = { it.outgoing_transactions.map { it.row_id } },
registered = listOf(
- {
- // Transactions using clean add incoming logic
- transfer("KUDOS:10")
+ {
+ talerableOut(db)
}
),
ignored = listOf(
{
- // gnore manual incoming transaction
- tx("exchange", "KUDOS:10", "merchant", "${ShortHashCode.rand()} http://exchange.example.com/")
+ // Ignore pending transfers
+ transfer()
+ },
+ {
+ // Ignore manual incoming transaction
+ talerableIn(db)
},
{
// Ignore malformed incoming transaction
- tx("merchant", "KUDOS:10", "exchange", "ignored")
+ ingestIn(db)
},
{
// Ignore malformed outgoing transaction
- tx("exchange", "KUDOS:10", "merchant", "ignored")
+ ingestOutgoingPayment(db, genOutPay("ignored"))
}
)
)
- }*/
+ }
- // Testing the /admin/add-incoming call from the TWG API.
+ // POST /taler-wire-gateway/admin/add-incoming
@Test
fun addIncoming() = serverSetup { _ ->
val valid_req = obj {
@@ -206,35 +186,47 @@ class WireGatewayApiTest {
"debit_account" to grothoffPayto
}
- //authRoutine(HttpMethod.Post, "/accounts/merchant/taler-wire-gateway/admin/add-incoming", valid_req, requireAdmin = true)
+ authRoutine(HttpMethod.Post, "/taler-wire-gateway/admin/add-incoming")
// Check OK
- client.post("/taler-wire-gateway/admin/add-incoming") {
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
json(valid_req)
}.assertOk()
// Trigger conflict due to reused reserve_pub
- client.post("/taler-wire-gateway/admin/add-incoming") {
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
json(valid_req)
}.assertConflict(TalerErrorCode.BANK_DUPLICATE_RESERVE_PUB_SUBJECT)
// Currency mismatch
- client.post("/taler-wire-gateway/admin/add-incoming") {
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
json(valid_req) { "amount" to "EUR:33" }
}.assertBadRequest(TalerErrorCode.GENERIC_CURRENCY_MISMATCH)
// Bad BASE32 reserve_pub
- client.post("/taler-wire-gateway/admin/add-incoming") {
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
json(valid_req) {
"reserve_pub" to "I love chocolate"
}
}.assertBadRequest()
// Bad BASE32 len reserve_pub
- client.post("/taler-wire-gateway/admin/add-incoming") {
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
json(valid_req) {
"reserve_pub" to Base32Crockford.encode(ByteArray(31).rand())
}
}.assertBadRequest()
+
+ // Bad payto kind
+ client.postA("/taler-wire-gateway/admin/add-incoming") {
+ json(valid_req) {
+ "debit_account" to "payto://x-taler-bank/bank.hostname.test/bar"
+ }
+ }.assertBadRequest()
+ }
+
+ @Test
+ fun noApi() = serverSetup("mini.conf") { _ ->
+ client.get("/taler-wire-gateway/config").assertNotImplemented()
}
} \ No newline at end of file