diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-09-05 10:03:56 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-09-05 10:04:17 +0200 |
commit | afe455c0b6494ef5518094162f505ee948bc16b4 (patch) | |
tree | 2fe52305d8a7b9cce724f4990c0826c23856691c /src/auditor | |
parent | b7454aadc492688bb5a00c794c7be834a7579bbb (diff) |
more auditor tests
Diffstat (limited to 'src/auditor')
-rw-r--r-- | src/auditor/taler-auditor.c | 59 | ||||
-rw-r--r-- | src/auditor/taler-wire-auditor.c | 6 | ||||
-rwxr-xr-x | src/auditor/test-auditor.sh | 153 |
3 files changed, 171 insertions, 47 deletions
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c index f2bcad6b8..5a621992e 100644 --- a/src/auditor/taler-auditor.c +++ b/src/auditor/taler-auditor.c @@ -2088,7 +2088,7 @@ check_transaction_history_for_deposit (const struct { report_row_inconsistency ("deposits", tl->serial_id, - "h_wire does not match wire"); + "h(wire) does not match wire"); } } amount_with_fee = &tl->details.deposit->amount_with_fee; @@ -2368,21 +2368,17 @@ wire_transfer_information_cb (void *cls, TALER_JSON_merchant_wire_signature_hash (account_details, &hw)) { - wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; report_row_inconsistency ("aggregation", rowid, "failed to compute hash of given wire data"); - return; } - if (0 != - GNUNET_memcmp (&hw, - h_wire)) + else if (0 != + GNUNET_memcmp (&hw, + h_wire)) { - wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; report_row_inconsistency ("aggregation", rowid, "database contains wrong hash code for wire details"); - return; } /* Obtain coin's transaction history */ @@ -2514,16 +2510,7 @@ wire_transfer_information_cb (void *cls, wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; report_row_inconsistency ("aggregation", rowid, - "wire method of aggregate do not match wire transfer"); - } - if (0 != GNUNET_memcmp (h_wire, - &wcc->h_wire)) - { - wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; - report_row_inconsistency ("aggregation", - rowid, - "account details of aggregate do not match account details of wire transfer"); - return; + "target of outgoing wire transfer do not match hash of wire from deposit"); } if (exec_time.abs_value_us != wcc->date.abs_value_us) { @@ -2533,18 +2520,22 @@ wire_transfer_information_cb (void *cls, report_row_inconsistency ("aggregation", rowid, "date given in aggregate does not match wire transfer date"); - return; } /* Add coin's contribution to total aggregate value */ - if (GNUNET_OK != - TALER_amount_add (&wcc->total_deposits, - &wcc->total_deposits, - &coin_value_without_fee)) { - GNUNET_break (0); - wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; - return; + struct TALER_Amount res; + + if (GNUNET_OK != + TALER_amount_add (&res, + &wcc->total_deposits, + &coin_value_without_fee)) + { + GNUNET_break (0); + wcc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + wcc->total_deposits = res; } } @@ -2732,17 +2723,18 @@ check_wire_out_cb GNUNET_free (method); return GNUNET_SYSERR; } - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != wcc.qs) { - /* FIXME: can we provide a more detailed error report? */ - report_row_inconsistency ("wire_out", - rowid, - "audit of associated transactions failed"); - GNUNET_free (method); - return GNUNET_OK; + /* Note: detailed information was already logged + in #wire_transfer_information_cb, so here we + only log for debugging */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Inconsitency for wire_out %llu (WTID %s) detected\n", + (unsigned long long) rowid, + TALER_B2S (wtid)); } + /* Subtract aggregation fee from total (if possible) */ { const struct TALER_Amount *wire_fee; @@ -5276,6 +5268,7 @@ run (void *cls, /* Tested in test-auditor.sh #4/#5/#6/#7/#13 */ "total_bad_sig_loss", TALER_JSON_from_amount (&total_bad_sig_loss), + /* Tested in test-auditor.sh #14/#15 */ "row_inconsistencies", report_row_inconsistencies, "denomination_key_validity_withdraw_inconsistencies", diff --git a/src/auditor/taler-wire-auditor.c b/src/auditor/taler-wire-auditor.c index c53527f16..e1af48883 100644 --- a/src/auditor/taler-wire-auditor.c +++ b/src/auditor/taler-wire-auditor.c @@ -404,12 +404,12 @@ do_shutdown (void *cls) " s:o, s:o, s:o, s:o, s:o," " s:o, s:o, s:o, s:o }", /* blocks of 5 */ - /* Tested in test-auditor.sh #11 */ + /* Tested in test-auditor.sh #11, #15 */ "wire_out_amount_inconsistencies", report_wire_out_inconsistencies, "total_wire_out_delta_plus", TALER_JSON_from_amount (&total_bad_amount_out_plus), - /* Tested in test-auditor.sh #11 */ + /* Tested in test-auditor.sh #11, #15 */ "total_wire_out_delta_minus", TALER_JSON_from_amount (&total_bad_amount_out_minus), /* Tested in test-auditor.sh #2 */ @@ -430,7 +430,7 @@ do_shutdown (void *cls) TALER_JSON_from_amount (&total_missattribution_in), "row_inconsistencies", report_row_inconsistencies, - /* Tested in test-auditor.sh #10 */ + /* Tested in test-auditor.sh #10/#17 */ "row_minor_inconsistencies", report_row_minor_inconsistencies, /* block */ diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index c038910c4..5058fea92 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -9,7 +9,7 @@ set -eu # Set of numbers for all the testcases. # When adding new tests, increase the last number: -ALL_TESTS=`seq 0 13` +ALL_TESTS=`seq 0 17` # $TESTS determines which tests we should run. # This construction is used to make it easy to @@ -788,29 +788,31 @@ echo PASS # cannot easily undo aggregator, hence full reload echo -n "Reloading database ..." -# full_reload +full_reload echo "DONE" } -# FIXME: Test where h_wire in the deposit table is wrong -test_99() { -echo "===========99: deposit wire hash wrong=================" +# Test where h_wire in the deposit table is wrong +function test_15() { +echo "===========15: deposit wire hash wrong=================" # Modify h_wire hash, so it is inconsistent with 'wire' echo "UPDATE deposits SET h_wire='\x973e52d193a357940be9ef2939c19b0575ee1101f52188c3c01d9005b7d755c397e92624f09cfa709104b3b65605fe5130c90d7e1b7ee30f8fc570f39c16b853' WHERE deposit_serial_id=1" | psql -Aqt $DB # The auditor checks h_wire consistency only for # coins where the wire transfer has happened, hence # run aggregator first to get this test to work. -# -# FIXME: current test database has transfers still -# in the *distant* future, test cannot yet work. -# patch up once DB was re-generated! run_audit aggregator -# FIXME: check for the respective inconsistency in the report! +echo -n "Testing inconsistency detection... " +TABLE=`jq -r .row_inconsistencies[0].table < test-audit.json` +if test "x$TABLE" != "xaggregation" -a "x$TABLE" != "xdeposits" +then + exit_fail "Reported table wrong: $TABLE" +fi +echo PASS # cannot easily undo aggregator, hence full reload echo -n "Reloading database ..." @@ -819,13 +821,142 @@ echo "DONE" } +# Test where wired amount (wire out) is wrong +function test_16() { +echo "===========16: incorrect wire_out amount=================" + +# First, we need to run the aggregator so we even +# have a wire_out to modify. +pre_audit aggregator + +# Modify wire amount, such that it is inconsistent with 'aggregation' +# (exchange account is #2, so the logic below should select the outgoing +# wire transfer): +OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE debit_account_id=2 ORDER BY id LIMIT 1;" | psql $DB -Aqt` +OLD_AMOUNT=`echo "SELECT amount FROM app_banktransaction WHERE id='${OLD_ID}';" | psql $DB -Aqt` +NEW_AMOUNT="TESTKUDOS:50" +echo "UPDATE app_banktransaction SET amount='${NEW_AMOUNT}' WHERE id='${OLD_ID}';" | psql -Aqt $DB + +audit_only + +echo -n "Testing inconsistency detection... " + +AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-wire-audit.json` +if test "x$AMOUNT" != "x$OLD_AMOUNT" +then + exit_fail "Reported justified amount wrong: $AMOUNT" +fi +AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json` +if test "x$AMOUNT" != "x$NEW_AMOUNT" +then + exit_fail "Reported wired amount wrong: $AMOUNT" +fi +TOTAL_AMOUNT=`jq -r .total_wire_out_delta_minus < test-wire-audit.json` +if test "x$TOTAL_AMOUNT" != "xTESTKUDOS:0" +then + exit_fail "Reported total wired amount minus wrong: $TOTAL_AMOUNT" +fi +TOTAL_AMOUNT=`jq -r .total_wire_out_delta_plus < test-wire-audit.json` +if test "x$TOTAL_AMOUNT" = "xTESTKUDOS:0" +then + exit_fail "Reported total wired amount plus wrong: $TOTAL_AMOUNT" +fi +echo PASS + +echo "Second modification: wire nothing" +NEW_AMOUNT="TESTKUDOS:0" +echo "UPDATE app_banktransaction SET amount='${NEW_AMOUNT}' WHERE id='${OLD_ID}';" | psql -Aqt $DB + +audit_only + +echo -n "Testing inconsistency detection... " + +AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-wire-audit.json` +if test "x$AMOUNT" != "x$OLD_AMOUNT" +then + exit_fail "Reported justified amount wrong: $AMOUNT" +fi +AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-wire-audit.json` +if test "x$AMOUNT" != "x$NEW_AMOUNT" +then + exit_fail "Reported wired amount wrong: $AMOUNT" +fi +TOTAL_AMOUNT=`jq -r .total_wire_out_delta_minus < test-wire-audit.json` +if test "x$TOTAL_AMOUNT" != "x$OLD_AMOUNT" +then + exit_fail "Reported total wired amount minus wrong: $TOTAL_AMOUNT (wanted $OLD_AMOUNT)" +fi +TOTAL_AMOUNT=`jq -r .total_wire_out_delta_plus < test-wire-audit.json` +if test "x$TOTAL_AMOUNT" != "xTESTKUDOS:0" +then + exit_fail "Reported total wired amount plus wrong: $TOTAL_AMOUNT" +fi +echo PASS + +post_audit + + +# Undo +echo "UPDATE app_banktransaction SET amount='${OLD_AMOUNT}' WHERE id='${OLD_ID}';" | psql -Aqt $DB +} + + + + +# Test where wire-out timestamp is wrong +function test_17() { +echo "===========17: incorrect wire_out timestamp=================" + +# First, we need to run the aggregator so we even +# have a wire_out to modify. +pre_audit aggregator + +# Modify wire amount, such that it is inconsistent with 'aggregation' +# (exchange account is #2, so the logic below should select the outgoing +# wire transfer): +OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE debit_account_id=2 ORDER BY id LIMIT 1;" | psql $DB -Aqt` +OLD_DATE=`echo "SELECT date FROM app_banktransaction WHERE id='${OLD_ID}';" | psql $DB -Aqt` +# Note: need - interval '1h' as "NOW()" may otherwise be exactly what is already in the DB +# (due to rounding, if this machine is fast...) +echo "UPDATE app_banktransaction SET date=NOW()- interval '1 hour' WHERE id='${OLD_ID}';" | psql -Aqt $DB + +audit_only +post_audit + +echo -n "Testing inconsistency detection... " +TABLE=`jq -r .row_minor_inconsistencies[0].table < test-wire-audit.json` +if test "x$TABLE" != "xwire_out" +then + exit_fail "Reported table wrong: $TABLE" +fi +DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-wire-audit.json` +if test "x$DIAG" != "xexecution date missmatch" +then + exit_fail "Reported diagnostic wrong: $DIAG" +fi +echo PASS + +# Undo +echo "UPDATE app_banktransaction SET date='${OLD_DATE}' WHERE id='${OLD_ID}';" | psql -Aqt $DB +} + + # ************************************************** -# Add more tests here! :-) +# FIXME: Add more tests here! :-) +# Specifically: +# - emergencies (detection) +# - revocation (payback, accepting +# of coins despite denomination revocation) +# - refunds +# - reserve closure (or lack thereof) +# - arithmetic problems +# - wire.row_inconsistencies (i.e. duplicate wire offset) # ************************************************** + # *************** Main logic starts here ************** # ####### Setup globals ###### |