aboutsummaryrefslogtreecommitdiff
path: root/src/backenddb/test_merchantdb.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-09-01 14:27:48 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-09-01 14:27:48 +0200
commit35dcd4514a93ba0f5353ecd1194fc9b515f2aad4 (patch)
tree399d8f8fbebf5e8ac383fc318b7be08901279a31 /src/backenddb/test_merchantdb.c
parent858e3047b8b595ab693e16ce0bbe0b8983b072ed (diff)
new CRUD APIs for OTP devices and merchant accounts (fixes #7929, #7824), one minor test is still failing...
Diffstat (limited to 'src/backenddb/test_merchantdb.c')
-rw-r--r--src/backenddb/test_merchantdb.c78
1 files changed, 43 insertions, 35 deletions
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 58470786..214bd5f8 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -259,6 +259,19 @@ check_accounts_equal (const struct TALER_MERCHANTDB_AccountDetails *a,
}
+// FIXME: use this!
+void
+lookup_accounts_cb (void *cls,
+ const struct TALER_MERCHANTDB_AccountDetails *account)
+{
+ const struct TALER_MERCHANTDB_AccountDetails *want = cls;
+
+ GNUNET_assert (0 ==
+ check_accounts_equal (want,
+ account));
+}
+
+
/**
* Called after testing 'lookup_instances'.
*
@@ -267,54 +280,33 @@ check_accounts_equal (const struct TALER_MERCHANTDB_AccountDetails *a,
* @param merchant_priv private key of the instance, NULL if not available
* @param is general instance settings
* @param ias instance authentication settings
- * @param accounts_length length of the @a accounts array
- * @param accounts list of accounts of the merchant
*/
static void
lookup_instances_cb (void *cls,
const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct TALER_MerchantPrivateKeyP *merchant_priv,
const struct TALER_MERCHANTDB_InstanceSettings *is,
- const struct TALER_MERCHANTDB_InstanceAuthSettings *ias,
- unsigned int accounts_length,
- const struct TALER_MERCHANTDB_AccountDetails accounts[])
+ const struct TALER_MERCHANTDB_InstanceAuthSettings *ias)
{
struct TestLookupInstances_Closure *cmp = cls;
+
if (NULL == cmp)
return;
cmp->results_length += 1;
/* Look through the closure and test each instance for equality */
for (unsigned int i = 0; cmp->instances_to_cmp_length > i; ++i)
{
- int accounts_matching[GNUNET_NZL (accounts_length)];
- bool accounts_match = true;
if (0 != check_instances_equal (cmp->instances_to_cmp[i].instance,
is))
continue;
- if (accounts_length != cmp->instances_to_cmp[i].accounts_length)
- continue;
- /* Count matches between the accounts found and accounts in cls */
- for (unsigned int j = 0; accounts_length > j; ++j)
- accounts_matching[j] = 0;
- for (unsigned int j = 0; accounts_length > j; ++j)
- {
- for (unsigned int k = 0; accounts_length > k; ++k)
- {
- if (0 == check_accounts_equal (&cmp->instances_to_cmp[i].accounts[j],
- &accounts[k]))
- accounts_matching[j] += 1;
- }
- }
- /* Each account from the lookup should match with one and only one from cls */
- for (unsigned int j = 0; accounts_length > j; ++j)
- if (1 != accounts_matching[j])
- accounts_match = false;
- if (true == accounts_match)
- cmp->results_matching[i] += 1;
+ cmp->results_matching[i] += 1;
}
}
+
+
+
/**
* Tests @e insert_instance.
*
@@ -6866,8 +6858,7 @@ make_template (const char *id,
{
template->id = id;
template->template.template_description = "This is a test template";
- template->template.pos_key = NULL;
- template->template.pos_algorithm = 0;
+ template->template.otp_id = NULL;
template->template.template_contract = json_array ();
GNUNET_assert (NULL != template->template.template_contract);
}
@@ -6881,7 +6872,7 @@ make_template (const char *id,
static void
free_template_data (struct TemplateData *template)
{
- GNUNET_free (template->template.pos_key);
+ GNUNET_free (template->template.otp_id);
json_decref (template->template.template_contract);
}
@@ -6899,9 +6890,10 @@ check_templates_equal (const struct TALER_MERCHANTDB_TemplateDetails *a,
{
if ((0 != strcmp (a->template_description,
b->template_description)) ||
- ( (NULL == a->pos_key) && (NULL != b->pos_key)) ||
- ( (NULL != a->pos_key) && (NULL == b->pos_key)) ||
- ( (NULL != a->pos_key) && (0 != strcmp (a->pos_key, b->pos_key))) ||
+ ( (NULL == a->otp_id) && (NULL != b->otp_id)) ||
+ ( (NULL != a->otp_id) && (NULL == b->otp_id)) ||
+ ( (NULL != a->otp_id) && (0 != strcmp (a->otp_id,
+ b->otp_id))) ||
(1 != json_equal (a->template_contract,
b->template_contract)))
return 1;
@@ -6967,6 +6959,7 @@ test_lookup_template (const struct InstanceData *instance,
const struct TemplateData *template)
{
struct TALER_MERCHANTDB_TemplateDetails lookup_result;
+
if (0 > plugin->lookup_template (plugin->cls,
instance->instance.id,
template->id,
@@ -7212,8 +7205,23 @@ run_test_templates (struct TestTemplates_Closure *cls)
/* Test template update */
cls->templates[0].template.template_description =
"This is a test template that has been updated!";
- GNUNET_free (cls->templates[0].template.pos_key);
- cls->templates[0].template.pos_key = GNUNET_strdup ("pos_key");
+ GNUNET_free (cls->templates[0].template.otp_id);
+ cls->templates[0].template.otp_id = GNUNET_strdup ("otp_id");
+ {
+ /* ensure OTP device exists */
+ struct TALER_MERCHANTDB_OtpDeviceDetails td = {
+ .otp_description = "my otp",
+ .otp_key = "my key",
+ .otp_algorithm = 1,
+ .otp_ctr = 42
+ };
+ GNUNET_assert (0 <=
+ plugin->insert_otp (plugin->cls,
+ cls->instance.instance.id,
+ "otp_id",
+ &td));
+ }
+
GNUNET_assert (0 ==
json_array_append_new (
cls->templates[0].template.template_contract,