aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-09-16 00:16:43 +0200
committerChristian Grothoff <christian@grothoff.org>2024-09-16 00:16:43 +0200
commitbaf074e2fa244dd5b2b9dd6c2938ea7ff8235312 (patch)
treed1c306fef286dabf327f48eb2aefd5be644dca0a
parent21b069168adbf913ef9dd7e7a6208d9595d1b8d4 (diff)
fix test-4 and associated auditor bugs
-rw-r--r--src/auditor/taler-auditor-httpd_bad-sig-losses-get.c9
-rw-r--r--src/auditor/taler-auditor-httpd_closure-lags-get.c68
-rwxr-xr-xsrc/auditor/test-auditor.sh97
-rw-r--r--src/auditordb/pg_get_auditor_closure_lags.c14
-rw-r--r--src/auditordb/pg_get_bad_sig_losses.c18
-rw-r--r--src/include/taler_auditordb_plugin.h7
6 files changed, 97 insertions, 116 deletions
diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c
index 826dce435..58a8eb733 100644
--- a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c
+++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c
@@ -45,12 +45,16 @@ add_bad_sig_losses (
obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_uint64 ("row_id",
serial_id),
+ GNUNET_JSON_pack_uint64 ("problem_row_id",
+ dc->problem_row_id),
GNUNET_JSON_pack_string ("operation",
dc->operation),
TALER_JSON_pack_amount ("loss",
&dc->loss),
GNUNET_JSON_pack_data_auto ("operation_specific_pub",
- &dc->operation_specific_pub)
+ &dc->operation_specific_pub),
+ GNUNET_JSON_pack_bool ("suppressed",
+ dc->suppressed)
);
GNUNET_break (0 ==
json_array_append_new (list,
@@ -93,12 +97,10 @@ TAH_BAD_SIG_LOSSES_handler_get (
TALER_MHD_parse_request_snumber (connection,
"limit",
&limit);
-
if (limit < 0)
offset = INT64_MAX;
else
offset = 0;
-
TALER_MHD_parse_request_number (connection,
"offset",
&offset);
@@ -130,7 +132,6 @@ TAH_BAD_SIG_LOSSES_handler_get (
op,
&add_bad_sig_losses,
ja);
-
if (0 > qs)
{
GNUNET_break (0);
diff --git a/src/auditor/taler-auditor-httpd_closure-lags-get.c b/src/auditor/taler-auditor-httpd_closure-lags-get.c
index e02c515bd..2d9016437 100644
--- a/src/auditor/taler-auditor-httpd_closure-lags-get.c
+++ b/src/auditor/taler-auditor-httpd_closure-lags-get.c
@@ -13,8 +13,6 @@
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/>
*/
-
-
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
@@ -26,30 +24,38 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_closure-lags-get.h"
+
/**
-* Add closure-lags to the list.
-*
-* @param[in,out] cls a `json_t *` array to extend
-* @param serial_id location of the @a dc in the database
-* @param dc struct of inconsistencies
-* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
-*/
+ * Add closure-lags to the list.
+ *
+ * @param[in,out] cls a `json_t *` array to extend
+ * @param serial_id location of the @a dc in the database
+ * @param dc struct of inconsistencies
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
static enum GNUNET_GenericReturnValue
process_closure_lags (
void *cls,
- uint64_t serial_id,
const struct TALER_AUDITORDB_ClosureLags *dc)
{
json_t *list = cls;
json_t *obj;
obj = GNUNET_JSON_PACK (
-
- TALER_JSON_pack_amount ("amount", &dc->amount),
- TALER_JSON_pack_time_abs_human ("deadline", dc->deadline),
- GNUNET_JSON_pack_data_auto ("wtid", &dc->wtid),
- GNUNET_JSON_pack_string ("account", dc->account)
-
+ GNUNET_JSON_pack_uint64 ("row_id",
+ dc->row_id),
+ GNUNET_JSON_pack_uint64 ("problem_row_id",
+ dc->problem_row_id),
+ TALER_JSON_pack_amount ("amount",
+ &dc->amount),
+ TALER_JSON_pack_time_abs_human ("deadline",
+ dc->deadline),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ &dc->wtid),
+ GNUNET_JSON_pack_string ("account",
+ dc->account),
+ GNUNET_JSON_pack_bool ("suppressed",
+ dc->suppressed)
);
GNUNET_break (0 ==
json_array_append_new (list,
@@ -71,6 +77,9 @@ TAH_CLOSURE_LAGS_handler_get (
{
json_t *ja;
enum GNUNET_DB_QueryStatus qs;
+ int64_t limit = -20;
+ uint64_t offset;
+ bool return_suppressed = false;
if (GNUNET_SYSERR ==
TAH_plugin->preflight (TAH_plugin->cls))
@@ -81,34 +90,28 @@ TAH_CLOSURE_LAGS_handler_get (
TALER_EC_GENERIC_DB_SETUP_FAILED,
NULL);
}
- ja = json_array ();
- GNUNET_break (NULL != ja);
-
- int64_t limit = -20;
- uint64_t offset;
-
TALER_MHD_parse_request_snumber (connection,
"limit",
&limit);
-
if (limit < 0)
offset = INT64_MAX;
else
offset = 0;
-
TALER_MHD_parse_request_number (connection,
"offset",
&offset);
-
- bool return_suppressed = false;
- const char *ret_s = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "return_suppressed");
- if (ret_s != NULL && strcmp (ret_s, "true") == 0)
{
- return_suppressed = true;
+ const char *ret_s
+ = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "return_suppressed");
+ if (ret_s != NULL && strcmp (ret_s, "true") == 0)
+ {
+ return_suppressed = true;
+ }
}
-
+ ja = json_array ();
+ GNUNET_break (NULL != ja);
qs = TAH_plugin->get_auditor_closure_lags (
TAH_plugin->cls,
limit,
@@ -116,7 +119,6 @@ TAH_CLOSURE_LAGS_handler_get (
return_suppressed,
&process_closure_lags,
ja);
-
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh
index b5ece1fcf..2ab318587 100755
--- a/src/auditor/test-auditor.sh
+++ b/src/auditor/test-auditor.sh
@@ -806,68 +806,45 @@ function test_3() {
# lower than what exchange claims to have received.
# FIXME: test-4 not implemented
function test_4() {
-# TODO : may need to be restructured, as db seems to have done
echo "===========4: deposit wire target wrong================="
-# # Original target bank account was 43, changing to 44
-# # TODO: ask grothoff check if I correctly chose table coin_deposit
-#
-# SERIALE=$(echo "SELECT coin_deposit_serial_id FROM exchange.coin_deposits WHERE (amount_with_fee).val=3 ORDER BY coin_deposit_serial_id LIMIT 1;" | psql "$DB" -Aqt)
-#
-# #SERIAL=$(echo "SELECT coin_deposit_serial_id FROM exchange.coin_deposits WHERE (amount_with_fee).val=3 AND (amount_with_fee).frac=0 ORDER BY coin_deposit_serial_id LIMIT 1;" | psql "$DB" -Aqt)
-# echo $SERIALE
-# OLD_WIRE_ID=$(echo "SELECT coin_sig FROM exchange.coin_deposits WHERE coin_deposit_serial_id=${SERIALE};" | psql "$DB" -Aqt)
-# #OLD_WIRE_ID=$(echo "SELECT wire_target_h_payto FROM exchange.deposits WHERE deposit_serial_id=${SERIAL};" | psql "$DB" -Aqt)
-## shellcheck disable=SC2028
-# echo "INSERT INTO exchange.wire_targets (payto_uri, wire_target_h_payto) VALUES ('payto://x-taler-bank/localhost/testuser-xxlargtp', '\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b');" \
-# | psql "$DB" \
-# -Aqt \
-# > /dev/null
+
+ SERIALE=$(echo "SELECT coin_deposit_serial_id FROM exchange.coin_deposits WHERE (amount_with_fee).val=3 ORDER BY coin_deposit_serial_id LIMIT 1;" | psql "$DB" -Aqt)
+ OLD_COIN_SIG=$(echo "SELECT coin_sig FROM exchange.coin_deposits WHERE coin_deposit_serial_id=${SERIALE};" | psql "$DB" -Aqt)
+ echo -n "Manipulating row ${SERIALE} ..."
+# shellcheck disable=SC2028
+ echo "INSERT INTO exchange.wire_targets (payto_uri, wire_target_h_payto) VALUES ('payto://x-taler-bank/localhost/testuser-xxlargtp', '\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b');" \
+ | psql -Aqt "$DB"
## shellcheck disable=SC2028
-# #echo "UPDATE exchange.deposits SET wire_target_h_payto='\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b' WHERE deposit_serial_id=${SERIAL}" \
-# # | psql -Aqt "$DB"
-# echo "UPDATE exchange.coin_deposits SET coin_sig='\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b' WHERE coin_deposit_serial_id=${SERIALE}" \
-# | psql -Aqt "$DB"
-#
-# run_audit
-# check_auditor_running
-#
-# echo -n "Testing inconsistency detection... "
-#
-# call_endpoint "bad-sig-losses"
-# jq -e .bad_sig_losses[0] < "${MY_TMP_DIR}/bad-sig-losses.json" > /dev/null || exit_fail "Bad signature not detected"
-#
-# ROW=$(jq -e .bad_sig_losses[0].row < "${MY_TMP_DIR}/bad-sig-losses.json")
-# if [ $ROW != "${SERIALE}" ]
-# then
-# exit_fail "Row wrong, got $ROW"
-# fi
-#
-# LOSS=$(jq -r .bad_sig_losses[0].loss < "${MY_TMP_DIR}/bad-sig-losses.json")
-# if [ $LOSS != '"TESTKUDOS:3"' ]
-# then
-# exit_fail "Wrong deposit bad signature loss, got $LOSS"
-# fi
-#
-# OP=$(jq -r .bad_sig_losses[0].operation < "${MY_TMP_DIR}/bad-sig-losses.json")
-# if [ $OP != "deposit" ]
-# then
-# exit_fail "Wrong operation, got $OP"
-# fi
-#
-# #LOSS=$(jq -r .irregular_loss < test-audit-coins.json")
-# #if [ "$LOSS" != "TESTKUDOS:3" ]
-# #then
-# # exit_fail "Wrong total bad sig loss, got $LOSS"
-# #fi
-#
-# echo PASS
-# # Undo:
-# #echo "UPDATE exchange.deposits SET wire_target_h_payto='$OLD_WIRE_ID' WHERE deposit_serial_id=${SERIAL}" | psql -Aqt "$DB"
-# echo "UPDATE exchange.deposits SET coin_sig='$OLD_WIRE_ID' WHERE coin_deposit_serial_id=${SERIALE}" | psql -Aqt "$DB"
-#
-# stop_auditor_httpd
-# full_reload
-# cleanup
+ echo "UPDATE exchange.coin_deposits SET coin_sig='\x0f29b2ebf3cd1ecbb3e1f2a7888872058fc870c28c0065d4a7d457f2fee9eb5ec376958fc52460c8c540e583be10cf67491a6651a62c1bda68051c62dbe9130c' WHERE coin_deposit_serial_id=${SERIALE}" \
+ | psql -Aqt "$DB"
+ echo " DONE"
+
+ run_audit
+ check_auditor_running
+
+ echo -n "Testing inconsistency detection... "
+ check_report \
+ "bad-sig-losses" \
+ "problem_row_id" "${SERIALE}"
+ echo -n "Testing loss report... "
+ check_report \
+ "bad-sig-losses" \
+ "loss" "TESTKUDOS:3.02"
+ echo -n "Testing loss operation attribution... "
+ check_report \
+ "bad-sig-losses" \
+ "operation" "deposit"
+ echo -n "Testing total coin_irregular_loss balance update... "
+ check_balance \
+ "coin_irregular_loss" \
+ "TESTKUDOS:3.02" \
+ "wrong total coin_irregular_loss"
+ # Undo:
+ echo "UPDATE exchange.coin_deposits SET coin_sig='$OLD_COIN_SIG' WHERE coin_deposit_serial_id=${SERIALE}" | psql -Aqt "$DB"
+
+ stop_auditor_httpd
+ full_reload
+ cleanup
}
diff --git a/src/auditordb/pg_get_auditor_closure_lags.c b/src/auditordb/pg_get_auditor_closure_lags.c
index 443c7f9cf..de2b98dd6 100644
--- a/src/auditordb/pg_get_auditor_closure_lags.c
+++ b/src/auditordb/pg_get_auditor_closure_lags.c
@@ -13,7 +13,6 @@
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/>
*/
-
#include "platform.h"
#include "taler_error_codes.h"
#include "taler_dbevents.h"
@@ -66,11 +65,10 @@ closure_lags_cb (void *cls,
for (unsigned int i = 0; i < num_results; i++)
{
- uint64_t serial_id;
struct TALER_AUDITORDB_ClosureLags dc;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("row_id",
- &serial_id),
+ &dc.row_id),
GNUNET_PQ_result_spec_uint64 ("problem_row_id",
&dc.problem_row_id),
TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
@@ -81,6 +79,8 @@ closure_lags_cb (void *cls,
&dc.wtid),
GNUNET_PQ_result_spec_string ("account",
&dc.account),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
GNUNET_PQ_result_spec_end
};
enum GNUNET_GenericReturnValue rval;
@@ -96,7 +96,6 @@ closure_lags_cb (void *cls,
}
dcc->qs = i + 1;
rval = dcc->cb (dcc->cb_cls,
- serial_id,
&dc);
GNUNET_PQ_cleanup_result (rs);
if (GNUNET_OK != rval)
@@ -138,9 +137,10 @@ TAH_PG_get_auditor_closure_lags (
",deadline"
",wtid"
",account"
+ ",suppressed"
" FROM auditor_closure_lags"
" WHERE (row_id < $1)"
- " AND ($2 OR suppressed is false)"
+ " AND ($2 OR NOT suppressed)"
" ORDER BY row_id DESC"
" LIMIT $3"
);
@@ -153,9 +153,10 @@ TAH_PG_get_auditor_closure_lags (
",deadline"
",wtid"
",account"
+ ",suppressed"
" FROM auditor_closure_lags"
" WHERE (row_id > $1)"
- " AND ($2 OR suppressed is false)"
+ " AND ($2 OR NOT suppressed)"
" ORDER BY row_id ASC"
" LIMIT $3"
);
@@ -167,7 +168,6 @@ TAH_PG_get_auditor_closure_lags (
params,
&closure_lags_cb,
&dcc);
-
if (qs > 0)
return dcc.qs;
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
diff --git a/src/auditordb/pg_get_bad_sig_losses.c b/src/auditordb/pg_get_bad_sig_losses.c
index 4691df84d..f28bedc60 100644
--- a/src/auditordb/pg_get_bad_sig_losses.c
+++ b/src/auditordb/pg_get_bad_sig_losses.c
@@ -62,22 +62,23 @@ bad_sig_losses_cb (void *cls,
{
struct BadSigLossesContext *dcc = cls;
struct PostgresClosure *pg = dcc->pg;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "---found badsiglosses...\n");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "---num_results: %u\n", num_results);
for (unsigned int i = 0; i < num_results; i++)
{
- uint64_t serial_id;
struct TALER_AUDITORDB_BadSigLosses dc;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("row_id",
- &serial_id),
+ &dc.row_id),
+ GNUNET_PQ_result_spec_uint64 ("problem_row_id",
+ &dc.problem_row_id),
GNUNET_PQ_result_spec_string ("operation",
&dc.operation),
TALER_PQ_RESULT_SPEC_AMOUNT ("loss",
&dc.loss),
GNUNET_PQ_result_spec_auto_from_type ("operation_specific_pub",
&dc.operation_specific_pub),
+ GNUNET_PQ_result_spec_bool ("suppressed",
+ &dc.suppressed),
GNUNET_PQ_result_spec_end
};
enum GNUNET_GenericReturnValue rval;
@@ -93,7 +94,6 @@ bad_sig_losses_cb (void *cls,
}
dcc->qs = i + 1;
rval = dcc->cb (dcc->cb_cls,
- serial_id,
&dc);
GNUNET_PQ_cleanup_result (rs);
if (GNUNET_OK != rval)
@@ -138,12 +138,14 @@ TAH_PG_get_bad_sig_losses (
"auditor_bad_sig_losses_get_desc",
"SELECT"
" row_id"
+ ",problem_row_id"
",operation"
",loss"
",operation_specific_pub"
+ ",suppressed"
" FROM auditor_bad_sig_losses"
" WHERE (row_id < $1)"
- " AND ($2 OR suppressed IS FALSE)"
+ " AND ($2 OR NOT suppressed)"
" AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)"
" AND ($5::TEXT IS NULL OR operation = $5)"
" ORDER BY row_id DESC"
@@ -153,12 +155,14 @@ TAH_PG_get_bad_sig_losses (
"auditor_bad_sig_losses_get_asc",
"SELECT"
" row_id"
+ ",problem_row_id"
",operation"
",loss"
",operation_specific_pub"
+ ",suppressed"
" FROM auditor_bad_sig_losses"
" WHERE (row_id > $1)"
- " AND ($2 OR suppressed IS FALSE)"
+ " AND ($2 OR NOT suppressed)"
" AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)"
" AND ($5::TEXT IS NULL OR operation = $5)"
" ORDER BY row_id ASC"
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index b71ba3d13..572ae07cc 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -266,6 +266,7 @@ struct TALER_AUDITORDB_BadSigLosses
char *operation;
struct TALER_Amount loss;
struct GNUNET_CRYPTO_EddsaPublicKey operation_specific_pub;
+ bool suppressed;
};
/**
@@ -279,7 +280,7 @@ struct TALER_AUDITORDB_ClosureLags
struct GNUNET_TIME_Absolute deadline;
struct TALER_WireTransferIdentifierRawP wtid;
char *account;
-
+ bool suppressed;
};
/**
@@ -456,14 +457,12 @@ typedef enum GNUNET_GenericReturnValue
* the auditor's database.
*
* @param cls closure
- * @param serial_id location of the @a dc in the database
* @param dc the structure itself
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
*/
typedef enum GNUNET_GenericReturnValue
(*TALER_AUDITORDB_BadSigLossesCallback)(
void *cls,
- uint64_t serial_id,
const struct TALER_AUDITORDB_BadSigLosses *dc);
/**
@@ -471,14 +470,12 @@ typedef enum GNUNET_GenericReturnValue
* the auditor's database.
*
* @param cls closure
- * @param serial_id location of the @a dc in the database
* @param dc the structure itself
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
*/
typedef enum GNUNET_GenericReturnValue
(*TALER_AUDITORDB_ClosureLagsCallback)(
void *cls,
- uint64_t serial_id,
const struct TALER_AUDITORDB_ClosureLags *dc);
/**