181 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

2021-04-17 16:31:44 -04:00
#!/usr/bin/expect
2021-04-18 10:06:04 -04:00
source ./test.exp
2021-04-17 16:31:44 -04:00
set passphrase "asdasd"
set secret "foo\nbar"
2021-04-18 10:06:04 -04:00
test_label "Should backup secret using Shamir Secret Sharing"
2021-04-17 16:31:44 -04:00
spawn qr-backup.sh --shamir-secret-sharing
expect {
-re {Format USB flash drive \(y or n\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {\[sudo\] password for pi:} {
2021-04-18 10:06:04 -04:00
test_send "$env(password)\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Please type secret and press enter, then ctrl\+d} {
2021-04-18 10:06:04 -04:00
test_send "$secret\r"
test_send "\x04"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Please type secret and press enter, then ctrl\+d \(again\)} {
2021-04-18 10:06:04 -04:00
test_send "$secret\r"
test_send "\x04"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Please type passphrase and press enter} {
2021-04-18 10:06:04 -04:00
test_send "$passphrase\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Please type passphrase and press enter \(again\)} {
2021-04-18 10:06:04 -04:00
test_send "$passphrase\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Show passphrase \(y or n\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
2021-04-18 10:06:04 -04:00
-re {Encrypting secret share 1 of 5…}
2021-04-17 16:31:44 -04:00
}
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\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
2021-04-18 10:06:04 -04:00
-re {Encrypting secret share 2 of 5…}
2021-04-17 16:31:44 -04:00
}
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\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
2021-04-18 10:06:04 -04:00
-re {Encrypting secret share 3 of 5…}
2021-04-17 16:31:44 -04:00
}
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\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
2021-04-18 10:06:04 -04:00
-re {Encrypting secret share 4 of 5…}
2021-04-17 16:31:44 -04:00
}
expect {
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
set short_hash_4 $expect_out(1,string)
}
}
expect {
-re {Show SHA512 hash as QR code \(y or n\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
2021-04-18 10:06:04 -04:00
-re {Encrypting secret share 5 of 5…}
2021-04-17 16:31:44 -04:00
}
expect {
-re {SHA512 short hash: .+?([a-f0-9]{8})} {
set short_hash_5 $expect_out(1,string)
}
}
expect {
-re {Show SHA512 hash as QR code \(y or n\)\?} {
2021-04-18 10:06:04 -04:00
test_send "n\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
2021-04-18 10:06:04 -04:00
-re {Done} {
test_ok
2021-04-17 16:31:44 -04:00
}
2021-05-21 14:02:00 -04:00
eof {
test_failed
}
2021-04-17 16:31:44 -04:00
}
2021-04-18 10:06:04 -04:00
test_label "Should restore secret using Shamir Secret Sharing"
2021-04-17 16:31:44 -04:00
spawn qr-restore.sh --images "$short_hash_1.jpg,$short_hash_2.jpg,$short_hash_5.jpg" --shamir-secret-sharing
expect {
-re {\[sudo\] password for pi:} {
2021-04-18 10:06:04 -04:00
test_send "$env(password)\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Please type passphrase and press enter} {
2021-04-18 10:06:04 -04:00
test_send "$passphrase\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Show secret \(y or n\)\?} {
2021-04-18 10:06:04 -04:00
test_send "y\r"
2021-04-17 16:31:44 -04:00
}
}
expect {
-re {Secret:\r\n((.|\r\n)+?)\r\nDone} {
set restored_secret $expect_out(1,string)
}
}
2021-04-19 13:43:55 -04:00
regsub -all {\033\[[0-9]*m(\017)?} $restored_secret {} restored_secret
2021-04-17 16:31:44 -04:00
regsub -all {\r} $restored_secret {} restored_secret
if { "$restored_secret" != "$secret" } {
2021-04-18 10:06:04 -04:00
test_failed
2021-04-17 16:31:44 -04:00
} else {
2021-04-18 10:06:04 -04:00
test_ok
2021-04-17 16:31:44 -04:00
}