gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Loopback (minimal) test.


From: gnunet
Subject: [libeufin] branch master updated: Loopback (minimal) test.
Date: Mon, 01 Jun 2020 15:35:32 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 7b0b802  Loopback (minimal) test.
7b0b802 is described below

commit 7b0b802861fcf5a7e75e61237ee4c82e0cd6079e
Author: MS <ms@taler.net>
AuthorDate: Mon Jun 1 15:35:00 2020 +0200

    Loopback (minimal) test.
---
 integration-tests/test-loopback-highlevel.py      | 120 ++++++++++++++++++++++
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt |  11 ++
 2 files changed, 131 insertions(+)

diff --git a/integration-tests/test-loopback-highlevel.py 
b/integration-tests/test-loopback-highlevel.py
new file mode 100755
index 0000000..9ea49cf
--- /dev/null
+++ b/integration-tests/test-loopback-highlevel.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python3
+
+from requests import post, get
+from subprocess import call, Popen, PIPE
+from time import sleep
+import os
+import socket
+import hashlib
+import base64
+
+# Steps implemented in this test.
+#
+# 0 Prepare nexus.
+#  -> (a) Make a Nexus user, (b) make a loopback bank connection
+#     associated to that user
+
+# Nexus user details
+USERNAME = "person"
+PASSWORD = "y"
+USER_AUTHORIZATION_HEADER = "basic {}".format(
+    base64.b64encode(b"person:y").decode("utf-8")
+)
+
+# Admin authentication
+ADMIN_AUTHORIZATION_HEADER = "basic {}".format(
+    base64.b64encode(b"admin:x").decode("utf-8")
+)
+
+BANK_ACCOUNT_LABEL = "savings"
+
+# Databases
+NEXUS_DB="test-nexus.sqlite3"
+
+def fail(msg):
+    print(msg)
+    nexus.terminate()
+    sandbox.terminate()
+    exit(1)
+
+
+def checkPorts(ports):
+    for i in ports:
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        try:
+            s.bind(("0.0.0.0", i))
+            s.close()
+        except:
+            print("Port {} is not available".format(i))
+            exit(77)
+
+
+def assertResponse(response):
+    if response.status_code != 200:
+        print("Test failed on URL: {}".format(response.url))
+        # stdout/stderr from both services is A LOT of text.
+        # Confusing to dump all that to console.
+        print("Check nexus.log and sandbox.log, probably under /tmp")
+        nexus.terminate()
+        sandbox.terminate()
+        exit(1)
+    # Allows for finer grained checks.
+    return response
+
+
+# -1 Clean databases and start services.
+os.chdir("..")
+assert 0 == call(["rm", "-f", "nexus/{}".format(NEXUS_DB)])
+DEVNULL = open(os.devnull, "w")
+
+assert 0 == call(
+    ["./gradlew", "nexus:run", "--console=plain", "--args=superuser admin 
--password x --db-name={}".format(NEXUS_DB)]
+)
+
+# Start nexus
+checkPorts([5001])
+nexus = Popen(
+    ["./gradlew", "nexus:run", "--console=plain", "--args=serve 
--db-name={}".format(NEXUS_DB)],
+    stdout=PIPE,
+    stderr=PIPE,
+)
+for i in range(10):
+    try:
+        get("http://localhost:5001/";)
+    except:
+        if i == 9:
+            nexus.terminate()
+            stdout, stderr = nexus.communicate()
+            print("Nexus timed out")
+            print("{}\n{}".format(stdout.decode(), stderr.decode()))
+            exit(77)
+        sleep(2)
+        continue
+    break
+
+# 0.a, make a new nexus user.
+assertResponse(
+    post(
+        "http://localhost:5001/users";,
+        headers=dict(Authorization=ADMIN_AUTHORIZATION_HEADER),
+        json=dict(username=USERNAME, password=PASSWORD),
+    )
+)
+
+print("creating bank connection")
+
+# 0.b, make a ebics bank connection for the new user.
+assertResponse(
+    post(
+        "http://localhost:5001/bank-connections";,
+        json=dict(
+            name="my-loopback",
+            source="new",
+            type="loopback",
+        ),
+        headers=dict(Authorization=USER_AUTHORIZATION_HEADER),
+    )
+)
+
+nexus.terminate()
+print("Test passed!")
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 0945c0f..801f9a5 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -192,6 +192,13 @@ fun createEbicsBankConnectionFromBackup(
     return
 }
 
+fun createLoopbackBankConnection(bankConnectionName: String, user: 
NexusUserEntity, data: JsonNode) {
+    val bankConn = NexusBankConnectionEntity.new(bankConnectionName) {
+        owner = user
+        type = "loopback"
+    }
+}
+
 fun createEbicsBankConnection(bankConnectionName: String, user: 
NexusUserEntity, data: JsonNode) {
     val bankConn = NexusBankConnectionEntity.new(bankConnectionName) {
         owner = user
@@ -691,6 +698,10 @@ fun serverMain(dbName: String) {
                                 "ebics" -> {
                                     createEbicsBankConnection(body.name, user, 
body.data)
                                 }
+                                "loopback" -> {
+                                    createLoopbackBankConnection(body.name, 
user, body.data)
+
+                                }
                                 else -> {
                                     throw 
NexusError(HttpStatusCode.BadRequest, "connection type not supported")
                                 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]