summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/taler-merchant-httpd_tip-authorize.c43
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c3
-rw-r--r--src/lib/merchant_api_tip_authorize.c6
-rw-r--r--src/lib/reserve_dtip.priv1
-rw-r--r--src/lib/test_merchant_api.c47
-rw-r--r--src/lib/test_merchant_api.conf12
6 files changed, 99 insertions, 13 deletions
diff --git a/src/backend/taler-merchant-httpd_tip-authorize.c b/src/backend/taler-merchant-httpd_tip-authorize.c
index ad33b37b..e46a4a3d 100644
--- a/src/backend/taler-merchant-httpd_tip-authorize.c
+++ b/src/backend/taler-merchant-httpd_tip-authorize.c
@@ -123,23 +123,30 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh,
res = TMH_PARSE_json_data (connection,
root,
spec);
- json_decref (root);
if (GNUNET_YES != res)
{
GNUNET_break_op (0);
+ json_decref (root);
return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
}
mi = TMH_lookup_instance (instance);
if (NULL == mi)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Instance `%s' not configured\n",
+ instance);
+ json_decref (root);
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_TIP_AUTHORIZE_INSTANCE_UNKNOWN,
"unknown instance");
+ }
if (NULL == mi->tip_exchange)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Instance `%s' not configured for tipping\n",
instance);
+ json_decref (root);
return TMH_RESPONSE_reply_not_found (connection,
TALER_EC_TIP_AUTHORIZE_INSTANCE_DOES_NOT_TIP,
"exchange for tipping not configured for the instance");
@@ -152,10 +159,31 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh,
&tip_id);
if (TALER_EC_NONE != ec)
{
- /* FIXME: differenciate better between ec's */
- return TMH_RESPONSE_reply_internal_error (connection,
- ec,
- "Database error approving tip");
+ unsigned int rc;
+
+ switch (ec)
+ {
+ case TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS:
+ rc = MHD_HTTP_PRECONDITION_FAILED;
+ break;
+ case TALER_EC_TIP_AUTHORIZE_RESERVE_EXPIRED:
+ rc = MHD_HTTP_PRECONDITION_FAILED;
+ break;
+ case TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN:
+ rc = MHD_HTTP_NOT_FOUND;
+ break;
+ case TALER_EC_TIP_AUTHORIZE_RESERVE_NOT_ENABLED:
+ rc = MHD_HTTP_NOT_FOUND;
+ break;
+ default:
+ rc = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ break;
+ }
+ json_decref (root);
+ return TMH_RESPONSE_reply_rc (connection,
+ rc,
+ ec,
+ "Database error approving tip");
}
if (0)
{
@@ -163,17 +191,18 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh,
"Insufficient funds to authorize tip over `%s' at instance `%s'\n",
TALER_amount2s (&amount),
instance);
+ json_decref (root);
return TMH_RESPONSE_reply_rc (connection,
MHD_HTTP_PRECONDITION_FAILED,
TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS,
"Insufficient funds for tip");
}
-
+ json_decref (root);
return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:o, s:o, s:s}",
"tip_id", GNUNET_JSON_from_data_auto (&tip_id),
- "tip_expiration", GNUNET_JSON_from_time_abs (expiration),
+ "expiration", GNUNET_JSON_from_time_abs (expiration),
"exchange_uri", mi->tip_exchange);
}
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 92287c4c..e9111cab 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -2804,7 +2804,7 @@ postgres_authorize_tip (void *cls,
/* reserve unknown */
postgres_rollback (pg);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- return TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN;
+ return TALER_EC_TIP_AUTHORIZE_RESERVE_NOT_ENABLED;
return (GNUNET_DB_STATUS_HARD_ERROR == qs)
? TALER_EC_TIP_AUTHORIZE_DB_HARD_ERROR
: TALER_EC_TIP_AUTHORIZE_DB_SOFT_ERROR;
@@ -2824,7 +2824,6 @@ postgres_authorize_tip (void *cls,
postgres_rollback (pg);
return TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS;
}
-
/* Update reserve balance */
{
struct GNUNET_PQ_QueryParam params[] = {
diff --git a/src/lib/merchant_api_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c
index e422197d..c2590b2b 100644
--- a/src/lib/merchant_api_tip_authorize.c
+++ b/src/lib/merchant_api_tip_authorize.c
@@ -139,6 +139,12 @@ handle_tip_authorize_finished (void *cls,
response_code = 0;
}
break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Well-defined status code, pass on to application! */
+ break;
+ case MHD_HTTP_PRECONDITION_FAILED:
+ /* Well-defined status code, pass on to application! */
+ break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
diff --git a/src/lib/reserve_dtip.priv b/src/lib/reserve_dtip.priv
new file mode 100644
index 00000000..d7fae398
--- /dev/null
+++ b/src/lib/reserve_dtip.priv
@@ -0,0 +1 @@
+A?*K4K31b'uyD;ȃC \ No newline at end of file
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index b0b546e7..5ccc5658 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -2860,8 +2860,10 @@ interpreter_run (void *cls)
&reserve_priv,
sizeof (reserve_priv));
/* Simply picked long enough for the test (we do not test expiration
- behavior for now) */
- expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
+ behavior for now), should be short enough so that the reserve
+ expires before the test is run again, so that we avoid old
+ state messing up fresh runs. */
+ expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
if (NULL == (cmd->details.tip_enable.teo
= TALER_MERCHANT_tip_enable
@@ -3118,6 +3120,47 @@ run (void *cls)
.expected_response_code = MHD_HTTP_OK,
.details.tip_enable.admin_add_incoming_ref = "create-reserve-tip-1",
.details.tip_enable.amount = "EUR:5.01" },
+ { .oc = OC_TIP_AUTHORIZE,
+ .label = "authorize-tip-1",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.tip_authorize.instance = "tip",
+ .details.tip_authorize.justification = "tip 1",
+ .details.tip_authorize.amount = "EUR:5.01" },
+ { .oc = OC_TIP_AUTHORIZE,
+ .label = "authorize-tip-2",
+ .expected_response_code = MHD_HTTP_OK,
+ .details.tip_authorize.instance = "tip",
+ .details.tip_authorize.justification = "tip 2",
+ .details.tip_authorize.amount = "EUR:5.01" },
+ { .oc = OC_TIP_AUTHORIZE,
+ .label = "authorize-tip-3-insufficient-funds",
+ .expected_response_code = MHD_HTTP_PRECONDITION_FAILED,
+ .details.tip_authorize.instance = "tip",
+ .details.tip_authorize.justification = "tip 3",
+ .details.tip_authorize.amount = "EUR:5.01",
+ .details.tip_authorize.expected_ec = TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS },
+ { .oc = OC_TIP_AUTHORIZE,
+ .label = "authorize-tip-4-unknown-instance",
+ .expected_response_code = MHD_HTTP_NOT_FOUND,
+ .details.tip_authorize.instance = "unknown",
+ .details.tip_authorize.justification = "tip 4",
+ .details.tip_authorize.amount = "EUR:5.01",
+ .details.tip_authorize.expected_ec = TALER_EC_TIP_AUTHORIZE_INSTANCE_UNKNOWN },
+ { .oc = OC_TIP_AUTHORIZE,
+ .label = "authorize-tip-5-notip-instance",
+ .expected_response_code = MHD_HTTP_NOT_FOUND,
+ .details.tip_authorize.instance = "default",
+ .details.tip_authorize.justification = "tip 5",
+ .details.tip_authorize.amount = "EUR:5.01",
+ .details.tip_authorize.expected_ec = TALER_EC_TIP_AUTHORIZE_INSTANCE_DOES_NOT_TIP },
+ { .oc = OC_TIP_AUTHORIZE,
+ .label = "authorize-tip-6-not-enabled-instance",
+ .expected_response_code = MHD_HTTP_NOT_FOUND,
+ .details.tip_authorize.instance = "dtip",
+ .details.tip_authorize.justification = "tip 6",
+ .details.tip_authorize.amount = "EUR:5.01",
+ .details.tip_authorize.expected_ec = TALER_EC_TIP_AUTHORIZE_RESERVE_NOT_ENABLED },
+
/* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per
diff --git a/src/lib/test_merchant_api.conf b/src/lib/test_merchant_api.conf
index 9767a376..91325e9f 100644
--- a/src/lib/test_merchant_api.conf
+++ b/src/lib/test_merchant_api.conf
@@ -33,7 +33,7 @@ WIREFORMAT = test
# during the tests. 'default' instance should explicitly be given.
# The instance "token" X must match the corresponding substring in
# section like X-wireformat and merchant-instance-X
-INSTANCES = tor default tip
+INSTANCES = tor default tip dtip
# Default choice for maximum wire fee.
DEFAULT_MAX_WIRE_FEE = EUR:0.10
@@ -84,15 +84,23 @@ KEYFILE = tor_merchant.priv
[merchant-instance-tip]
KEYFILE = reserve_tip.priv
-TIP_EXCHANGE = http://127.0.0.1:8081/
+TIP_EXCHANGE = http://localhost:8081/
TIP_RESERVE_PRIV = RKEJM3J3K8D02V6WFHWY14WM2RKFVBW35ZJ0FHWTEJDPN0T7CPYG
+[merchant-instance-dtip]
+KEYFILE = reserve_dtip.priv
+TIP_EXCHANGE = http://localhost:8081/
+TIP_RESERVE_PRIV = ENK9E0GYJ5EJEEC0QN3GY7KJRMNXW3B2SSWQDNJ3F1CEMFGC0970
+
[merchant-instance-wireformat-tor]
TEST_RESPONSE_FILE = ${TALER_CONFIG_HOME}/merchant/wire/test.json
[merchant-instance-wireformat-tip]
TEST_RESPONSE_FILE = ${TALER_CONFIG_HOME}/merchant/wire/test.json
+[merchant-instance-wireformat-dtip]
+TEST_RESPONSE_FILE = ${TALER_CONFIG_HOME}/merchant/wire/test.json
+
# Auditors must be in sections "auditor-", the rest of the section
# name could be anything.
[merchant-auditor-ezb]