mirror of
https://github.com/sunknudsen/privacy-guides.git
synced 2025-02-23 09:13:56 +00:00
Refactored unit tests
This commit is contained in:
parent
aaccc14e76
commit
4980788afc
@ -156,7 +156,7 @@ read_passphrase () {
|
||||
printf "$bold%s$normal\n" "Please type passphrase and press enter (again)"
|
||||
read -rs data_confirmation
|
||||
if [ ! "$data" = "$data_confirmation" ]; then
|
||||
printf "$red%s$normal\n" "Passphrases do not match"
|
||||
printf "$bold$red%s$normal\n" "Passphrases do not match"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB7OOAACgkQH6dnhiu9
|
||||
EwXjPg//VtWqugIVSPKBE2HBTKr4Pp9EDBSuLy1nI/Dq89vxU74BjXovDFN02iLv
|
||||
J7t7vgQ1gk4zfisMdPi199GrgKOVE6Ke1xxHbRWIdWRTBF+7hcNzEm7YCd+HfrMq
|
||||
S1dEMbN+2xxDm9NJJ506d9BPS5GicOY+0yu1BAOonKioIgrBwPCcAhjA6Miws8+/
|
||||
E0XIhNErSwqVOPQcRlRLhhIWIT6iMZgMOLPUpTHna7KfOlmfCcbNzlxHxBPO8OV7
|
||||
4LruoGqDRQAk5h6pXKf95WVaDioUe4SHDvdq0tLjDNqMBZ0Fur9PBCzDcHc3KDaq
|
||||
XwWKldxIWvjTGLD7I2Jz7Y6/vnANoibQpJ20yXTS1KTZiVqRJbZI76NHz+Tm6ZJ1
|
||||
hVMjl+ZUAHrDnCIFxBdirJh62pBPRFvvC/FmbluNUuUQXPNs5E+62LDlkzMwN4XI
|
||||
fmhiFj5karjsIk7TYAXyeOb8dQQXTohfsY0YTUBSAt09Pb0L3Dq4kSVm79gEXaem
|
||||
5WIy4UawC3yj2lA4EaqyVUrA7oldMM7AIUfIo1niKNMPnrjaP9VdHJQR0g4QSMms
|
||||
VnTxcrJPT7t4BkEgvjc43vTEAkVtGqZv32nmT8aLAhy3GERH//ZDqFe3wvqw0VGM
|
||||
hI+lXgTwywALCna9cqOmWD/cktmq/riG0aB9SQGPluqI80elaO4=
|
||||
=CTqJ
|
||||
iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB8uqsACgkQH6dnhiu9
|
||||
EwXNpRAApaR7KeapzT01v6WgfDD1/BNCTjGDR2A6dq2eY0VCi6T1GsPudzWtaeni
|
||||
h4LJTgkJ0nmMH+hM9acPdPYi+9JnhOM/RGmaMOO7dcFio5abp8+IVERXytrYgH6k
|
||||
jtx+GE8lEpxLSl2yTNvq/jep9Vmcpwp0w2MWIx7Ra6ahmwqHqvdwLIMPx1/+UclX
|
||||
Eb8vzsi/WOwncE8nyahDgY5yCAwbqziVcAnPtg4ACLMBlX7hhw0XBub5aiQFpr7r
|
||||
LZaDd6j6O77povtOT3SKJ/6xYZxwzMgZ2MTZpTr/X8rAoXSwQ3N+IqBcHRntzYVJ
|
||||
jVE0fInqw56V5KJFtaZdnbK9H0VVQ86pvpU2Rry3S04k1CiNzwfgtv0iZ55hKPJA
|
||||
Rn1s0SQBQ4GHalJAqNhCoub4FoDmPcM/qTtjuwg8wIL20dHLdzRL9JacENKmg3yn
|
||||
jdLEn/MxCaTHiWHzTocjO5Gpkvffu1hSYmjbHGVU/fK9HWKmXBNzSJn1/gI48SBv
|
||||
Q5cjJfxFA96cHPeuFkWgCO+RyVj9YMG6hF58D6PGK+3XwnSy9aDTRRbTSGZAMG3c
|
||||
gyAfZfrtuhUk/+fPtxOrIIt4N/m092JVV35ROxoPLzHR7eQGEW52wuUTDV1cTC+8
|
||||
3sIFNeL+L7Q9RIiA7q+f66LE+uDQfZzD/I98Xbl+5CcuvHWm+Qs=
|
||||
=7QwI
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -3,6 +3,8 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
shamir_secret_sharing=false
|
||||
|
||||
share_threshold=3
|
||||
|
||||
positional=()
|
||||
|
@ -1,16 +1,16 @@
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB7OOYACgkQH6dnhiu9
|
||||
EwUy3w//ckQVIouZjTiNam7DBoyGUXw+lfXKKnkR0HEbLeUld0KvDh8fON1IB4GM
|
||||
0eRIpkkbmW8Dp4uAnVxtcQKeEHTZfja7g04hD7AO0JjD7b1drtFjxny8Ue74lR4Q
|
||||
kfIIcB4WEj7nAfEFffgHbihnt1R27shXFcbvWH11DkChXT0tpFZhN2QYqDzK+8t+
|
||||
Ru4Xz+zQ6YDRv40YV4NRMJG8ju9xvfecPLRDK0aO0W/N7HNZMiMYP+ZqgpLlx+11
|
||||
ru550caSKg8VlwywkjoKx84kmBCdhuc90BNgjOsLoL71naRo2f6N+PelUcWzF+VB
|
||||
9J0yVrOq8el6oCfPxT9lnn3BcaVjMrQWHfTM4AllRYEpeU/MqdnknhnxCGlH/u3I
|
||||
fov9kA/shgeAwQ266KTX+l+mPADE4uV0UWCT9vfXOUM9gkPzW040t1pwCqBqhJNP
|
||||
Rwy9ppF4yIMgDZTokpt/s2JMhAHKYCqJRZKaQx0sf+eSO8Ye+SeyfrXYT79JiCT5
|
||||
TYNBEClTLfPJIBx6g2HTxJoO/oKQr0J/usNXzqdN1y5Rzq9IVeyVOxw03VqLu7dW
|
||||
eLfJm5sNUQZtwu8fwqzc3/gtsHchFXmd5700i35rCT/DxUdpEKTDtH/qlp3kqUez
|
||||
5iJmmhsMKXL2AYXYroTAWo/FnPlALJ1+mE/8eWwYjDFjItUjGE8=
|
||||
=9ATO
|
||||
iQIzBAABCgAdFiEEqYzNEiJDZVsm+vthH6dnhiu9EwUFAmB8tvUACgkQH6dnhiu9
|
||||
EwWnhQ//QqY56NLvkUreXU7mEcqvUhxE3HwJdX519QqmMC5+qgLGP1V0BoKqaUYo
|
||||
JlJ5qPiK8y3P6ZYHoX4oajm5LlVoGh5MG+R0xJtnKN0leTa220guzh3/DEKoYJ/1
|
||||
wNFT+R3eGqZIS9ulZrRxKJPaxb+QfbpNVmwMymnwgS+4v0M6uN7L8d9GVws+8DMK
|
||||
owPuT7gC3IpTVR+/Qo++Oesldo3xGWVny7/a+bZ+vCV0OpQ/ybZ139Mava4KrKg7
|
||||
FIFmHcLrSLGu9ud537aMOvtltHAulcpQ/WQND2GAwt9xuVlD0wb924DkmSMEqmL3
|
||||
sn7GMl3icKW2lUR7a4O6kSR+gBGz+6nW9l2XkQjjXrjJsuWcL23x4kAKCvl2TxZF
|
||||
qLGgl7jwrdiaPxdUp45wSgInLORDujXatMRd1otaq34R0L5aH98/RhktiqKI2Mq/
|
||||
9XsW1+k2bWL6tizcL5iv9lqYIoZpfbAO2OcrTfMlG9I2Lcc/UQ9WQAWxMrdCMYCp
|
||||
3RAjkt1miGH77+F3tWRF+MQ+i43F5/C9rty2/3wOYjDei41KQuehDKQ3g4fATkOs
|
||||
AbaP+EEcwwGw0tnQ/lWnJ7dBBtdT2sRnwqKQJ7LMVHcPLqM9m9Pfxlk7GHecp8xi
|
||||
QJ7LUUmSE4hp3xspxxaTLVsTJcBXQeIooiDnDP5T4fSh8ByBodw=
|
||||
=Ljp9
|
||||
-----END PGP SIGNATURE-----
|
||||
|
45
how-to-create-encrypted-paper-backup/test.exp
Normal file
45
how-to-create-encrypted-paper-backup/test.exp
Normal file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/expect
|
||||
|
||||
# exp_internal 1
|
||||
# log_file -noappend ~/expect.log
|
||||
|
||||
set timeout 30
|
||||
|
||||
set bold [exec tput bold]
|
||||
set red [exec tput setaf 1]
|
||||
set green [exec tput setaf 2]
|
||||
set normal [exec tput sgr0]
|
||||
|
||||
proc test_label {value} {
|
||||
upvar bold bold
|
||||
upvar normal normal
|
||||
puts "Running ${bold}${value}${normal}…"
|
||||
}
|
||||
proc test_send {value} {
|
||||
sleep 0.1
|
||||
send "$value"
|
||||
}
|
||||
proc test_failed {} {
|
||||
upvar bold bold
|
||||
upvar red red
|
||||
upvar normal normal
|
||||
sleep 0.1
|
||||
puts "${bold}${red}Failed${normal}"
|
||||
exit 1
|
||||
}
|
||||
proc test_ok {{force_close false}} {
|
||||
upvar bold bold
|
||||
upvar green green
|
||||
upvar normal normal
|
||||
sleep 0.1
|
||||
puts "${bold}${green}OK${normal}"
|
||||
if {$force_close} {
|
||||
close
|
||||
}
|
||||
}
|
||||
|
||||
expect_before {
|
||||
default {
|
||||
test_failed
|
||||
}
|
||||
}
|
@ -17,4 +17,8 @@ expect ./tests/bip39.exp
|
||||
expect ./tests/electrum.exp
|
||||
expect ./tests/default.exp
|
||||
expect ./tests/shamir.exp
|
||||
expect ./tests/shamir2of3.exp
|
||||
expect ./tests/shamir-2-of-3.exp
|
||||
expect ./tests/clone.exp
|
||||
expect ./tests/convert-default-to-shamir-2-of-3.exp
|
||||
expect ./tests/convert-shamir-2-of-3-to-default.exp
|
||||
expect ./tests/duplicate.exp
|
||||
|
@ -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…
x
Reference in New Issue
Block a user