Refactored unit tests

This commit is contained in:
Sun Knudsen 2021-04-18 10:06:04 -04:00
parent aaccc14e76
commit 4980788afc
No known key found for this signature in database
GPG key ID: 1FA767862BBD1305
20 changed files with 876 additions and 769 deletions

View file

@ -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