diff options
Diffstat (limited to 'src/auditor/test-auditor.sh')
-rwxr-xr-x | src/auditor/test-auditor.sh | 84 |
1 files changed, 57 insertions, 27 deletions
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index d7ee79e96..c038910c4 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh | |||
@@ -36,11 +36,9 @@ function exit_fail() { | |||
36 | exit 1 | 36 | exit 1 |
37 | } | 37 | } |
38 | 38 | ||
39 | # Run audit process on current database, including report | 39 | |
40 | # generation. Pass "aggregator" as $1 to run | 40 | # Operations to run before the actual audit |
41 | # $ taler-exchange-aggregator | 41 | function pre_audit () { |
42 | # before auditor (to trigger pending wire transfers). | ||
43 | function run_audit () { | ||
44 | # Launch bank | 42 | # Launch bank |
45 | echo -n "Launching bank " | 43 | echo -n "Launching bank " |
46 | taler-bank-manage -c $CONF serve-http 2>bank.err >bank.log & | 44 | taler-bank-manage -c $CONF serve-http 2>bank.err >bank.log & |
@@ -58,14 +56,21 @@ function run_audit () { | |||
58 | taler-exchange-aggregator -t -c $CONF 2> aggregator.log | 56 | taler-exchange-aggregator -t -c $CONF 2> aggregator.log |
59 | echo " DONE" | 57 | echo " DONE" |
60 | fi | 58 | fi |
59 | } | ||
61 | 60 | ||
61 | # actual audit run | ||
62 | function audit_only () { | ||
62 | # Run the auditor! | 63 | # Run the auditor! |
63 | echo -n "Running audit(s) ..." | 64 | echo -n "Running audit(s) ..." |
64 | taler-auditor -r -c $CONF -m $MASTER_PUB > test-audit.json 2> test-audit.log || exit_fail "auditor failed" | 65 | taler-auditor -r -c $CONF -m $MASTER_PUB > test-audit.json 2> test-audit.log || exit_fail "auditor failed" |
65 | 66 | ||
66 | taler-wire-auditor -r -c $CONF -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed" | 67 | taler-wire-auditor -r -c $CONF -m $MASTER_PUB > test-wire-audit.json 2> test-wire-audit.log || exit_fail "wire auditor failed" |
67 | echo " DONE" | 68 | echo " DONE" |
69 | } | ||
68 | 70 | ||
71 | |||
72 | # Cleanup to run after the auditor | ||
73 | function post_audit () { | ||
69 | kill `jobs -p` || true | 74 | kill `jobs -p` || true |
70 | 75 | ||
71 | echo -n "TeXing ..." | 76 | echo -n "TeXing ..." |
@@ -77,6 +82,18 @@ function run_audit () { | |||
77 | } | 82 | } |
78 | 83 | ||
79 | 84 | ||
85 | # Run audit process on current database, including report | ||
86 | # generation. Pass "aggregator" as $1 to run | ||
87 | # $ taler-exchange-aggregator | ||
88 | # before auditor (to trigger pending wire transfers). | ||
89 | function run_audit () { | ||
90 | pre_audit ${1:-no} | ||
91 | audit_only | ||
92 | post_audit | ||
93 | |||
94 | } | ||
95 | |||
96 | |||
80 | # Do a full reload of the (original) database | 97 | # Do a full reload of the (original) database |
81 | full_reload() | 98 | full_reload() |
82 | { | 99 | { |
@@ -87,7 +104,7 @@ full_reload() | |||
87 | } | 104 | } |
88 | 105 | ||
89 | 106 | ||
90 | test_0() { | 107 | function test_0() { |
91 | 108 | ||
92 | echo "===========0: normal run with aggregator===========" | 109 | echo "===========0: normal run with aggregator===========" |
93 | run_audit aggregator | 110 | run_audit aggregator |
@@ -153,7 +170,7 @@ echo "DONE" | |||
153 | 170 | ||
154 | # Run without aggregator, hence auditor should detect wire | 171 | # Run without aggregator, hence auditor should detect wire |
155 | # transfer lag! | 172 | # transfer lag! |
156 | test_1() { | 173 | function test_1() { |
157 | 174 | ||
158 | echo "===========1: normal run===========" | 175 | echo "===========1: normal run===========" |
159 | run_audit | 176 | run_audit |
@@ -213,7 +230,7 @@ echo "OK" | |||
213 | 230 | ||
214 | 231 | ||
215 | # Change amount of wire transfer reported by exchange | 232 | # Change amount of wire transfer reported by exchange |
216 | test_2() { | 233 | function test_2() { |
217 | 234 | ||
218 | echo "===========2: reserves_in inconsitency===========" | 235 | echo "===========2: reserves_in inconsitency===========" |
219 | echo "UPDATE reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" | psql -Aqt $DB | 236 | echo "UPDATE reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" | psql -Aqt $DB |
@@ -257,7 +274,7 @@ echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql | |||
257 | 274 | ||
258 | # Check for incoming wire transfer amount given being | 275 | # Check for incoming wire transfer amount given being |
259 | # lower than what exchange claims to have received. | 276 | # lower than what exchange claims to have received. |
260 | test_3() { | 277 | function test_3() { |
261 | 278 | ||
262 | echo "===========3: reserves_in inconsitency===========" | 279 | echo "===========3: reserves_in inconsitency===========" |
263 | echo "UPDATE reserves_in SET credit_val=15 WHERE reserve_in_serial_id=1" | psql -Aqt $DB | 280 | echo "UPDATE reserves_in SET credit_val=15 WHERE reserve_in_serial_id=1" | psql -Aqt $DB |
@@ -320,7 +337,7 @@ echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql | |||
320 | 337 | ||
321 | # Check for incoming wire transfer amount given being | 338 | # Check for incoming wire transfer amount given being |
322 | # lower than what exchange claims to have received. | 339 | # lower than what exchange claims to have received. |
323 | test_4() { | 340 | function test_4() { |
324 | 341 | ||
325 | echo "===========4: deposit wire target wrong=================" | 342 | echo "===========4: deposit wire target wrong=================" |
326 | # Original target bank account was 43, changing to 44 | 343 | # Original target bank account was 43, changing to 44 |
@@ -362,7 +379,7 @@ echo "UPDATE deposits SET wire='$OLD_WIRE' WHERE deposit_serial_id=1" | psql -Aq | |||
362 | 379 | ||
363 | # Test where h_contract_terms in the deposit table is wrong | 380 | # Test where h_contract_terms in the deposit table is wrong |
364 | # (=> bad signature) | 381 | # (=> bad signature) |
365 | test_5() { | 382 | function test_5() { |
366 | echo "===========5: deposit contract hash wrong=================" | 383 | echo "===========5: deposit contract hash wrong=================" |
367 | # Modify h_wire hash, so it is inconsistent with 'wire' | 384 | # Modify h_wire hash, so it is inconsistent with 'wire' |
368 | OLD_H=`echo 'SELECT h_contract_terms FROM deposits WHERE deposit_serial_id=1;' | psql $DB -Aqt` | 385 | OLD_H=`echo 'SELECT h_contract_terms FROM deposits WHERE deposit_serial_id=1;' | psql $DB -Aqt` |
@@ -402,7 +419,7 @@ echo "UPDATE deposits SET h_contract_terms='${OLD_H}' WHERE deposit_serial_id=1" | |||
402 | 419 | ||
403 | # Test where denom_sig in known_coins table is wrong | 420 | # Test where denom_sig in known_coins table is wrong |
404 | # (=> bad signature) | 421 | # (=> bad signature) |
405 | test_6() { | 422 | function test_6() { |
406 | echo "===========6: known_coins signature wrong=================" | 423 | echo "===========6: known_coins signature wrong=================" |
407 | # Modify denom_sig, so it is wrong | 424 | # Modify denom_sig, so it is wrong |
408 | OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -Aqt` | 425 | OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -Aqt` |
@@ -443,7 +460,7 @@ echo "UPDATE known_coins SET denom_sig='$OLD_SIG' WHERE coin_pub='$COIN_PUB'" | | |||
443 | 460 | ||
444 | 461 | ||
445 | # Test where h_wire in the deposit table is wrong | 462 | # Test where h_wire in the deposit table is wrong |
446 | test_7() { | 463 | function test_7() { |
447 | echo "===========7: reserves_out signature wrong=================" | 464 | echo "===========7: reserves_out signature wrong=================" |
448 | # Modify reserve_sig, so it is bogus | 465 | # Modify reserve_sig, so it is bogus |
449 | HBE=`echo 'SELECT h_blind_ev FROM reserves_out LIMIT 1;' | psql $DB -Aqt` | 466 | HBE=`echo 'SELECT h_blind_ev FROM reserves_out LIMIT 1;' | psql $DB -Aqt` |
@@ -494,7 +511,7 @@ echo "UPDATE reserves_out SET reserve_sig='$OLD_SIG' WHERE h_blind_ev='$HBE'" | | |||
494 | 511 | ||
495 | 512 | ||
496 | # Test wire transfer subject disagreement! | 513 | # Test wire transfer subject disagreement! |
497 | test_8() { | 514 | function test_8() { |
498 | 515 | ||
499 | echo "===========8: wire-transfer-subject disagreement===========" | 516 | echo "===========8: wire-transfer-subject disagreement===========" |
500 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` | 517 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` |
@@ -564,7 +581,7 @@ echo "UPDATE app_banktransaction SET subject='$OLD_WTID' WHERE id='$OLD_ID';" | | |||
564 | 581 | ||
565 | 582 | ||
566 | # Test wire origin disagreement! | 583 | # Test wire origin disagreement! |
567 | test_9() { | 584 | function test_9() { |
568 | 585 | ||
569 | echo "===========9: wire-origin disagreement===========" | 586 | echo "===========9: wire-origin disagreement===========" |
570 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` | 587 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` |
@@ -593,7 +610,7 @@ echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC;" | psql -Aqt $DB | |||
593 | 610 | ||
594 | 611 | ||
595 | # Test wire_in timestamp disagreement! | 612 | # Test wire_in timestamp disagreement! |
596 | test_10() { | 613 | function test_10() { |
597 | 614 | ||
598 | echo "===========10: wire-timestamp disagreement===========" | 615 | echo "===========10: wire-timestamp disagreement===========" |
599 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` | 616 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` |
@@ -622,7 +639,7 @@ echo "UPDATE app_banktransaction SET date='$OLD_DATE' WHERE id=$OLD_ID;" | psql | |||
622 | 639 | ||
623 | 640 | ||
624 | # Test for extra outgoing wire transfer. | 641 | # Test for extra outgoing wire transfer. |
625 | test_11() { | 642 | function test_11() { |
626 | 643 | ||
627 | echo "===========11: spurious outgoing transfer ===========" | 644 | echo "===========11: spurious outgoing transfer ===========" |
628 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` | 645 | OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` |
@@ -672,7 +689,7 @@ echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id | |||
672 | 689 | ||
673 | 690 | ||
674 | # Test for hanging/pending refresh. | 691 | # Test for hanging/pending refresh. |
675 | test_12() { | 692 | function test_12() { |
676 | 693 | ||
677 | echo "===========12: incomplete refresh ===========" | 694 | echo "===========12: incomplete refresh ===========" |
678 | OLD_ACC=`echo "DELETE FROM refresh_revealed_coins;" | psql $DB -Aqt` | 695 | OLD_ACC=`echo "DELETE FROM refresh_revealed_coins;" | psql $DB -Aqt` |
@@ -703,7 +720,7 @@ echo "DONE" | |||
703 | 720 | ||
704 | 721 | ||
705 | # Test for wrong signature on refresh. | 722 | # Test for wrong signature on refresh. |
706 | test_13() { | 723 | function test_13() { |
707 | 724 | ||
708 | echo "===========13: wrong melt signature ===========" | 725 | echo "===========13: wrong melt signature ===========" |
709 | # Modify denom_sig, so it is wrong | 726 | # Modify denom_sig, so it is wrong |
@@ -742,23 +759,36 @@ echo "DONE" | |||
742 | } | 759 | } |
743 | 760 | ||
744 | 761 | ||
745 | # FIXME: Test for wire fee disagreement | 762 | # Test for wire fee disagreement |
746 | test_98() { | 763 | function test_14() { |
764 | |||
765 | echo "===========14: wire-fee disagreement===========" | ||
747 | 766 | ||
748 | echo "===========11: wire-fee disagreement===========" | ||
749 | echo "UPDATE wire_fee SET wire_fee_frac='100';" | psql -Aqt $DB | ||
750 | 767 | ||
751 | # Wire fees are only checked/generated once there are | 768 | # Wire fees are only checked/generated once there are |
752 | # actual outgoing wire transfers, so we need to run the | 769 | # actual outgoing wire transfers, so we need to run the |
753 | # aggregator here. | 770 | # aggregator here. |
754 | run_audit aggregator | 771 | pre_audit aggregator |
772 | echo "UPDATE wire_fee SET wire_fee_frac=100;" | psql -Aqt $DB | ||
773 | audit_only | ||
774 | post_audit | ||
755 | 775 | ||
756 | # FIXME: needs new DB where aggregator does stuff! | 776 | echo -n "Testing inconsistency detection... " |
757 | # FIXME: check report generation! | 777 | TABLE=`jq -r .row_inconsistencies[0].table < test-audit.json` |
778 | if test "x$TABLE" != "xwire-fee" | ||
779 | then | ||
780 | exit_fail "Reported table wrong: $TABLE" | ||
781 | fi | ||
782 | DIAG=`jq -r .row_inconsistencies[0].diagnostic < test-audit.json` | ||
783 | if test "x$DIAG" != "xwire fee signature invalid at given time" | ||
784 | then | ||
785 | exit_fail "Reported diagnostic wrong: $DIAG" | ||
786 | fi | ||
787 | echo PASS | ||
758 | 788 | ||
759 | # cannot easily undo aggregator, hence full reload | 789 | # cannot easily undo aggregator, hence full reload |
760 | echo -n "Reloading database ..." | 790 | echo -n "Reloading database ..." |
761 | full_reload | 791 | # full_reload |
762 | echo "DONE" | 792 | echo "DONE" |
763 | 793 | ||
764 | } | 794 | } |