gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (c6138ded -> 8cd553b2)


From: gnunet
Subject: [libeufin] branch master updated (c6138ded -> 8cd553b2)
Date: Fri, 13 Jan 2023 16:03:00 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from c6138ded honor API docs
     new 9040df7a move CLI tests
     new 8cd553b2 fix #7038

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Makefile                                    |   4 +-
 cli/bin/libeufin-cli                        | 102 +++++++++++++---------------
 cli/{bin => tests}/circuit_test.sh          |   0
 cli/{bin => tests}/circuit_test_file_tan.sh |   0
 cli/{bin => tests}/debit_test.sh            |   0
 cli/tests/libeufin-cli                      |   1 +
 cli/tests/registration_test.sh              |  43 ++++++++++++
 7 files changed, 94 insertions(+), 56 deletions(-)
 rename cli/{bin => tests}/circuit_test.sh (100%)
 rename cli/{bin => tests}/circuit_test_file_tan.sh (100%)
 rename cli/{bin => tests}/debit_test.sh (100%)
 create mode 120000 cli/tests/libeufin-cli
 create mode 100755 cli/tests/registration_test.sh

diff --git a/Makefile b/Makefile
index 6597f3c2..91576dbf 100644
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,8 @@ assemble:
 .PHONY: check
 check:
        @./gradlew check
-       @cd ./cli/bin && ./circuit_test.sh
-       @cd ./cli/bin && ./debit_test.sh
+       @cd ./cli/tests && ./circuit_test.sh
+       @cd ./cli/tests && ./debit_test.sh
 
 # .PHONY: parse
 # parse:
diff --git a/cli/bin/libeufin-cli b/cli/bin/libeufin-cli
index 417c25ea..1ac725b8 100755
--- a/cli/bin/libeufin-cli
+++ b/cli/bin/libeufin-cli
@@ -14,6 +14,17 @@ from requests import post, get, auth, delete, patch
 from urllib.parse import urljoin
 from getpass import getpass
 
+# Prepares the 'auth' option to pass to requests.
+def maybe_auth(sandbox_ctx):
+    if (sandbox_ctx.credentials_found):
+        return dict(
+            auth=auth.HTTPBasicAuth(
+                sandbox_ctx.username,
+                sandbox_ctx.password
+            )
+        )
+    return dict()
+
 def get_account_name(accountNameCli, usernameEnv):
     maybeUsername = accountNameCli
     if not maybeUsername:
@@ -292,16 +303,18 @@ class SandboxContext:
     def __init__(self):
         self.sandbox_base_url = None
         self.demobank_name = None
-        self.username, self.password = self.require_sandbox_credentials()
-
-    def require_sandbox_credentials(self):
-        sandbox_username = os.environ.get("LIBEUFIN_SANDBOX_USERNAME")
-        sandbox_password = os.environ.get("LIBEUFIN_SANDBOX_PASSWORD")
-        if not sandbox_username or not sandbox_password:
-            print("""INFO: LIBEUFIN_SANDBOX_USERNAME and 
LIBEUFIN_SANDBOX_PASSWORD
-not found in the environment, assuming tests are being run..."""
+        self.init_sandbox_credentials()
+        if not self.credentials_found:
+            print("""INFO: LIBEUFIN_SANDBOX_USERNAME or 
LIBEUFIN_SANDBOX_PASSWORD
+not found in the environment.  Won't authenticate"""
             )
-        return sandbox_username, sandbox_password
+
+    def init_sandbox_credentials(self):
+        self.username = os.environ.get("LIBEUFIN_SANDBOX_USERNAME")
+        self.password = os.environ.get("LIBEUFIN_SANDBOX_PASSWORD")
+        self.credentials_found = False
+        if self.username and self.password:
+            self.credentials_found = True 
 
     def require_sandbox_base_url(self):
         if self.sandbox_base_url:
@@ -1087,7 +1100,7 @@ def make_ebics_host(obj, host_id):
         resp = post(
             url,
             json=dict(hostID=host_id, ebicsVersion="2.5"),
-            auth=auth.HTTPBasicAuth(obj.username, obj.password),
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1104,7 +1117,7 @@ def list_ebics_host(obj):
     sandbox_base_url = obj.require_sandbox_base_url()
     url = urljoin_nodrop(sandbox_base_url, "/admin/ebics/hosts")
     try:
-        resp = get(url,auth=auth.HTTPBasicAuth(obj.username, obj.password))
+        resp = get(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox")
@@ -1132,7 +1145,7 @@ def create_ebics_subscriber(obj, host_id, partner_id, 
user_id):
         resp = post(
             url,
             json=dict(hostID=host_id, partnerID=partner_id, userID=user_id),
-            auth=auth.HTTPBasicAuth(obj.username, obj.password),
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1149,7 +1162,7 @@ def list_ebics_subscriber(obj):
     sandbox_base_url = obj.require_sandbox_base_url()
     url = urljoin_nodrop(sandbox_base_url, "/admin/ebics/subscribers")
     try:
-        resp = get(url,auth=auth.HTTPBasicAuth(obj.username, obj.password))
+        resp = get(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox")
@@ -1203,7 +1216,7 @@ def associate_bank_account(
     try:
         resp = post(
             url, json=body,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password),
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1247,10 +1260,7 @@ def sandbox_demobank(ctx, demobank_name):
 def sandbox_demobank_list_transactions(obj, bank_account):
     url = obj.access_api_url (f"/accounts/{bank_account}/transactions")
     try:
-        resp = get(
-            url,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password),
-        )
+        resp = get(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox at " + url)
@@ -1286,7 +1296,7 @@ def sandbox_demobank_new_transaction(obj, bank_account, 
payto_with_subject, amou
         resp = post(
             url,
             json=body,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password),
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1305,10 +1315,7 @@ def sandbox_demobank_new_transaction(obj, bank_account, 
payto_with_subject, amou
 def sandbox_demobank_info(obj, bank_account):
     url = obj.access_api_url (f"/accounts/{bank_account}")
     try:
-        resp = get(
-            url,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
-        )
+        resp = get(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox")
@@ -1337,13 +1344,7 @@ def debug_url(obj):
 def sandbox_demobank_delete(obj, bank_account):
     url = obj.access_api_url (f"/accounts/{bank_account}")
     try:
-        resp = delete(
-            url,
-            auth=auth.HTTPBasicAuth(
-              obj.username,
-              obj.password
-            )
-        )
+        resp = delete(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox at " + url)
@@ -1373,16 +1374,15 @@ def sandbox_demobank_delete(obj, bank_account):
 @click.pass_obj
 def sandbox_demobank_register(obj, public, name, iban):
     url = obj.access_api_url ("/testing/register")
+    if not obj.credentials_found:
+        print("WARNING: registering with unset credentials in the 
environment!!")
     req = dict(username=obj.username, password=obj.password, isPublic=public)
     if name != "":
         req.update(name=name)
     if iban:
         req.update(iban=iban)
     try:
-        resp = post(
-            url,
-            json=req,
-        )
+        resp = post(url, json=req)
     except Exception as e:
         print(e)
         print("Could not reach sandbox at " + url)
@@ -1412,10 +1412,7 @@ def sandbox_demobank_ebicssubscriber(obj, host_id, 
partner_id, user_id, bank_acc
                 userID=user_id,
                 demobankAccountLabel=bank_account
             ),
-            auth=auth.HTTPBasicAuth(
-                obj.username,
-                obj.password
-            ),
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1429,7 +1426,7 @@ def bankaccount_list(obj):
     sandbox_base_url = obj.require_sandbox_base_url()
     url = urljoin_nodrop(sandbox_base_url, f"/admin/bank-accounts")
     try:
-        resp = get(url,auth=auth.HTTPBasicAuth(obj.username, obj.password))
+        resp = get(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox")
@@ -1448,7 +1445,7 @@ def transactions_list(obj, account_label):
         sandbox_base_url, f"/admin/bank-accounts/{account_label}/transactions"
     )
     try:
-        resp = get(url,auth=auth.HTTPBasicAuth(obj.username, obj.password))
+        resp = get(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox")
@@ -1468,10 +1465,7 @@ def bankaccount_generate_transactions(obj, 
account_label):
         f"/admin/bank-accounts/{account_label}/generate-transactions"
     )
     try:
-        resp = post(
-            url,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
-        )
+        resp = post(url, **maybe_auth(obj))
     except Exception as e:
         print(e)
         print("Could not reach sandbox")
@@ -1516,7 +1510,7 @@ def simulate_incoming_transaction(
         resp = post(
             url,
             json=body,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1553,11 +1547,11 @@ def circuit_cashout_confirm(obj, tan, uuid):
         resp = post(
             cashout_confirm_endpoint,
             json=req,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
-        print("Could not reach the bank at " + cashout_abort_endpoint)
+        print("Could not reach the bank at " + cashout_confirm_endpoint)
         exit(1)
 
     check_response_status(resp, 204)
@@ -1579,7 +1573,7 @@ def circuit_cashout_abort(obj, uuid):
     try:
         resp = post(
             cashout_abort_endpoint,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1604,7 +1598,7 @@ def circuit_cashout_info(obj, uuid):
     try:
         resp = get(
             cashout_info_endpoint,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1641,7 +1635,7 @@ def circuit_delete(obj, username):
     try:
         resp = delete(
             account_deletion_endpoint,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1727,7 +1721,7 @@ def circuit_register(
         resp = post(
             registration_endpoint,
             json=req,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1782,7 +1776,7 @@ def circuit_reconfig(
         resp = patch(
             reconfig_endpoint,
             json=req,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1830,7 +1824,7 @@ def password_reconfig(obj, username):
         resp = patch(
             password_reconfig_endpoint,
             json=req,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
@@ -1883,7 +1877,7 @@ def circuit_cashout(obj, subject, amount_debit, 
amount_credit, tan_channel):
         resp = post(
             cashout_creation_endpoint,
             json=req,
-            auth=auth.HTTPBasicAuth(obj.username, obj.password)
+            **maybe_auth(obj)
         )
     except Exception as e:
         print(e)
diff --git a/cli/bin/circuit_test.sh b/cli/tests/circuit_test.sh
similarity index 100%
rename from cli/bin/circuit_test.sh
rename to cli/tests/circuit_test.sh
diff --git a/cli/bin/circuit_test_file_tan.sh 
b/cli/tests/circuit_test_file_tan.sh
similarity index 100%
rename from cli/bin/circuit_test_file_tan.sh
rename to cli/tests/circuit_test_file_tan.sh
diff --git a/cli/bin/debit_test.sh b/cli/tests/debit_test.sh
similarity index 100%
rename from cli/bin/debit_test.sh
rename to cli/tests/debit_test.sh
diff --git a/cli/tests/libeufin-cli b/cli/tests/libeufin-cli
new file mode 120000
index 00000000..c69a3d87
--- /dev/null
+++ b/cli/tests/libeufin-cli
@@ -0,0 +1 @@
+../bin/libeufin-cli
\ No newline at end of file
diff --git a/cli/tests/registration_test.sh b/cli/tests/registration_test.sh
new file mode 100755
index 00000000..0e561cbc
--- /dev/null
+++ b/cli/tests/registration_test.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# Tests successful cases of the CLI acting
+# as the client of the Circuit API.
+
+set -eu
+
+echo TESTING ACCESS API REGISTRATION
+jq --version &> /dev/null || (echo "'jq' command not found"; exit 77)
+curl --version &> /dev/null || (echo "'curl' command not found"; exit 77)
+
+DB_PATH=/tmp/registration-test.sqlite3
+export LIBEUFIN_SANDBOX_DB_CONNECTION=jdbc:sqlite:$DB_PATH
+
+echo -n Delete previous data..
+rm -f $DB_PATH
+echo DONE
+echo -n Configure the default demobank, with users limit 0...
+libeufin-sandbox config default
+echo DONE
+echo -n Start the bank...
+export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=circuit
+libeufin-sandbox serve &> sandbox.log &
+SANDBOX_PID=$!
+trap "echo -n 'killing the bank (pid $SANDBOX_PID)...'; kill $SANDBOX_PID; 
wait; echo DONE" EXIT
+echo DONE
+echo -n Wait for the bank...
+curl --max-time 2 --retry-connrefused --retry-delay 1 --retry 10 
http://localhost:5000/ &> /dev/null
+echo DONE
+
+echo -n "Register new account..."
+export LIBEUFIN_SANDBOX_USERNAME=www
+export LIBEUFIN_SANDBOX_PASSWORD=foo
+
+./libeufin-cli \
+  sandbox --sandbox-url http://localhost:5000/ \
+  demobank \
+  register
+echo DONE
+
+echo -n Check the account is found...
+curl -u "www:foo" 
http://localhost:5000/demobanks/default/access-api/accounts/www
+echo DONE

-- 
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]