| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | test_description="Test rotate command" |
| 4 | |
| 5 | . lib/test-lib.sh |
| 6 | |
| 7 | test_rotate() { |
| 8 | FROM_ALG=$1 |
| 9 | TO_ALG=$2 |
| 10 | |
| 11 | test_expect_success "ipfs init (from $FROM_ALG, to $TO_ALG)" ' |
| 12 | export IPFS_PATH="$(pwd)/.ipfs" && |
| 13 | case $FROM_ALG in |
| 14 | rsa) |
| 15 | ipfs init --profile=test -a=rsa > /dev/null |
| 16 | ;; |
| 17 | ed25519) |
| 18 | ipfs init --profile=test -a=ed25519 > /dev/null |
| 19 | ;; |
| 20 | *) |
| 21 | ipfs init --profile=test > /dev/null |
| 22 | ;; |
| 23 | esac |
| 24 | ' |
| 25 | |
| 26 | test_expect_success "Save first ID and key" ' |
| 27 | ipfs id -f="<id>" > first_id && |
| 28 | ipfs id -f="<pubkey>" > first_key |
| 29 | ' |
| 30 | |
| 31 | test_launch_ipfs_daemon |
| 32 | |
| 33 | test_kill_ipfs_daemon |
| 34 | |
| 35 | test_expect_success "rotating keys" ' |
| 36 | case $TO_ALG in |
| 37 | rsa) |
| 38 | ipfs key rotate -t=rsa -s=2048 --oldkey=oldkey |
| 39 | ;; |
| 40 | ed25519) |
| 41 | ipfs key rotate -t=ed25519 --oldkey=oldkey |
| 42 | ;; |
| 43 | *) |
| 44 | ipfs key rotate --oldkey=oldkey |
| 45 | ;; |
| 46 | esac |
| 47 | ' |
| 48 | |
| 49 | test_expect_success "'ipfs key rotate -o self' should fail" ' |
| 50 | echo "Error: keystore name for back up cannot be named '\''self'\''" >expected-self |
| 51 | test_must_fail ipfs key rotate -o self 2>actual-self && |
| 52 | test_cmp expected-self actual-self |
| 53 | ' |
| 54 | |
| 55 | test_expect_success "Compare second ID and key to first" ' |
| 56 | ipfs id -f="<id>" > second_id && |
| 57 | ipfs id -f="<pubkey>" > second_key && |
| 58 | ! test_cmp first_id second_id && |
| 59 | ! test_cmp first_key second_key |
| 60 | ' |
| 61 | |
| 62 | test_expect_success "checking ID" ' |
| 63 | ipfs config Identity.PeerID > expected-id && |
| 64 | ipfs id -f "<id>\n" > actual-id && |
| 65 | ipfs key list -l --ipns-base=b58mh | grep self | cut -d " " -f1 > keystore-id && |
| 66 | ipfs key list -l --ipns-base=b58mh | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && |
| 67 | test_cmp expected-id actual-id && |
| 68 | test_cmp expected-id keystore-id && |
| 69 | test_cmp old-keystore-id first_id |
| 70 | ' |
| 71 | |
| 72 | test_launch_ipfs_daemon |
| 73 | |
| 74 | test_expect_success "publish name with new and old keys" ' |
| 75 | echo "hello world" > msg && |
| 76 | ipfs add msg | cut -d " " -f2 | tr -d "\n" > msg_hash && |
| 77 | ipfs name publish --offline --allow-offline --key=self $(cat msg_hash) && |
| 78 | ipfs name publish --offline --allow-offline --key=oldkey $(cat msg_hash) |
| 79 | ' |
| 80 | |
| 81 | test_kill_ipfs_daemon |
| 82 | |
| 83 | test_expect_success "clean up ipfs dir" ' |
| 84 | rm -rf "$IPFS_PATH" |
| 85 | ' |
| 86 | |
| 87 | } |
| 88 | test_rotate 'rsa' '' |
| 89 | test_rotate 'ed25519' '' |
| 90 | test_rotate '' '' |
| 91 | test_rotate 'rsa' 'rsa' |
| 92 | test_rotate 'ed25519' 'rsa' |
| 93 | test_rotate '' 'rsa' |
| 94 | test_rotate 'rsa' 'ed25519' |
| 95 | test_rotate 'ed25519' 'ed25519' |
| 96 | test_rotate '' 'ed25519' |
| 97 | |
| 98 | test_done |