t0165-keystore.sh 1.97 KB
Newer Older
Łukasz Magiera's avatar
Łukasz Magiera committed
1
#!/usr/bin/env bash
Jeromy's avatar
Jeromy committed
2 3 4 5 6 7 8 9 10 11 12 13
#
# Copyright (c) 2017 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test keystore commands"

. lib/test-lib.sh

test_init_ipfs

test_key_cmd() {
Łukasz Magiera's avatar
Łukasz Magiera committed
14 15 16
  test_expect_success "create a new rsa key" '
    rsahash=$(ipfs key gen foobarsa --type=rsa --size=2048)
  '
Jeromy's avatar
Jeromy committed
17

Łukasz Magiera's avatar
Łukasz Magiera committed
18 19 20
  test_expect_success "create a new ed25519 key" '
    edhash=$(ipfs key gen bazed --type=ed25519)
  '
Jeromy's avatar
Jeromy committed
21

Łukasz Magiera's avatar
Łukasz Magiera committed
22 23 24 25 26 27 28
  test_expect_success "both keys show up in list output" '
    echo bazed > list_exp &&
    echo foobarsa >> list_exp &&
    echo self >> list_exp
    ipfs key list | sort > list_out &&
    test_cmp list_exp list_out
  '
Jeromy's avatar
Jeromy committed
29

Łukasz Magiera's avatar
Łukasz Magiera committed
30 31 32 33
  test_expect_success "key hashes show up in long list output" '
    ipfs key list -l | grep $edhash > /dev/null &&
    ipfs key list -l | grep $rsahash > /dev/null
  '
34

Łukasz Magiera's avatar
Łukasz Magiera committed
35 36 37 38
  test_expect_success "key list -l contains self key with peerID" '
    PeerID="$(ipfs config Identity.PeerID)"
    ipfs key list -l | grep "$PeerID self"
  '
Michael Muré's avatar
Michael Muré committed
39

Łukasz Magiera's avatar
Łukasz Magiera committed
40 41 42 43 44 45 46
  test_expect_success "key rm remove a key" '
    ipfs key rm foobarsa
    echo bazed > list_exp &&
    echo self >> list_exp
    ipfs key list | sort > list_out &&
    test_cmp list_exp list_out
  '
47

Łukasz Magiera's avatar
Łukasz Magiera committed
48 49 50 51
  test_expect_success "key rm can't remove self" '
    test_must_fail ipfs key rm self 2>&1 | tee key_rm_out &&
    grep -q "Error: cannot remove key with name" key_rm_out
  '
52

Łukasz Magiera's avatar
Łukasz Magiera committed
53 54 55 56 57 58 59
  test_expect_success "key rename rename a key" '
    ipfs key rename bazed fooed
    echo fooed > list_exp &&
    echo self >> list_exp
    ipfs key list | sort > list_out &&
    test_cmp list_exp list_out
  '
60

Łukasz Magiera's avatar
Łukasz Magiera committed
61 62 63 64
  test_expect_success "key rename can't rename self" '
    test_must_fail ipfs key rename self bar 2>&1 | tee key_rename_out &&
    grep -q "Error: cannot rename key with name" key_rename_out
  '
65

Łukasz Magiera's avatar
Łukasz Magiera committed
66 67 68 69
  test_expect_success "key rename can't overwrite self, even with force" '
    test_must_fail ipfs key rename -f fooed self 2>&1 | tee key_rename_out &&
    grep -q "Error: cannot overwrite key with name" key_rename_out
  '
Jeromy's avatar
Jeromy committed
70 71 72 73 74
}

test_key_cmd

test_done