[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: Worked on testing the api. Test
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: Worked on testing the api. Tests not functioning yet |
Date: |
Sat, 23 Nov 2019 23:26:56 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 1a57862 Worked on testing the api. Tests not functioning yet
1a57862 is described below
commit 1a57862b3870e71052b0770e56256f193329b6fb
Author: Dennis Neufeld <address@hidden>
AuthorDate: Sat Nov 23 22:26:27 2019 +0000
Worked on testing the api. Tests not functioning yet
---
src/include/anastasis_testing_lib.h | 139 ++++++++++++
src/lib/Makefile.am | 53 ++++-
src/lib/anastasis_api_policy.c | 4 -
src/lib/test_anastasis_api.c | 427 ++++++++++++++++++++++++++++++++++++
src/lib/testing_api_cmd_policy.c | 214 ++++++++++++++++++
src/lib/testing_api_helpers.c | 196 +++++++++++++++++
src/stasis/anastasis_db_plugin.c | 3 +-
src/util/Makefile.am | 14 +-
src/util/anastasis-dbinit.c | 113 ++++++++++
9 files changed, 1156 insertions(+), 7 deletions(-)
diff --git a/src/include/anastasis_testing_lib.h
b/src/include/anastasis_testing_lib.h
new file mode 100644
index 0000000..a6657b7
--- /dev/null
+++ b/src/include/anastasis_testing_lib.h
@@ -0,0 +1,139 @@
+/*
+ This file is part of TALER
+ (C) 2018 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file include/anastasis_testing_lib.h
+ * @brief API for writing an interpreter to test Taler components
+ * @author Christian Grothoff <address@hidden>
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+#ifndef ANASTASIS_TESTING_LIB_H
+#define ANASTASIS_TESTING_LIB_H
+
+#include "anastasis_service.h"
+#include <gnunet/gnunet_json_lib.h>
+#include <microhttpd.h>
+
+/* ********************* Helper functions ********************* */
+
+#define ANASTASIS_FAIL() \
+ do {GNUNET_break (0); return NULL; } while (0)
+
+/**
+ * Prepare the merchant execution. Create tables and check if
+ * the port is available.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the base url, or NULL upon errors. Must be freed
+ * by the caller.
+ */
+char *
+TALER_TESTING_prepare_merchant (const char *config_filename);
+
+
+/**
+ * Start the merchant backend process. Assume the port
+ * is available and the database is clean. Use the "prepare
+ * merchant" function to do such tasks.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the process, or NULL if the process could not
+ * be started.
+ */
+struct GNUNET_OS_Process *
+TALER_TESTING_run_merchant (const char *config_filename,
+ const char *merchant_url);
+
+
+/**
+ * Start the anastasis backend process. Assume the port
+ * is available and the database is clean. Use the "prepare
+ * anastasis" function to do such tasks.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the process, or NULL if the process could not
+ * be started.
+ */
+struct GNUNET_OS_Process *
+TALER_TESTING_run_anastasis (const char *config_filename,
+ const char *anastasis_url);
+
+
+/**
+ * Prepare the anastasis execution. Create tables and check if
+ * the port is available.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the base url, or NULL upon errors. Must be freed
+ * by the caller.
+ */
+char *
+TALER_TESTING_prepare_anastasis (const char *config_filename);
+
+
+/* ************** Specific interpreter commands ************ */
+
+/**
+ * Make the "policy store" command.
+ *
+ * @param label command label
+ * @param anastasis_url base URL of the anastasis serving
+ * the policy store request.
+ * @param http_status expected HTTP status.
+ * @param pub account identifier
+ * @param payment_id payment identifier
+ * @param policy_data recovery data to post
+ *
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_policy_store (const char *label,
+ const char *anastasis_url,
+ unsigned int http_status,
+ const struct
+ ANASTASIS_AccountPubP *pub,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_id,
+ const void *policy_data);
+/**
+ * Make a "policy lookup" command.
+ *
+ * @param label command label.
+ * @param anastasis_url base URL of the anastasis backend
+ * serving the policy lookup request.
+ * @param http_status expected HTTP response code.
+ * @param policy_reference reference to a "policy store" CMD.
+ * @param order_id order id to lookup, can be NULL.
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_policy_lookup (const char *label,
+ const char *anastasis_url,
+ unsigned int http_status,
+ const char *proposal_reference,
+ const struct
+ ANASTASIS_AccountPubP pub);
+
+#endif
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 3e67e50..806c246 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -7,12 +7,17 @@ if USE_COVERAGE
endif
lib_LTLIBRARIES = \
- libanastasis.la
+ libanastasis.la \
+ libanastasistesting.la
libanastasis_la_LDFLAGS = \
-version-info 0:0:0 \
-no-undefined
+libanastasistesting_la_LDFLAGS = \
+ -version-info 0:0:0 \
+ -no-undefined
+
libanastasis_la_SOURCES = \
anastasis_api_salt.c \
anastasis_api_policy.c
@@ -26,6 +31,22 @@ libanastasis_la_LIBADD = \
-ltalerutil
$(XLIB)
+libanastasistesting_la_SOURCES = \
+ testing_api_cmd_policy.c \
+ testing_api_helpers.c
+
+libanastasistesting_la_LIBADD = \
+ libanastasis.la \
+ -ltalerexchange \
+ -ltalerjson \
+ -ltalerutil \
+ -lgnunetcurl \
+ -lgnunetjson \
+ -lgnunetutil \
+ -ljansson \
+ -ltalertesting \
+ $(XLIB)
+
if HAVE_LIBCURL
libanastasis_la_LIBADD += -lcurl
else
@@ -34,4 +55,34 @@ libanastasis_la_LIBADD += -lgnurl
endif
endif
+check_PROGRAMS = \
+ test_anastasis_api
+
+TESTS = \
+ $(check_PROGRAMS)
+
+test_anastasis_api_SOURCES = \
+ test_anastasis_api.c
+test_anastasis_api_LDADD = \
+ $(top_srcdir)/src/stasis/libanastasisdb.la \
+ libanastasis.la \
+ $(LIBGCRYPT_LIBS) \
+ -ltalertesting \
+ -lanastasistesting \
+ -ltalermerchanttesting \
+ -ltalerfakebank \
+ -ltalerbank \
+ -ltalerexchange \
+ -ltalermerchant \
+ -ltalerjson \
+ -ltalerutil \
+ -lgnunetjson \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -ljansson
+EXTRA_DIST = \
+ test_anastasis_api.conf \
+ test_anastasis_api_home/.local/share/taler/exchange/offline-keys/master.priv
\
+ test_anastasis_api_home/.config/taler/merchant/wire/test.json \
+ test_anastasis_api_home/.config/taler/test.json
\ No newline at end of file
diff --git a/src/lib/anastasis_api_policy.c b/src/lib/anastasis_api_policy.c
index 1549453..1236929 100644
--- a/src/lib/anastasis_api_policy.c
+++ b/src/lib/anastasis_api_policy.c
@@ -35,10 +35,6 @@
#include <taler/taler_util.h>
#include "anastasis_service.h"
-#if COMPRESS_BODIES
-#include <zlib.h>
-#endif
-
/**
* @brief A Contract Operation Handle
diff --git a/src/lib/test_anastasis_api.c b/src/lib/test_anastasis_api.c
new file mode 100644
index 0000000..2354660
--- /dev/null
+++ b/src/lib/test_anastasis_api.c
@@ -0,0 +1,427 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2018 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file exchange/test_merchant_api_new.c
+ * @brief testcase to test exchange's HTTP API interface
+ * @author Sree Harsha Totakura <address@hidden>
+ * @author Christian Grothoff
+ * @author Marcello Stanisci
+ */
+
+#include "platform.h"
+#include <taler/taler_util.h>
+#include <taler/taler_signatures.h>
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_json_lib.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include <taler/taler_bank_service.h>
+#include <taler/taler_fakebank_lib.h>
+#include <taler/taler_testing_lib.h>
+#include <taler/taler_error_codes.h>
+#include "anastasis_testing_lib.h"
+
+/**
+ * Configuration file we use. One (big) configuration is used
+ * for the various components for this test.
+ */
+#define CONFIG_FILE "test_anastasis_api.conf"
+
+/**
+ * Exchange base URL. Could also be taken from config.
+ */
+#define EXCHANGE_URL "http://localhost:8081/"
+
+static const char *pickup_amounts_1[] = {"EUR:5", NULL};
+
+/**
+ * URL of the fakebank.
+ */
+static char *fakebank_url;
+
+/**
+ * Merchant base URL.
+ */
+static char *merchant_url;
+
+/**
+ * Anastasis base URL.
+ */
+static char *anastasis_url;
+
+/**
+ * Merchant process.
+ */
+static struct GNUNET_OS_Process *merchantd;
+
+/**
+ * Anastasis process.
+ */
+static struct GNUNET_OS_Process *anastasisd;
+
+/**
+ * Exchange base URL.
+ */
+static char *exchange_url;
+
+/**
+ * Auditor base URL; only used to fix FTBFS.
+ */
+static char *auditor_url;
+
+/**
+ * Account number of the exchange at the bank.
+ */
+#define EXCHANGE_ACCOUNT_NO 2
+
+/**
+ * Account number of some user.
+ */
+#define USER_ACCOUNT_NO 62
+
+/**
+ * Account number used by the merchant
+ */
+#define MERCHANT_ACCOUNT_NO 3
+
+/**
+ * User name. Never checked by fakebank.
+ */
+#define USER_LOGIN_NAME "user42"
+
+/**
+ * User password. Never checked by fakebank.
+ */
+#define USER_LOGIN_PASS "pass42"
+
+/**
+ * Execute the taler-exchange-wirewatch command with
+ * our configuration file.
+ *
+ * @param label label to use for the command.
+ */
+#define CMD_EXEC_WIREWATCH(label) \
+ TALER_TESTING_cmd_exec_wirewatch (label, CONFIG_FILE)
+
+/**
+ * Execute the taler-exchange-aggregator command with
+ * our configuration file.
+ *
+ * @param label label to use for the command.
+ */
+#define CMD_EXEC_AGGREGATOR(label) \
+ TALER_TESTING_cmd_exec_aggregator (label, CONFIG_FILE)
+
+/**
+ * Run wire transfer of funds from some user's account to the
+ * exchange.
+ *
+ * @param label label to use for the command.
+ * @param amount amount to transfer, i.e. "EUR:1"
+ * @param url exchange_url
+ */
+#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
+ TALER_TESTING_cmd_fakebank_transfer (label, amount, \
+ fakebank_url, USER_ACCOUNT_NO, \
+ EXCHANGE_ACCOUNT_NO, \
+ USER_LOGIN_NAME, USER_LOGIN_PASS, \
+ EXCHANGE_URL)
+
+/**
+ * Run wire transfer of funds from some user's account to the
+ * exchange.
+ *
+ * @param label label to use for the command.
+ * @param amount amount to transfer, i.e. "EUR:1"
+ */
+#define CMD_TRANSFER_TO_EXCHANGE_SUBJECT(label,amount,subject) \
+ TALER_TESTING_cmd_fakebank_transfer_with_subject \
+ (label, amount, fakebank_url, USER_ACCOUNT_NO, \
+ EXCHANGE_ACCOUNT_NO, USER_LOGIN_NAME, USER_LOGIN_PASS, \
+ subject)
+
+
+static struct GNUNET_CONTAINER_MultiHashMap *interned_strings;
+
+static const char *
+intern (const char *str)
+{
+ struct GNUNET_HashCode hash;
+ const char *hs;
+
+ if (NULL == interned_strings)
+ interned_strings = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ GNUNET_assert (NULL != interned_strings);
+ GNUNET_CRYPTO_hash (str, strlen (str), &hash);
+ hs = GNUNET_CONTAINER_multihashmap_get (interned_strings, &hash);
+ if (NULL != hs)
+ return hs;
+ hs = GNUNET_strdup (str);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
+ interned_strings,
+ &hash,
+ (void *) hs,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ return hs;
+}
+
+
+#define BUF_SZ 512
+
+static const char *
+merchant_url_internal (const char *instance_id)
+{
+ char buf[BUF_SZ];
+ if (NULL == instance_id)
+ GNUNET_assert (0 < snprintf (buf, BUF_SZ, "%s", merchant_url));
+ else
+ GNUNET_assert (0 < snprintf (buf, BUF_SZ, "%sinstances/%s/", merchant_url,
+ instance_id));
+ return intern (buf);
+}
+
+
+static const char *
+merchant_url_external (const char *instance_id)
+{
+ char buf[BUF_SZ];
+ if (NULL == instance_id)
+ GNUNET_assert (0 < snprintf (buf, BUF_SZ, "%spublic/", merchant_url));
+ else
+ GNUNET_assert (0 < snprintf (buf, BUF_SZ, "%spublic/instances/%s/",
+ merchant_url, instance_id));
+ return intern (buf);
+}
+
+
+/**
+ * Main function that will tell the interpreter what commands to
+ * run.
+ *
+ * @param cls closure
+ */
+static void
+run (void *cls,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct TALER_TESTING_Command pay[] = {
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
+ "EUR:10.02"),
+ /**
+ * Make a reserve exist, according to the previous
+ * transfer.
+ */
+ CMD_EXEC_WIREWATCH ("wirewatch-1"),
+
+ TALER_TESTING_cmd_check_bank_transfer
+ ("check_bank_transfer-2",
+ EXCHANGE_URL,
+ "EUR:10.02",
+ USER_ACCOUNT_NO,
+ EXCHANGE_ACCOUNT_NO),
+
+ TALER_TESTING_cmd_withdraw_amount
+ ("withdraw-coin-1",
+ "create-reserve-1",
+ "EUR:5",
+ MHD_HTTP_OK),
+
+ TALER_TESTING_cmd_withdraw_amount
+ ("withdraw-coin-2",
+ "create-reserve-1",
+ "EUR:5",
+ MHD_HTTP_OK),
+
+ /**
+ * Check the reserve is depleted.
+ */
+ TALER_TESTING_cmd_status ("withdraw-status-1",
+ "create-reserve-1",
+ "EUR:0",
+ MHD_HTTP_OK),
+
+ TALER_TESTING_cmd_check_bank_empty
+ ("check_bank_empty-1"),
+
+ CMD_EXEC_AGGREGATOR ("run-aggregator"),
+
+ TALER_TESTING_cmd_check_bank_transfer
+ ("check_bank_transfer-498c",
+ EXCHANGE_URL,
+ "EUR:4.98",
+ EXCHANGE_ACCOUNT_NO,
+ MERCHANT_ACCOUNT_NO),
+
+ TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-2"),
+
+ TALER_TESTING_cmd_end ()
+ };
+
+ struct TALER_TESTING_Command policy[] = {
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
+ "EUR:10.02"),
+ /**
+ * Make a reserve exist, according to the previous
+ * transfer.
+ */
+ CMD_EXEC_WIREWATCH ("wirewatch-1"),
+
+ TALER_TESTING_cmd_check_bank_transfer
+ ("check_bank_transfer-2",
+ EXCHANGE_URL,
+ "EUR:10.02",
+ USER_ACCOUNT_NO,
+ EXCHANGE_ACCOUNT_NO),
+
+ TALER_TESTING_cmd_withdraw_amount
+ ("withdraw-coin-1",
+ "create-reserve-1",
+ "EUR:5",
+ MHD_HTTP_OK),
+
+ TALER_TESTING_cmd_withdraw_amount
+ ("withdraw-coin-2",
+ "create-reserve-1",
+ "EUR:5",
+ MHD_HTTP_OK),
+
+ /**
+ * Check the reserve is depleted.
+ */
+ TALER_TESTING_cmd_status ("withdraw-status-1",
+ "create-reserve-1",
+ "EUR:0",
+ MHD_HTTP_OK),
+
+ TALER_TESTING_cmd_check_bank_empty
+ ("check_bank_empty-1"),
+
+ CMD_EXEC_AGGREGATOR ("run-aggregator"),
+
+ TALER_TESTING_cmd_check_bank_transfer
+ ("check_bank_transfer-498c",
+ EXCHANGE_URL,
+ "EUR:4.98",
+ EXCHANGE_ACCOUNT_NO,
+ MERCHANT_ACCOUNT_NO),
+
+ TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-2"),
+
+ TALER_TESTING_cmd_end ()
+ };
+
+ struct TALER_TESTING_Command commands[] = {
+
+ TALER_TESTING_cmd_batch ("pay",
+ pay),
+
+ TALER_TESTING_cmd_batch ("policy",
+ policy),
+
+
+ /**
+ * End the suite. Fixme: better to have a label for this
+ * too, as it shows a "(null)" token on logs.
+ */
+ TALER_TESTING_cmd_end ()
+ };
+
+ TALER_TESTING_run_with_fakebank (is,
+ commands,
+ fakebank_url);
+}
+
+int
+main (int argc,
+ char *const *argv)
+{
+ unsigned int ret;
+ /* These environment variables get in the way... */
+ unsetenv ("XDG_DATA_HOME");
+ unsetenv ("XDG_CONFIG_HOME");
+
+ GNUNET_log_setup ("test-anastasis-api-new",
+ "DEBUG",
+ NULL);
+ if (NULL ==
+ (fakebank_url = TALER_TESTING_prepare_fakebank
+ (CONFIG_FILE,
+ "account-exchange")))
+ return 77;
+ if (NULL ==
+ (merchant_url = TALER_TESTING_prepare_merchant (CONFIG_FILE)))
+ return 77;
+
+ if (NULL ==
+ (anastasis_url = TALER_TESTING_prepare_anastasis (CONFIG_FILE)))
+ return 77;
+
+ TALER_TESTING_cleanup_files (CONFIG_FILE);
+
+ switch (TALER_TESTING_prepare_exchange (CONFIG_FILE,
+ &auditor_url,
+ &exchange_url))
+ {
+ case GNUNET_SYSERR:
+ GNUNET_break (0);
+ return 1;
+ case GNUNET_NO:
+ return 77;
+
+ case GNUNET_OK:
+
+ if (NULL == (merchantd =
+ TALER_TESTING_run_merchant (CONFIG_FILE, merchant_url)))
+ return 1;
+
+ if (NULL == (anastasisd =
+ TALER_TESTING_run_anastasis (CONFIG_FILE, anastasis_url)))
+ return 1;
+
+ ret = TALER_TESTING_setup_with_exchange (&run,
+ NULL,
+ CONFIG_FILE);
+
+ GNUNET_OS_process_kill (merchantd, SIGTERM);
+ GNUNET_OS_process_kill (anastasisd, SIGTERM);
+ GNUNET_OS_process_wait (merchantd);
+ GNUNET_OS_process_wait (anastasisd);
+ GNUNET_OS_process_destroy (merchantd);
+ GNUNET_OS_process_destroy (anastasisd);
+ GNUNET_free (merchant_url);
+ GNUNET_free (anastasis_url);
+
+ if (GNUNET_OK != ret)
+ return 1;
+ break;
+ default:
+ GNUNET_break (0);
+ return 1;
+ }
+ return 0;
+}
+
+/* end of test_merchant_api_new.c */
diff --git a/src/lib/testing_api_cmd_policy.c b/src/lib/testing_api_cmd_policy.c
new file mode 100644
index 0000000..80adee2
--- /dev/null
+++ b/src/lib/testing_api_cmd_policy.c
@@ -0,0 +1,214 @@
+/*
+ This file is part of ANASTASIS
+ Copyright (C) 2014-2019 Taler Systems SA
+
+ ANASTASIS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ ANASTASIS 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with ANASTASIS; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file lib/testing_api_cmd_policy.c
+ * @brief command to execute the anastasis backend service.
+ * @author Marcello Stanisci
+ */
+
+#include "platform.h"
+#include "anastasis_service.h"
+#include "anastasis_testing_lib.h"
+#include <taler/taler_util.h>
+#include <taler/taler_testing_lib.h>
+
+/**
+ * State for a "policy store" CMD.
+ */
+struct PolicyStoreState
+{
+
+ /**
+ * The policy data.
+ */
+ const void *policy_data;
+
+ /**
+ * Expected status code.
+ */
+ unsigned int http_status;
+
+ /**
+ * Eddsa Publickey.
+ */
+ const struct ANASTASIS_AccountPubP *anastasis_pub;
+
+ /**
+ * The /policy POST operation handle.
+ */
+ struct ANASTASIS_PolicyStoreOperation *pso;
+
+ /**
+ * The nonce.
+ */
+ struct GNUNET_CRYPTO_EddsaPublicKey nonce;
+
+ /**
+ * URL of the anastasis backend.
+ */
+ const char *anastasis_url;
+
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Payment identifier.
+ */
+ const struct ANASTASIS_PaymentSecretP *payment_id;
+};
+
+
+/**
+ * State for a "policy lookup" CMD.
+ */
+struct PolicyLookupState
+{
+ /**
+ * The interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Eddsa Publickey.
+ */
+ const struct ANASTASIS_AccountPubP anastasis_pub;
+
+ /**
+ * URL of the anastasis backend.
+ */
+ const char *anastasis_url;
+
+ /**
+ * Expected status code.
+ */
+ unsigned int http_status;
+
+ /**
+ * The /policy GET operation handle.
+ */
+ struct ANASTASIS_PolicyLookupOperation *plo;
+};
+
+
+/**
+ * Run a "policy store" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+policy_store_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PolicyStoreState *pss = cls;
+
+ pss->is = is;
+
+
+ GNUNET_CRYPTO_random_block
+ (GNUNET_CRYPTO_QUALITY_WEAK,
+ &pss->nonce,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+
+ pss->pso = ANASTASIS_policy_store (is->ctx,
+ pss->anastasis_url,
+ pss->anastasis_pub,
+ pss->policy_data,
+ sizeof (pss->policy_data),
+ pss->payment_id,
+ NULL,
+ //&policy_store_cb,
+ pss);
+ GNUNET_assert (NULL != pss->pso);
+}
+
+
+/**
+ * Free the state of a "policy sore" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ * @param cmd command being freed.
+ */
+static void
+policy_store_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PolicyStoreState *pss = cls;
+
+ if (NULL != pss->pso)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Command '%s' did not complete (policy post)\n",
+ cmd->label);
+ ANASTASIS_policy_store_cancel (pss->pso);
+ pss->pso = NULL;
+ }
+
+ //GNUNET_free_non_null ((void *) pss->order_id);
+ GNUNET_free (pss);
+}
+
+
+/**
+ * Make the "policy store" command.
+ *
+ * @param label command label
+ * @param anastasis_url base URL of the anastasis serving
+ * the policy store request.
+ * @param http_status expected HTTP status.
+ * @param pub account identifier
+ * @param payment_id payment identifier
+ * @param policy_data recovery data to post
+ *
+ * @return the command
+ */
+struct TALER_TESTING_Command
+ANASTASIS_TESTING_cmd_policy_store (const char *label,
+ const char *anastasis_url,
+ unsigned int http_status,
+ const struct
+ ANASTASIS_AccountPubP *pub,
+ const struct
+ ANASTASIS_PaymentSecretP *payment_id,
+ const void *policy_data)
+{
+ struct PolicyStoreState *pss;
+
+ pss = GNUNET_new (struct PolicyStoreState);
+ pss->anastasis_pub = pub;
+ pss->policy_data = policy_data;
+ pss->payment_id = payment_id;
+ pss->http_status = http_status;
+ pss->anastasis_url = anastasis_url;
+
+ struct TALER_TESTING_Command cmd = {
+ .cls = pss,
+ .label = label,
+ .run = &policy_store_run,
+ .cleanup = &policy_store_cleanup
+ };
+
+ return cmd;
+}
\ No newline at end of file
diff --git a/src/lib/testing_api_helpers.c b/src/lib/testing_api_helpers.c
new file mode 100644
index 0000000..bc5e3f6
--- /dev/null
+++ b/src/lib/testing_api_helpers.c
@@ -0,0 +1,196 @@
+/*
+ This file is part of ANASTASIS
+ Copyright (C) 2014-2018 Taler Systems SA
+
+ ANASTASIS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ ANASTASIS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ ANASTASISABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with ANASTASIS; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file lib/testing_api_helpers.c
+ * @brief helper functions for test library.
+ * @author Christian Grothoff
+ * @author Marcello Stanisci
+ */
+
+#include "platform.h"
+#include <taler/taler_testing_lib.h>
+#include "anastasis_testing_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+
+
+/**
+ * Start the anastasis backend process. Assume the port
+ * is available and the database is clean. Use the "prepare
+ * anastasis" function to do such tasks.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the process, or NULL if the process could not
+ * be started.
+ */
+struct GNUNET_OS_Process *
+TALER_TESTING_run_anastasis (const char *config_filename,
+ const char *anastasis_url)
+{
+ struct GNUNET_OS_Process *anastasis_proc;
+ unsigned int iter;
+ char *wget_cmd;
+
+ anastasis_proc
+ = GNUNET_OS_start_process (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "anastasis-httpd",
+ "anastasis-httpd",
+ "--log=INFO",
+ "-c", config_filename,
+ NULL);
+ if (NULL == anastasis_proc)
+ ANASTASIS_FAIL ();
+
+ GNUNET_asprintf (&wget_cmd,
+ "wget -q -t 1 -T 1"
+ " --header='Authorization: ApiKey sandbox'"
+ " %s"
+ " -o /dev/null -O /dev/null",
+ anastasis_url);
+
+ /* give child time to start and bind against the socket */
+ fprintf (stderr,
+ "Waiting for `anastasis-httpd' to be ready\n");
+ iter = 0;
+ do
+ {
+ if (10 == iter)
+ {
+ fprintf (stderr,
+ "Failed to launch"
+ " `anastasis-httpd' (or `wget')\n");
+ GNUNET_OS_process_kill (anastasis_proc,
+ SIGTERM);
+ GNUNET_OS_process_wait (anastasis_proc);
+ GNUNET_OS_process_destroy (anastasis_proc);
+ ANASTASIS_FAIL ();
+ }
+ fprintf (stderr, ".\n");
+ sleep (1);
+ iter++;
+ }
+ while (0 != system (wget_cmd));
+ GNUNET_free (wget_cmd);
+ fprintf (stderr, "\n");
+
+ return anastasis_proc;
+}
+
+
+/**
+ * Prepare the anastasis execution. Create tables and check if
+ * the port is available.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the base url, or NULL upon errors. Must be freed
+ * by the caller.
+ */
+char *
+TALER_TESTING_prepare_anastasis (const char *config_filename)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ unsigned long long port;
+ struct GNUNET_OS_Process *dbinit_proc;
+ enum GNUNET_OS_ProcessStatusType type;
+ unsigned long code;
+ char *base_url;
+
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (cfg,
+ config_filename))
+ ANASTASIS_FAIL ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "anastasis",
+ "PORT",
+ &port))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "anastasis",
+ "PORT");
+ GNUNET_CONFIGURATION_destroy (cfg);
+ ANASTASIS_FAIL ();
+ }
+
+ GNUNET_CONFIGURATION_destroy (cfg);
+
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
+ (uint16_t) port))
+ {
+ fprintf (stderr,
+ "Required port %llu not available, skipping.\n",
+ port);
+ ANASTASIS_FAIL ();
+ }
+
+ /* DB preparation */
+ if (NULL == (dbinit_proc = GNUNET_OS_start_process
+ (GNUNET_NO,
+ GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "anastasis-dbinit",
+ "anastasis-dbinit",
+ "-c", config_filename,
+ "-r",
+ NULL)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run anastasis-dbinit."
+ " Check your PATH.\n");
+ ANASTASIS_FAIL ();
+ }
+
+ if (GNUNET_SYSERR ==
+ GNUNET_OS_process_wait_status (dbinit_proc,
+ &type,
+ &code))
+ {
+ GNUNET_OS_process_destroy (dbinit_proc);
+ ANASTASIS_FAIL ();
+ }
+ if ( (type == GNUNET_OS_PROCESS_EXITED) &&
+ (0 != code) )
+ {
+ fprintf (stderr,
+ "Failed to setup database\n");
+ ANASTASIS_FAIL ();
+ }
+ if ( (type != GNUNET_OS_PROCESS_EXITED) ||
+ (0 != code) )
+ {
+ fprintf (stderr,
+ "Unexpected error running"
+ " `anastasis-dbinit'!\n");
+ ANASTASIS_FAIL ();
+ }
+ GNUNET_OS_process_destroy (dbinit_proc);
+
+
+
+ GNUNET_asprintf (&base_url,
+ "http://localhost:%llu/",
+ port);
+ return base_url;
+}
diff --git a/src/stasis/anastasis_db_plugin.c b/src/stasis/anastasis_db_plugin.c
index 6b2c6e0..8bfd7bd 100644
--- a/src/stasis/anastasis_db_plugin.c
+++ b/src/stasis/anastasis_db_plugin.c
@@ -20,6 +20,7 @@
* @author Sree Harsha Totakura <address@hidden>
*/
#include "platform.h"
+#include <taler/taler_util.h>
#include "anastasis_database_plugin.h"
#include <ltdl.h>
@@ -57,7 +58,7 @@ ANASTASIS_DB_plugin_load (const struct
GNUNET_CONFIGURATION_Handle *cfg)
plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup);
if (NULL != plugin)
plugin->library_name = lib_name;
- else
+ else
GNUNET_free (lib_name);
GNUNET_CONFIGURATION_destroy (cfg_dup);
return plugin;
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 4efc486..6dfa506 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -6,7 +6,6 @@ if USE_COVERAGE
XLIB = -lgcov
endif
-
pkgcfgdir = $(prefix)/share/anastasis/config.d/
pkgcfg_DATA = \
@@ -27,3 +26,16 @@ libanastasisutil_la_LDFLAGS = \
-version-info 0:0:0 \
-export-dynamic -no-undefined
+
+bin_PROGRAMS = \
+ anastasis-dbinit
+
+anastasis_dbinit_SOURCES = \
+ anastasis-dbinit.c
+
+anastasis_dbinit_LDADD = \
+ $(LIBGCRYPT_LIBS) \
+ -lanastasisdb \
+ -lgnunetutil \
+ -ltalerutil \
+ -ltalerpq
diff --git a/src/util/anastasis-dbinit.c b/src/util/anastasis-dbinit.c
new file mode 100644
index 0000000..fc570ec
--- /dev/null
+++ b/src/util/anastasis-dbinit.c
@@ -0,0 +1,113 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014, 2015 GNUnet e.V.
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file util/anastasis-dbinit.c
+ * @brief Create tables for the merchant database.
+ * @author Dennis Neufeld
+ * @author Dominik Meister
+ */
+#include "platform.h"
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis_database_lib.h"
+
+
+/**
+ * Return value from main().
+ */
+static int global_ret;
+
+/**
+ * -r option: do full DB reset
+ */
+static int reset_db;
+
+/**
+ * Main function that will be run.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct ANASTASIS_DatabasePlugin *plugin;
+
+ if (NULL ==
+ (plugin = ANASTASIS_DB_plugin_load (cfg)))
+ {
+ fprintf (stderr,
+ "Failed to initialize database plugin.\n");
+ global_ret = 1;
+ return;
+ }
+ if (reset_db)
+ {
+ (void) plugin->drop_tables (plugin->cls);
+ ANASTASIS_DB_plugin_unload (plugin);
+ plugin = ANASTASIS_DB_plugin_load (cfg);
+ }
+ ANASTASIS_DB_plugin_unload (plugin);
+}
+
+
+/**
+ * The main function of the database initialization tool.
+ * Used to initialize the Anastasis' database.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+
+ GNUNET_GETOPT_option_flag ('r',
+ "reset",
+ "reset database (DANGEROUS: all existing data
is lost!)",
+ &reset_db),
+
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ /* force linker to link against libtalerutil; if we do
+ not do this, the linker may "optimize" libtalerutil
+ away and skip #TALER_OS_init(), which we do need */
+ (void) TALER_project_data_default ();
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_log_setup ("anastasis-dbinit",
+ "INFO",
+ NULL));
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run (argc, argv,
+ "anastasis-dbinit",
+ "Initialize anastasis database",
+ options,
+ &run, NULL))
+ return 1;
+ return global_ret;
+}
+
+
+/* end of anastasis-dbinit.c */
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: Worked on testing the api. Tests not functioning yet,
gnunet <=