libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 0661cf1597f110b782154de202ce06d24f7e8946
parent 545ebacc71734b3b6f9a491f7cddf1450fbda5fd
Author: Marcello Stanisci <ms@taler.net>
Date:   Tue, 12 May 2020 19:48:49 +0200

integration test

Up to the point where a new Ebics transport
is being created, but parsing the request body fails.

Diffstat:
Mintegration-tests/test-ebics-new.py | 39++++++++++++++++++++++++---------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt | 9++++-----
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 30++++++++++++++++--------------
3 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/integration-tests/test-ebics-new.py b/integration-tests/test-ebics-new.py @@ -92,9 +92,10 @@ for i in range(10): if i == 9: nexus.terminate() stdout, stderr = nexus.communicate() + print("Nexus timed out") print("{}\n{}".format(stdout.decode(), stderr.decode())) exit(77) - sleep(1) + sleep(2) continue break # Start sandbox @@ -108,9 +109,10 @@ for i in range(10): nexus.terminate() sandbox.terminate() stdout, stderr = nexus.communicate() + print("Sandbox timed out") print("{}\n{}".format(stdout.decode(), stderr.decode())) exit(77) - sleep(1) + sleep(2) continue break @@ -169,7 +171,7 @@ dbconn.close() assertResponse( post( "http://localhost:5001/users", - headers=dict(authorization=ADMIN_AUTHORIZATION_HEADER), + headers=dict(Authorization=ADMIN_AUTHORIZATION_HEADER), json=dict( username=USERNAME, password=PASSWORD @@ -177,23 +179,30 @@ assertResponse( ) ) -nexus.terminate() -sandbox.terminate() -print("All done!") -exit(44) - -#1.b +#1.b, make a ebics transport for the new user. assertResponse( post( - "http://localhost:5001/ebics/subscribers/{}".format(USERNAME), + "http://localhost:5001/bank-transports", json=dict( - ebicsURL=EBICS_URL, - hostID=HOST_ID, - partnerID=PARTNER_ID, - userID=USER_ID - ) + transport=dict( + name="my-ebics", + type="ebics" + ), + data=dict( + ebicsURL=EBICS_URL, + hostID=HOST_ID, + partnerID=PARTNER_ID, + userID=USER_ID + ) + ), + headers=dict(Authorization=USER_AUTHORIZATION_HEADER) ) ) + +nexus.terminate() +sandbox.terminate() +exit(44) + #2.a assertResponse( post( diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt @@ -80,10 +80,9 @@ data class RawPayments( * API types (used as requests/responses types) * *************************************************/ data class BankTransport( - val name: String, - val backup: Any, // only EbicsKeysBackupJson exists now. - val new: Any, - val type: String + val transport: tech.libeufin.nexus.Transport, + val backup: Any?, + val data: Any? ) /** @@ -107,7 +106,7 @@ data class EbicsNewTransport( val partnerID: String, val hostID: String, val ebicsURL: String, - val systemID: String + val systemID: String? ) /** Response type of "GET /prepared-payments/{uuid}" */ diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -405,8 +405,10 @@ fun main() { val userId = authenticateRequest(call.request.headers["Authorization"]) // user exists and is authenticated. val body = call.receive<BankTransport>() + logger.debug("Request body parsed") when (body.backup) { is EbicsKeysBackupJson -> { + logger.debug("Restoring a transport: ${body.transport.name}") val (authKey, encKey, sigKey) = try { Triple( CryptoUtil.decryptKey( @@ -433,7 +435,7 @@ fun main() { logger.info("Restoring keys, creating new user: $userId") try { transaction { - EbicsSubscriberEntity.new(userId) { + EbicsSubscriberEntity.new(body.transport.name) { this.nexusUser = extractNexusUser(userId) ebicsURL = body.backup.ebicsURL hostID = body.backup.hostID @@ -451,34 +453,34 @@ fun main() { ) return@post } + call.respondText("Backup restored") + return@post } } - when (body.new) { + when (body.data) { is EbicsNewTransport -> { + logger.debug("Creating new transport: ${body.transport.name}") val pairA = CryptoUtil.generateRsaKeyPair(2048) val pairB = CryptoUtil.generateRsaKeyPair(2048) val pairC = CryptoUtil.generateRsaKeyPair(2048) transaction { - EbicsSubscriberEntity.new { + EbicsSubscriberEntity.new(body.transport.name) { nexusUser = extractNexusUser(userId) - ebicsURL = body.new.ebicsURL - hostID = body.new.hostID - partnerID = body.new.partnerID - userID = body.new.userID - systemID = body.new.systemID + ebicsURL = body.data.ebicsURL + hostID = body.data.hostID + partnerID = body.data.partnerID + userID = body.data.userID + systemID = body.data.systemID signaturePrivateKey = SerialBlob(pairA.private.encoded) encryptionPrivateKey = SerialBlob(pairB.private.encoded) authenticationPrivateKey = SerialBlob(pairC.private.encoded) } } - call.respondText( - "EBICS user successfully created", - ContentType.Text.Plain, - HttpStatusCode.OK - ) + call.respondText("EBICS user successfully created") return@post } - } + } // end of second 'when'. + call.respond( HttpStatusCode.BadRequest, "Neither backup nor new transport given in request"