commit 9e348baffc2a7953014e53e8e3afc9598825922f
parent d2e65f33ac744786faddab9e01709b048c1f72c5
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 8 Dec 2024 23:03:58 +0100
more fixes on tests
Diffstat:
8 files changed, 56 insertions(+), 26 deletions(-)
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -1318,10 +1318,11 @@ set_token_family (struct OrderContext *oc,
struct GNUNET_TIME_Timestamp min_valid_after;
struct GNUNET_TIME_Timestamp max_valid_after;
- if (GNUNET_OK != get_rounded_time_interval (precision,
- *valid_after,
- &min_valid_after,
- &max_valid_after))
+ if (GNUNET_OK !=
+ get_rounded_time_interval (precision,
+ *valid_after,
+ &min_valid_after,
+ &max_valid_after))
{
GNUNET_break (0);
reply_with_error (oc,
@@ -1347,10 +1348,10 @@ set_token_family (struct OrderContext *oc,
{
if (GNUNET_TIME_timestamp_cmp (family->keys[i].valid_after,
>=,
- min_valid_after)
- && GNUNET_TIME_timestamp_cmp (family->keys[i].valid_after,
- <,
- max_valid_after))
+ min_valid_after) &&
+ GNUNET_TIME_timestamp_cmp (family->keys[i].valid_after,
+ <,
+ max_valid_after))
{
/* The token family and a matching key is already added. */
*valid_after = family->keys[i].valid_after;
@@ -1383,7 +1384,8 @@ set_token_family (struct OrderContext *oc,
break;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Token family slug unknown\n");
+ "Token family slug %s unknown\n",
+ slug);
http_status = MHD_HTTP_NOT_FOUND;
ec = TALER_EC_MERCHANT_PRIVATE_POST_ORDERS_TOKEN_FAMILY_SLUG_UNKNOWN;
break;
@@ -1505,7 +1507,12 @@ set_token_family (struct OrderContext *oc,
.private_key = priv,
};
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Storing new key for slug %s of %s\n",
+ slug,
+ oc->hc->instance->settings.id);
iqs = TMH_db->insert_token_family_key (TMH_db->cls,
+ oc->hc->instance->settings.id,
slug,
&token_pub,
&token_priv,
diff --git a/src/backenddb/merchant-0002.sql b/src/backenddb/merchant-0002.sql
@@ -76,7 +76,7 @@ CREATE INDEX IF NOT EXISTS merchant_deposits_by_deposit_confirmation_serial
CREATE TABLE IF NOT EXISTS merchant_token_families
(token_family_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
,merchant_serial BIGINT NOT NULL REFERENCES merchant_instances (merchant_serial) ON DELETE CASCADE
- ,slug TEXT NOT NULL UNIQUE
+ ,slug TEXT NOT NULL UNIQUE -- Constraint fixed in merchant-0013!
,name TEXT NOT NULL
,description TEXT
,description_i18n BYTEA NOT NULL
diff --git a/src/backenddb/merchant-0013.sql b/src/backenddb/merchant-0013.sql
@@ -27,6 +27,13 @@ SELECT _v.register_patch('merchant-0013', NULL, NULL);
SET search_path TO merchant;
+-- Slug was incorrectly set to be globally unique, is only
+-- unique per instance!
+ALTER TABLE merchant_token_families
+ DROP CONSTRAINT merchant_token_families_slug_key,
+ ADD UNIQUE (merchant_serial,slug);
+
+
-- Function to replace placeholders in a string with a given value
CREATE OR REPLACE FUNCTION replace_placeholder(
template TEXT,
diff --git a/src/backenddb/pg_insert_token_family_key.c b/src/backenddb/pg_insert_token_family_key.c
@@ -27,13 +27,16 @@
#include "pg_insert_token_family_key.h"
#include "pg_helper.h"
+
enum GNUNET_DB_QueryStatus
-TMH_PG_insert_token_family_key (void *cls,
- const char *token_family_slug,
- const struct TALER_TokenIssuePublicKeyP *pub,
- const struct TALER_TokenIssuePrivateKeyP *priv,
- const struct GNUNET_TIME_Timestamp valid_after,
- const struct GNUNET_TIME_Timestamp valid_before)
+TMH_PG_insert_token_family_key (
+ void *cls,
+ const char *merchant_id,
+ const char *token_family_slug,
+ const struct TALER_TokenIssuePublicKeyP *pub,
+ const struct TALER_TokenIssuePrivateKeyP *priv,
+ const struct GNUNET_TIME_Timestamp valid_after,
+ const struct GNUNET_TIME_Timestamp valid_before)
{
struct PostgresClosure *pg = cls;
const char *cipher = NULL;
@@ -53,6 +56,7 @@ TMH_PG_insert_token_family_key (void *cls,
&pub_hash);
break;
case GNUNET_CRYPTO_BSA_INVALID:
+ GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
}
GNUNET_assert (pub->public_key->cipher ==
@@ -77,7 +81,11 @@ TMH_PG_insert_token_family_key (void *cls,
",cipher)"
" SELECT token_family_serial, $2, $3, $4, $5, $6, $7"
" FROM merchant_token_families"
- " WHERE slug = $1");
+ " WHERE (slug = $1)"
+ " AND merchant_serial="
+ " (SELECT merchant_serial"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$8)");
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (token_family_slug),
@@ -87,6 +95,7 @@ TMH_PG_insert_token_family_key (void *cls,
GNUNET_PQ_query_param_timestamp (&valid_after),
GNUNET_PQ_query_param_timestamp (&valid_before),
GNUNET_PQ_query_param_string (cipher),
+ GNUNET_PQ_query_param_string (merchant_id),
GNUNET_PQ_query_param_end
};
diff --git a/src/backenddb/pg_insert_token_family_key.h b/src/backenddb/pg_insert_token_family_key.h
@@ -27,7 +27,10 @@
/**
+ * Insert new key pair for a token family.
+ *
* @param cls closure
+ * @param merchant_id instance name
* @param token_family_slug slug of the token family to insert the key for
* @param pub public key to insert
* @param priv private key to insert
@@ -36,11 +39,13 @@
* @return database result code
*/
enum GNUNET_DB_QueryStatus
-TMH_PG_insert_token_family_key (void *cls,
- const char *token_family_slug,
- const struct TALER_TokenIssuePublicKeyP *pub,
- const struct TALER_TokenIssuePrivateKeyP *priv,
- const struct GNUNET_TIME_Timestamp valid_after,
- const struct GNUNET_TIME_Timestamp valid_before);
+TMH_PG_insert_token_family_key (
+ void *cls,
+ const char *merchant_id,
+ const char *token_family_slug,
+ const struct TALER_TokenIssuePublicKeyP *pub,
+ const struct TALER_TokenIssuePrivateKeyP *priv,
+ const struct GNUNET_TIME_Timestamp valid_after,
+ const struct GNUNET_TIME_Timestamp valid_before);
#endif
diff --git a/src/backenddb/pg_lookup_token_family_key.c b/src/backenddb/pg_lookup_token_family_key.c
@@ -55,8 +55,8 @@ TMH_PG_lookup_token_family_key (
",pub"
",priv"
",cipher"
- ",merchant_token_family_keys.valid_after as key_valid_after"
- ",merchant_token_family_keys.valid_before as key_valid_before"
+ ",merchant_token_family_keys.valid_after AS key_valid_after"
+ ",merchant_token_family_keys.valid_before AS key_valid_before"
",slug"
",name"
",description"
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
@@ -3759,6 +3759,7 @@ struct TALER_MERCHANTDB_Plugin
* Insert details a key pair for a token family.
*
* @param cls closure
+ * @param merchant_id instance name
* @param token_family_slug slug of token family to insert the key pair for
* @param pub token family public key
* @param priv token family private key
@@ -3769,6 +3770,7 @@ struct TALER_MERCHANTDB_Plugin
enum GNUNET_DB_QueryStatus
(*insert_token_family_key)(
void *cls,
+ const char *merchant_id,
const char *token_family_slug,
const struct TALER_TokenIssuePublicKeyP *pub,
const struct TALER_TokenIssuePrivateKeyP *priv,
diff --git a/src/testing/test_merchant_instance_auth.sh b/src/testing/test_merchant_instance_auth.sh
@@ -71,7 +71,7 @@ unset SETUP_PID
setup -c test_template.conf \
-ef \
-u "exchange-account-2" \
- -m "merchant-exchange-default"
+ -r "merchant-exchange-default"
NEW_SECRET=secret-token:different_value