gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] 02/02: stubs for #4781


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] 02/02: stubs for #4781
Date: Wed, 29 Mar 2017 00:25:43 +0200

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

marcello pushed a commit to branch master
in repository merchant.

commit 48de11406b70731ccaf7192d1710720d023d8bbf
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Mar 29 00:25:15 2017 +0200

    stubs for #4781
---
 src/mitm/README  | 14 ++++++++++++
 src/mitm/mitm.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/src/mitm/README b/src/mitm/README
new file mode 100644
index 0000000..1b23432
--- /dev/null
+++ b/src/mitm/README
@@ -0,0 +1,14 @@
+
+=== INTRODUCTION ===
+
+This directory contain a Web server that listens for
+requests addressed to the exchange, relays them to the
+exchange, and returns a modified response to the caller.
+
+The modifications are made to test error management in the
+merchant, and are driven by a HTTP header that instructs the
+proxy about the modifications to be made.
+
+=== INVOCATION ===
+
+FIXME
diff --git a/src/mitm/mitm.py b/src/mitm/mitm.py
new file mode 100644
index 0000000..0b6f9bc
--- /dev/null
+++ b/src/mitm/mitm.py
@@ -0,0 +1,69 @@
+#This file is part of TALER
+#Copyright (C) 2014, 2015, 2016, 2017 GNUnet e.V. and INRIA
+#
+#TALER is free software; you can redistribute it and/or modify it under the
+#terms of the GNU Lesser General Public License as published by the Free 
Software
+#Foundation; either version 2.1, or (at your option) any later version.
+#
+#TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+#WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+#A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
details.
+#
+#You should have received a copy of the GNU Lesser General Public License 
along with
+#TALER; see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>
+
+# @author Marcello Stanisci
+# @brief Error generator for responses coming from the exchange
+
+from flask import (request,
+                   Flask,
+                   jsonify)
+import requests
+from urllib.parse import (urljoin,
+                          urlencode,
+                          urlparse,
+                          urlunparse)
+from pytaler import amount
+import base64
+import os
+import logging
+import json
+from random import randint
+from datetime import datetime
+
+# FIXME make this as a standalone executable, and accept
+# the exchange url as a cli option.
+
+app = Flask(__name__)
+app.secret_key = base64.b64encode(os.urandom(64)).decode('utf-8')
+logger = logging.getLogger(__name__)
+exchange_url = os.environ.get("TALER_EXCHANGE_URL")
+assert(None != exchange_url)
+
+def track_transaction(resp):
+    return resp
+
+def track_transfer(resp):
+    return resp
+
address@hidden('/', defaults={'path': ''})
address@hidden('/<path:path>', methods=["GET", "POST"])
+def all(path):
+    body = request.get_json()
+    url = list(urlparse(request.url))
+    xurl = urlparse(exchange_url)
+    url[0] = xurl[0]
+    url[1] = xurl[1]
+    url = urlunparse(url)
+    print("Querying " + url)
+    r = requests.post(urljoin(url, path), json=body)
+    resp = dict()
+    if "application/json" == r.headers["Content-Type"]:
+        resp = r.json()
+    dispatcher = {
+        "track_transaction": track_transaction,
+        "track_transfer": track_transfer
+    }
+    func = dispatcher.get(request.headers.get("X-Taler-Mitm"),
+                          lambda x: x)
+    return jsonify(func(resp)), r.status_code

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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