Refactored unit tests
This commit is contained in:
parent
aaccc14e76
commit
4980788afc
20 changed files with 876 additions and 769 deletions
|
@ -1,190 +1,104 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
# exp_internal 1
|
||||
# log_file -noappend ~/expect.log
|
||||
|
||||
set timeout 30
|
||||
|
||||
proc bold {} {
|
||||
return [exec tput bold]
|
||||
}
|
||||
proc red {} {
|
||||
return [exec tput setaf 1]
|
||||
}
|
||||
proc green {} {
|
||||
return [exec tput setaf 2]
|
||||
}
|
||||
proc normal {} {
|
||||
return [exec tput sgr0]
|
||||
}
|
||||
source ./test.exp
|
||||
|
||||
set bip39_mnemonic "online pipe enough dutch decorate want moment scheme rigid enlist blast boat purse sick chalk shop brush all return betray jacket salon abandon retire"
|
||||
set electrum_mnemonic "month pet slice know amused leave now vague palm guess cattle element cross truly auto put among craft repeat van sample nephew sad family"
|
||||
set failed "[bold][red]Failed[normal]"
|
||||
set ok "[bold][green]OK[normal]"
|
||||
|
||||
puts "[bold]Should create BIP39 mnemonic[normal]"
|
||||
test_label "Should create BIP39 mnemonic"
|
||||
|
||||
spawn qr-backup.sh --create-bip39-mnemonic
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Creating BIP39 mnemonic…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {(([a-z]+ ?){24})} {
|
||||
exit 0
|
||||
-re {([a-z]+ ?){24}} {
|
||||
test_ok true
|
||||
}
|
||||
}
|
||||
|
||||
puts "[bold]Should validate valid BIP39 mnemonic[normal]"
|
||||
test_label "Should validate valid BIP39 mnemonic"
|
||||
|
||||
spawn qr-backup.sh --validate-bip39-mnemonic
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
sleep 0.1
|
||||
send "$bip39_mnemonic\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
test_send "$bip39_mnemonic\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type bip39_mnemonic and press enter, then ctrl\+d \(again\)} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
test_send "$bip39_mnemonic\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
puts $ok
|
||||
exit 0
|
||||
test_ok true
|
||||
}
|
||||
}
|
||||
|
||||
puts "[bold]Should fail to validate invalid BIP39 mnemonic[normal]"
|
||||
test_label "Should fail to validate invalid BIP39 mnemonic"
|
||||
|
||||
spawn qr-backup.sh --validate-bip39-mnemonic
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
sleep 0.1
|
||||
send "$electrum_mnemonic\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
test_send "$electrum_mnemonic\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type electrum_mnemonic and press enter, then ctrl\+d \(again\)} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
test_send "$electrum_mnemonic\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Invalid BIP39 mnemonic} {
|
||||
puts $ok
|
||||
exit 0
|
||||
test_ok true
|
||||
}
|
||||
}
|
||||
|
||||
interact
|
||||
|
|
99
how-to-create-encrypted-paper-backup/tests/clone.exp
Normal file
99
how-to-create-encrypted-paper-backup/tests/clone.exp
Normal file
|
@ -0,0 +1,99 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
source ./test.exp
|
||||
|
||||
set secret "foo\nbar"
|
||||
set passphrase "asdasd"
|
||||
|
||||
test_label "Should clone backup"
|
||||
|
||||
source ./tests/helpers/backup.exp
|
||||
|
||||
spawn qr-clone.sh --qr-restore-options "--images $short_hash.jpg"
|
||||
|
||||
expect {
|
||||
-re {Restoring…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Backing up…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set new_short_hash $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
if { "$new_short_hash" == "$short_hash" } {
|
||||
test_failed
|
||||
}
|
||||
|
||||
set short_hash "$new_short_hash"
|
||||
|
||||
source ./tests/helpers/restore.exp
|
||||
|
||||
regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
||||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
test_failed
|
||||
} else {
|
||||
test_ok
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
source ./test.exp
|
||||
|
||||
set secret "foo\nbar"
|
||||
set passphrase "asdasd"
|
||||
|
||||
test_label "Should convert default backup to 2-of-3 Shamir Secret Sharing"
|
||||
|
||||
source ./tests/helpers/backup.exp
|
||||
|
||||
spawn qr-clone.sh --qr-restore-options "--images $short_hash.jpg" --qr-backup-options "--shamir-secret-sharing --number-of-shares 3 --share-threshold 2"
|
||||
|
||||
expect {
|
||||
-re {Restoring…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Backing up…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Encrypting secret share 1 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_1 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Encrypting secret share 2 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_2 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Encrypting secret share 3 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_3 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
source ./tests/helpers/shamir-2-of-3-restore.exp
|
||||
|
||||
regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
||||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
test_failed
|
||||
} else {
|
||||
test_ok
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
source ./test.exp
|
||||
|
||||
set secret "foo\nbar"
|
||||
set passphrase "asdasd"
|
||||
|
||||
test_label "Should convert 2-of-3 Shamir Secret Sharing backup to default"
|
||||
|
||||
source ./tests/helpers/shamir-2-of-3-backup.exp
|
||||
|
||||
spawn qr-clone.sh --qr-restore-options "--images \"$short_hash_1.jpg,$short_hash_2.jpg\" --shamir-secret-sharing --share-threshold 2"
|
||||
|
||||
expect {
|
||||
-re {Restoring…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Backing up…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
source ./tests/helpers/restore.exp
|
||||
|
||||
regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
||||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
test_failed
|
||||
} else {
|
||||
test_ok
|
||||
}
|
|
@ -1,200 +1,191 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
# exp_internal 1
|
||||
# log_file -noappend ~/expect.log
|
||||
|
||||
set timeout 30
|
||||
|
||||
proc bold {} {
|
||||
return [exec tput bold]
|
||||
}
|
||||
proc red {} {
|
||||
return [exec tput setaf 1]
|
||||
}
|
||||
proc green {} {
|
||||
return [exec tput setaf 2]
|
||||
}
|
||||
proc normal {} {
|
||||
return [exec tput sgr0]
|
||||
}
|
||||
source ./test.exp
|
||||
|
||||
set secret "foo\nbar"
|
||||
set passphrase "asdasd"
|
||||
set failed "[bold][red]Failed[normal]"
|
||||
set ok "[bold][green]OK[normal]"
|
||||
|
||||
puts "[bold]Should backup secret[normal]"
|
||||
test_label "Should fails to backup secret using secrets that do not match"
|
||||
|
||||
spawn qr-backup.sh
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
sleep 0.1
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
test_send "foo\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Secrets do not match} {
|
||||
test_ok
|
||||
}
|
||||
}
|
||||
|
||||
test_label "Should fails to backup secret using passphrases that do not match"
|
||||
|
||||
spawn qr-backup.sh
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
test_send "foo\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Passphrases do not match} {
|
||||
test_ok
|
||||
}
|
||||
}
|
||||
|
||||
test_label "Should format USB flash drive and backup secret showing passphrase"
|
||||
|
||||
spawn qr-backup.sh
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {mkfs\.fat 4\.1 \(2017-01-24\)}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
test_send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
$passphrase
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
-re {Done} {
|
||||
test_ok
|
||||
}
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
puts "[bold]Should restore secret[normal]"
|
||||
test_label "Should restore secret"
|
||||
|
||||
spawn qr-restore.sh --images $short_hash.jpg
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
sleep 0.1
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
test_send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
|
||||
set restored_secret $expect_out(1,string)
|
||||
}
|
||||
|
@ -204,11 +195,7 @@ regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
|||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
puts $failed
|
||||
exit 1
|
||||
test_failed
|
||||
} else {
|
||||
puts $ok
|
||||
exit 0
|
||||
test_ok
|
||||
}
|
||||
|
||||
interact
|
||||
|
|
69
how-to-create-encrypted-paper-backup/tests/duplicate.exp
Normal file
69
how-to-create-encrypted-paper-backup/tests/duplicate.exp
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
source ./test.exp
|
||||
|
||||
set secret "foo\nbar"
|
||||
set passphrase "asdasd"
|
||||
|
||||
test_label "Should duplicate backup"
|
||||
|
||||
source ./tests/helpers/backup.exp
|
||||
|
||||
spawn qr-clone.sh --duplicate --qr-restore-options "--images $short_hash.jpg"
|
||||
|
||||
expect {
|
||||
-re {Restoring…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Backing up…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set new_short_hash $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
if { "$new_short_hash" != "$short_hash" } {
|
||||
test_failed
|
||||
}
|
||||
|
||||
set short_hash "$new_short_hash"
|
||||
|
||||
source ./tests/helpers/restore.exp
|
||||
|
||||
regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
||||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
test_failed
|
||||
} else {
|
||||
test_ok
|
||||
}
|
|
@ -1,68 +1,29 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
# exp_internal 1
|
||||
# log_file -noappend ~/expect.log
|
||||
source ./test.exp
|
||||
|
||||
set timeout 30
|
||||
|
||||
proc bold {} {
|
||||
return [exec tput bold]
|
||||
}
|
||||
proc red {} {
|
||||
return [exec tput setaf 1]
|
||||
}
|
||||
proc green {} {
|
||||
return [exec tput setaf 2]
|
||||
}
|
||||
proc normal {} {
|
||||
return [exec tput sgr0]
|
||||
}
|
||||
|
||||
set passphrase "asdasd"
|
||||
set failed "[bold][red]Failed[normal]"
|
||||
set ok "[bold][green]OK[normal]"
|
||||
|
||||
puts "[bold]Should create Electrum mnemonic[normal]"
|
||||
test_label "Should create Electrum mnemonic"
|
||||
|
||||
spawn qr-backup.sh --create-electrum-mnemonic
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Creating Electrum mnemonic…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {(([a-z]+ ?){24})} {
|
||||
puts $ok
|
||||
exit 0
|
||||
-re {([a-z]+ ?){24}} {
|
||||
test_ok true
|
||||
}
|
||||
}
|
||||
|
||||
interact
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
spawn qr-backup.sh
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
spawn qr-restore.sh --images $short_hash.jpg
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
test_send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
|
||||
set restored_secret $expect_out(1,string)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
spawn qr-backup.sh --shamir-secret-sharing --number-of-shares 3 --share-threshold 2
|
||||
|
||||
expect {
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Encrypting secret share 1 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_1 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Encrypting secret share 2 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_2 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Encrypting secret share 3 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_3 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg" --shamir-secret-sharing --share-threshold 2
|
||||
|
||||
expect {
|
||||
-re {\[sudo\] password for pi:} {
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Please type passphrase and press enter} {
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
test_send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
|
||||
set restored_secret $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
-re {Done}
|
||||
}
|
25
how-to-create-encrypted-paper-backup/tests/shamir-2-of-3.exp
Normal file
25
how-to-create-encrypted-paper-backup/tests/shamir-2-of-3.exp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
source ./test.exp
|
||||
|
||||
set passphrase "asdasd"
|
||||
set secret "foo\nbar"
|
||||
|
||||
test_label "Should backup secret using 2-of-3 Shamir Secret Sharing"
|
||||
|
||||
source ./tests/helpers/shamir-2-of-3-backup.exp
|
||||
|
||||
test_ok
|
||||
|
||||
test_label "Should restore secret using 2-of-3 Shamir Secret Sharing"
|
||||
|
||||
source ./tests/helpers/shamir-2-of-3-restore.exp
|
||||
|
||||
regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
||||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
test_failed
|
||||
} else {
|
||||
test_ok
|
||||
}
|
|
@ -1,324 +1,167 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
# exp_internal 1
|
||||
# log_file -noappend ~/expect.log
|
||||
|
||||
set timeout 30
|
||||
|
||||
proc bold {} {
|
||||
return [exec tput bold]
|
||||
}
|
||||
proc red {} {
|
||||
return [exec tput setaf 1]
|
||||
}
|
||||
proc green {} {
|
||||
return [exec tput setaf 2]
|
||||
}
|
||||
proc normal {} {
|
||||
return [exec tput sgr0]
|
||||
}
|
||||
source ./test.exp
|
||||
|
||||
set passphrase "asdasd"
|
||||
set secret "foo\nbar"
|
||||
set failed "[bold][red]Failed[normal]"
|
||||
set ok "[bold][green]OK[normal]"
|
||||
|
||||
puts "[bold]Should backup secret using Shamir Secret Sharing[normal]"
|
||||
test_label "Should backup secret using Shamir Secret Sharing"
|
||||
|
||||
spawn qr-backup.sh --shamir-secret-sharing
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
sleep 0.1
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {mkfs\.fat 4\.1 \(2017-01-24\)}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
test_send "$secret\r"
|
||||
test_send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
$passphrase
|
||||
-re {Encrypting secret share 1 of 5…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 1 of 5…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_1 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 2 of 5…}
|
||||
-re {Encrypting secret share 2 of 5…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_2 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 3 of 5…}
|
||||
-re {Encrypting secret share 3 of 5…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_3 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 4 of 5…}
|
||||
-re {Encrypting secret share 4 of 5…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_4 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 5 of 5…}
|
||||
-re {Encrypting secret share 5 of 5…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_5 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
test_send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
-re {Done} {
|
||||
test_ok
|
||||
}
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
puts "[bold]Should restore secret using Shamir Secret Sharing[normal]"
|
||||
test_label "Should restore secret using Shamir Secret Sharing"
|
||||
|
||||
spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg,$short_hash_5.jpg" --shamir-secret-sharing
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
sleep 0.1
|
||||
send "$env(password)\r"
|
||||
test_send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
test_send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
test_send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
|
||||
set restored_secret $expect_out(1,string)
|
||||
}
|
||||
|
@ -328,11 +171,7 @@ regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
|||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
puts $failed
|
||||
exit 1
|
||||
test_failed
|
||||
} else {
|
||||
puts $ok
|
||||
exit 0
|
||||
test_ok
|
||||
}
|
||||
|
||||
interact
|
||||
|
|
|
@ -1,280 +0,0 @@
|
|||
#!/usr/bin/expect
|
||||
|
||||
# exp_internal 1
|
||||
# log_file -noappend ~/expect.log
|
||||
|
||||
set timeout 30
|
||||
|
||||
proc bold {} {
|
||||
return [exec tput bold]
|
||||
}
|
||||
proc red {} {
|
||||
return [exec tput setaf 1]
|
||||
}
|
||||
proc green {} {
|
||||
return [exec tput setaf 2]
|
||||
}
|
||||
proc normal {} {
|
||||
return [exec tput sgr0]
|
||||
}
|
||||
|
||||
set passphrase "asdasd"
|
||||
set secret "foo\nbar"
|
||||
set failed "[bold][red]Failed[normal]"
|
||||
set ok "[bold][green]OK[normal]"
|
||||
|
||||
puts "[bold]Should backup secret using 2 of 3 Shamir Secret Sharing[normal]"
|
||||
|
||||
spawn qr-backup.sh --shamir-secret-sharing --number-of-shares 3 --share-threshold 2
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Format USB flash drive \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
sleep 0.1
|
||||
send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {mkfs\.fat 4\.1 \(2017-01-24\)}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
|
||||
sleep 0.1
|
||||
send "$secret\r"
|
||||
sleep 0.1
|
||||
send "\x04"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter \(again\)} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show passphrase \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
$passphrase
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 1 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_1 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 2 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_2 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
{Encrypting secret share 3 of 3…}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
|
||||
set short_hash_3 $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show SHA512 hash as QR code \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "n\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Done}
|
||||
}
|
||||
|
||||
puts "[bold]Should restore secret using 2 of 3 Shamir Secret Sharing[normal]"
|
||||
|
||||
spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg" --shamir-secret-sharing --share-threshold 2
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {\[sudo\] password for pi:} {
|
||||
sleep 0.1
|
||||
send "$env(password)\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Please type passphrase and press enter} {
|
||||
sleep 0.1
|
||||
send "$passphrase\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Show secret \(y or n\)\?} {
|
||||
sleep 0.1
|
||||
send "y\r"
|
||||
}
|
||||
}
|
||||
|
||||
expect {
|
||||
default {
|
||||
puts $failed
|
||||
exit 1
|
||||
}
|
||||
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
|
||||
set restored_secret $expect_out(1,string)
|
||||
}
|
||||
}
|
||||
|
||||
regsub -all {(\e\(B)?\e\[[0-9]*?m} $restored_secret {} restored_secret
|
||||
regsub -all {\r} $restored_secret {} restored_secret
|
||||
|
||||
if { "$restored_secret" != "$secret" } {
|
||||
puts $failed
|
||||
exit 1
|
||||
} else {
|
||||
puts $ok
|
||||
exit 0
|
||||
}
|
||||
|
||||
interact
|
Loading…
Add table
Add a link
Reference in a new issue