|
|
@ -12,8 +12,9 @@ oneTimeSetUp() { |
|
|
|
newKey(){ |
|
|
|
assertNotNull "keyname required" "$1" |
|
|
|
KEYPASS=${2:-qwertyuiop} |
|
|
|
KEY=$(echo $KEYPASS | ${EXE} new $1) |
|
|
|
assertTrue "created $1" $? |
|
|
|
KEY=$(echo $KEYPASS | ${EXE} new $1 -o json) |
|
|
|
if ! assertTrue "created $1" $?; then return 1; fi |
|
|
|
assertEquals "$1" $(echo $KEY | jq .key.name | tr -d \") |
|
|
|
return $? |
|
|
|
} |
|
|
|
|
|
|
@ -59,6 +60,52 @@ test02updateKeys() { |
|
|
|
assertTrue "takes new key after update" "updateKey $USER $PASS2 $PASS3" |
|
|
|
} |
|
|
|
|
|
|
|
test03recoverKeys() { |
|
|
|
USER=sleepy |
|
|
|
PASS1=S4H.9j.D9S7hso |
|
|
|
|
|
|
|
USER2=easy |
|
|
|
PASS2=1234567890 |
|
|
|
|
|
|
|
# make a user and check they exist |
|
|
|
echo "create..." |
|
|
|
KEY=$(echo $PASS1 | ${EXE} new $USER -o json) |
|
|
|
if ! assertTrue "created $USER" $?; then return 1; fi |
|
|
|
if [ -n "$DEBUG" ]; then echo $KEY; echo; fi |
|
|
|
|
|
|
|
SEED=$(echo $KEY | jq .seed | tr -d \") |
|
|
|
ADDR=$(echo $KEY | jq .key.address | tr -d \") |
|
|
|
PUBKEY=$(echo $KEY | jq .key.pubkey | tr -d \") |
|
|
|
assertTrue "${EXE} get $USER > /dev/null" |
|
|
|
|
|
|
|
# let's delete this key |
|
|
|
echo "delete..." |
|
|
|
assertFalse "echo foo | ${EXE} delete $USER > /dev/null" |
|
|
|
assertTrue "echo $PASS1 | ${EXE} delete $USER > /dev/null" |
|
|
|
assertFalse "${EXE} get $USER > /dev/null" |
|
|
|
|
|
|
|
# fails on short password |
|
|
|
echo "recover..." |
|
|
|
assertFalse "echo foo; echo $SEED | ${EXE} recover $USER2 -o json > /dev/null" |
|
|
|
# fails on bad seed |
|
|
|
assertFalse "echo $PASS2; echo \"silly white whale tower bongo\" | ${EXE} recover $USER2 -o json > /dev/null" |
|
|
|
# now we got it |
|
|
|
KEY2=$((echo $PASS2; echo $SEED) | ${EXE} recover $USER2 -o json) |
|
|
|
if ! assertTrue "recovery failed: $KEY2" $?; then return 1; fi |
|
|
|
if [ -n "$DEBUG" ]; then echo $KEY2; echo; fi |
|
|
|
|
|
|
|
# make sure it looks the same |
|
|
|
NAME2=$(echo $KEY2 | jq .name | tr -d \") |
|
|
|
ADDR2=$(echo $KEY2 | jq .address | tr -d \") |
|
|
|
PUBKEY2=$(echo $KEY2 | jq .pubkey | tr -d \") |
|
|
|
assertEquals "wrong username" "$USER2" "$NAME2" |
|
|
|
assertEquals "address doesn't match" "$ADDR" "$ADDR2" |
|
|
|
assertEquals "pubkey doesn't match" "$PUBKEY" "$PUBKEY2" |
|
|
|
|
|
|
|
# and we can find the info |
|
|
|
assertTrue "${EXE} get $USER2 > /dev/null" |
|
|
|
} |
|
|
|
|
|
|
|
# load and run these tests with shunit2! |
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory |
|
|
|
. $DIR/shunit2 |