libeufin

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

commit 2c20308c86309fccb3843d095c89320a6995e49e
parent d7878cb5d05c76959ca97f8fca79ea93afe0d02b
Author: MS <ms@taler.net>
Date:   Thu, 29 Oct 2020 22:27:55 +0100

checks (work in progress)

Diffstat:
Mintegration-tests/all.sh | 2+-
Mintegration-tests/json_checks.py | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Mintegration-tests/test-bankAccount.py | 2++
Mintegration-tests/test-bankConnection.py | 11++++++++++-
Mintegration-tests/test-ebics-highlevel.py | 4++--
Mintegration-tests/test-ebics.py | 13++++++++++---
Mintegration-tests/util.py | 2+-
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 2+-
8 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/integration-tests/all.sh b/integration-tests/all.sh @@ -6,7 +6,7 @@ set -e ./test-ebics-highlevel.py ./test-ebics.py ./test-sandbox.py -./test-taler-facade.py +./test-taler-facade.py ./test-bankConnection.py ./test-ebics-double-payment-submission.py echo "All tests passed." diff --git a/integration-tests/json_checks.py b/integration-tests/json_checks.py @@ -10,6 +10,15 @@ def checkNewUserRequest(json): c = T(F("username"), F("password")) return c.check(json) +def checkBankAccountElement(json): + c = T( + F("nexusBankAccountId"), + F("iban"), + F("bic"), + F("ownerName") + ) + return c.check(json) + def checkPreparePayment(json): c = T( F("iban"), @@ -20,10 +29,51 @@ def checkPreparePayment(json): ) return c.check(json) +def checkBankConnection(json): + c = T( + F("bankConnectionId"), + F("bankConnectionType"), + F("ready"), + F("bankKeysReviewed") + ) + return c.check(json) + +def checkDeleteConnection(json): + c = T(F("bankConnectionId")) + return c.check(json) + +def checkConnectionListElement(json): + c = T( + F("name"), + F("type") + ) + return c.check(json) + def checkPreparedPaymentResponse(json): c = T(F("uuid")) return c.check(json) +def checkPreparedPaymentElement(json): + c = T( + F("paymentInitiationId"), + F("submitted"), + F("creditorIban"), + F("creditorBic"), + F("creditorName"), + F("amount"), + F("subject"), + F("submissionDate"), + F("preparationDate") + ) + return c.check(json) + +def checkFetchTransactions(json): + c = T( + F("rangeType"), + F("level") + ) + return c.check(json) + def checkTransaction(json): c = T( F("account"), @@ -34,6 +84,7 @@ def checkTransaction(json): F("date"), F("subject") ) + return c.check(json) def checkNewEbicsConnection(json): c = T( diff --git a/integration-tests/test-bankAccount.py b/integration-tests/test-bankAccount.py @@ -7,6 +7,7 @@ import hashlib import base64 from util import startNexus, startSandbox, assertResponse +from json_checks import checkNewUserRequest, checkBankAccountElement # Nexus user details USERNAME = "person" @@ -153,6 +154,7 @@ listOfferedAccountsAfter = assertResponse( ) for el in listOfferedAccountsAfter.json().get("accounts"): + checkBankAccountElement(el) if el.get("nexusBankAccountId") == "savings-at-nexus": exit(0) print("Test passed!") diff --git a/integration-tests/test-bankConnection.py b/integration-tests/test-bankConnection.py @@ -7,6 +7,7 @@ import hashlib import base64 from util import startNexus, startSandbox, assertResponse +from json_checks import checkDeleteConnection, checkConnectionListElement, checkBankConnection # Nexus user details USERNAME = "person" @@ -119,7 +120,7 @@ assertResponse( assertResponse( post( "http://localhost:5001/bank-connections/delete-connection", - json=dict(bankConnectionId="my-ebics") + json=checkDeleteConnection(dict(bankConnectionId="my-ebics")) ) ) @@ -131,8 +132,16 @@ connectionsList = resp.json().get("bankConnections") assert(connectionsList != None) for el in connectionsList: + checkConnectionListElement(el) if el.get("name") == "my-ebics": print("fail: account not deleted!") exit(1) +resp = assertResponse( + get("http://localhost:5001/bank-connections/my-ebics-new", + headers=dict(Authorization=USER_AUTHORIZATION_HEADER) + ) +) +checkBankConnection(resp.json()) + print("Test passed!") diff --git a/integration-tests/test-ebics-highlevel.py b/integration-tests/test-ebics-highlevel.py @@ -181,7 +181,7 @@ resp = assertResponse( headers=dict(Authorization=USER_AUTHORIZATION_HEADER), ) ) -checkPreparedPaymentResponse(resp) +checkPreparedPaymentResponse(resp.json()) PREPARED_PAYMENT_UUID = resp.json().get("uuid") # 5.b, submit payment initiation @@ -213,6 +213,6 @@ if len(transactions) != 1: print(transactions) fail(f"Unexpected number of transactions ({len(transactions)}); should be 1") -checkTransactions(transactions[0]) +checkTransaction(transactions[0]) print("Test passed!") diff --git a/integration-tests/test-ebics.py b/integration-tests/test-ebics.py @@ -3,13 +3,13 @@ from requests import post, get from subprocess import call, Popen, PIPE from time import sleep +from util import startNexus, startSandbox, assertResponse +from json_checks import checkFetchTransactions, checkPreparedPaymentElement import os import socket import hashlib import base64 -from util import startNexus, startSandbox, assertResponse - # Steps implemented in this test. # # 0 Prepare sandbox. @@ -212,6 +212,13 @@ PREPARED_PAYMENT_UUID = resp.json().get("uuid") if PREPARED_PAYMENT_UUID == None: fail("Payment UUID not received") +resp = assertResponse( + get(f"http://localhost:5001/bank-accounts/{BANK_ACCOUNT_LABEL}/payment-initiations/{PREPARED_PAYMENT_UUID}", + headers=dict(Authorization=USER_AUTHORIZATION_HEADER) + ) +) +checkPreparedPaymentElement(resp.json()) + # 5.b, submit prepared statement assertResponse( post( @@ -225,7 +232,7 @@ assertResponse( assertResponse( post( f"http://localhost:5001/bank-accounts/{BANK_ACCOUNT_LABEL}/fetch-transactions", - json=dict(level="all", rangeType="all"), + json=checkFetchTransactions(dict(level="all", rangeType="all")), headers=dict(Authorization=USER_AUTHORIZATION_HEADER), ) ) diff --git a/integration-tests/util.py b/integration-tests/util.py @@ -16,7 +16,7 @@ class CheckJsonField: def check(self, json): if self.name not in json and not self.optional: - print(f"'{self.name}' not found in the JSON.") + print(f"'{self.name}' not found in the JSON: {json}.") sys.exit(1) if self.nested: self.nested.check(json.get(self.name)) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -119,7 +119,7 @@ fun extractUserAndPassword(authorizationHeader: String): Pair<String, String> { fun authenticateRequest(request: ApplicationRequest): NexusUserEntity { val authorization = request.headers["Authorization"] val headerLine = if (authorization == null) throw NexusError( - HttpStatusCode.BadRequest, "Authentication:-header line not found" + HttpStatusCode.BadRequest, "Authorization header not found" ) else authorization val (username, password) = extractUserAndPassword(headerLine) val user = NexusUserEntity.find {