aboutsummaryrefslogtreecommitdiff
path: root/src/auditor/test-auditor.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/auditor/test-auditor.sh')
-rwxr-xr-xsrc/auditor/test-auditor.sh84
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 41function pre_audit () {
42# before auditor (to trigger pending wire transfers).
43function 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
62function 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
73function 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).
89function 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
81full_reload() 98full_reload()
82{ 99{
@@ -87,7 +104,7 @@ full_reload()
87} 104}
88 105
89 106
90test_0() { 107function test_0() {
91 108
92echo "===========0: normal run with aggregator===========" 109echo "===========0: normal run with aggregator==========="
93run_audit aggregator 110run_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!
156test_1() { 173function test_1() {
157 174
158echo "===========1: normal run===========" 175echo "===========1: normal run==========="
159run_audit 176run_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
216test_2() { 233function test_2() {
217 234
218echo "===========2: reserves_in inconsitency===========" 235echo "===========2: reserves_in inconsitency==========="
219echo "UPDATE reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" | psql -Aqt $DB 236echo "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.
260test_3() { 277function test_3() {
261 278
262echo "===========3: reserves_in inconsitency===========" 279echo "===========3: reserves_in inconsitency==========="
263echo "UPDATE reserves_in SET credit_val=15 WHERE reserve_in_serial_id=1" | psql -Aqt $DB 280echo "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.
323test_4() { 340function test_4() {
324 341
325echo "===========4: deposit wire target wrong=================" 342echo "===========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)
365test_5() { 382function test_5() {
366echo "===========5: deposit contract hash wrong=================" 383echo "===========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'
368OLD_H=`echo 'SELECT h_contract_terms FROM deposits WHERE deposit_serial_id=1;' | psql $DB -Aqt` 385OLD_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)
405test_6() { 422function test_6() {
406echo "===========6: known_coins signature wrong=================" 423echo "===========6: known_coins signature wrong================="
407# Modify denom_sig, so it is wrong 424# Modify denom_sig, so it is wrong
408OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -Aqt` 425OLD_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
446test_7() { 463function test_7() {
447echo "===========7: reserves_out signature wrong=================" 464echo "===========7: reserves_out signature wrong================="
448# Modify reserve_sig, so it is bogus 465# Modify reserve_sig, so it is bogus
449HBE=`echo 'SELECT h_blind_ev FROM reserves_out LIMIT 1;' | psql $DB -Aqt` 466HBE=`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!
497test_8() { 514function test_8() {
498 515
499echo "===========8: wire-transfer-subject disagreement===========" 516echo "===========8: wire-transfer-subject disagreement==========="
500OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` 517OLD_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!
567test_9() { 584function test_9() {
568 585
569echo "===========9: wire-origin disagreement===========" 586echo "===========9: wire-origin disagreement==========="
570OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` 587OLD_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!
596test_10() { 613function test_10() {
597 614
598echo "===========10: wire-timestamp disagreement===========" 615echo "===========10: wire-timestamp disagreement==========="
599OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` 616OLD_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.
625test_11() { 642function test_11() {
626 643
627echo "===========11: spurious outgoing transfer ===========" 644echo "===========11: spurious outgoing transfer ==========="
628OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10.00' ORDER BY id LIMIT 1;" | psql $DB -Aqt` 645OLD_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.
675test_12() { 692function test_12() {
676 693
677echo "===========12: incomplete refresh ===========" 694echo "===========12: incomplete refresh ==========="
678OLD_ACC=`echo "DELETE FROM refresh_revealed_coins;" | psql $DB -Aqt` 695OLD_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.
706test_13() { 723function test_13() {
707 724
708echo "===========13: wrong melt signature ===========" 725echo "===========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
746test_98() { 763function test_14() {
764
765echo "===========14: wire-fee disagreement==========="
747 766
748echo "===========11: wire-fee disagreement==========="
749echo "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.
754run_audit aggregator 771pre_audit aggregator
772echo "UPDATE wire_fee SET wire_fee_frac=100;" | psql -Aqt $DB
773audit_only
774post_audit
755 775
756# FIXME: needs new DB where aggregator does stuff! 776echo -n "Testing inconsistency detection... "
757# FIXME: check report generation! 777TABLE=`jq -r .row_inconsistencies[0].table < test-audit.json`
778if test "x$TABLE" != "xwire-fee"
779then
780 exit_fail "Reported table wrong: $TABLE"
781fi
782DIAG=`jq -r .row_inconsistencies[0].diagnostic < test-audit.json`
783if test "x$DIAG" != "xwire fee signature invalid at given time"
784then
785 exit_fail "Reported diagnostic wrong: $DIAG"
786fi
787echo PASS
758 788
759# cannot easily undo aggregator, hence full reload 789# cannot easily undo aggregator, hence full reload
760echo -n "Reloading database ..." 790echo -n "Reloading database ..."
761full_reload 791# full_reload
762echo "DONE" 792echo "DONE"
763 793
764} 794}