@cryptotaxi247 / kubo / commits / c7657cb69

Fix sharness tests

rendaw committed Jul 16, 2020 at 23:57 UTC c7657cb69036cd0c2c11b34b0f41fb44254fa61d
3 files changed +44 -21
core/commands/keystore.go
+6 -1
@@ -240,7 +240,7 @@ var keyExportCmd = &cmds.Command{
240 name := req.Arguments[0]
241
242 if name == "self" {
243 - return fmt.Errorf("exporting key 'self' is not allowed")
243 + return fmt.Errorf("cannot export key with name 'self'")
244 }
245
246 cfgRoot, err := cmdenv.GetConfigRoot(env)
@@ -290,6 +290,11 @@ var keyImportCmd = &cmds.Command{
290 },
291 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
292 name := req.Arguments[0]
293 +
294 + if name == "self" {
295 + return fmt.Errorf("cannot import key with name 'self'")
296 + }
297 +
298 encoded := req.Arguments[1]
299
300 data, err := base58.Decode(encoded)
test/sharness/lib/test-lib.sh
+5 -5
@@ -484,19 +484,19 @@ test_check_ed25519_b36cid_peerid() {
484 }
485
486 test_check_rsa2048_sk() {
487 - peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
488 - test "$sklen" = "300" || {
487 + sklen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
488 + if (($sklen < 1600)); then
489 echo "Bad RSA2048 sk '$1' with len '$sklen'"
490 return 1
491 - }
491 + fi
492 }
493
494 test_check_ed25519_sk() {
495 sklen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
496 - test "$sklen" = "300" || {
496 + if (($sklen < 1600)); then
497 echo "Bad ED25519 sk '$1' with len '$sklen'"
498 return 1
499 - }
499 + fi
500 }
501
502 convert_tcp_maddr() {
test/sharness/t0165-keystore.sh
+33 -15
@@ -11,15 +11,31 @@ test_description="Test keystore commands"
11 test_init_ipfs
12
13 test_key_cmd() {
14 + test_expect_success "export with no store doesn't store" '
15 + ipfs key gen -n -e && echo self > list_exp &&
16 + ipfs key list > list_out &&
17 + test_sort_cmp list_exp list_out
18 + '
19 +
20 + test_expect_success "no store without export is an error" '
21 + test_must_fail ipfs key gen -n 2>&1 | tee key_gen_out &&
22 + grep -q "you must export key" key_gen_out
23 + '
24 +
25 + test_expect_success "key gen without name is an error" '
26 + test_must_fail ipfs key gen 2>&1 | tee key_gen_out &&
27 + grep -q "you must specify a key name" key_gen_out
28 + '
29 +
30 # test key output format
31 test_expect_success "create an RSA key and test B58MH multihash output" '
32 PEERID=$(ipfs key gen -f=b58mh --type=rsa --size=2048 key_rsa) &&
33 test_check_rsa2048_b58mh_peerid $PEERID
34 '
35
20 -test_expect_success "test RSA key B36CID sk export format" '
21 -PEERID=$(ipfs key export key_rsa) &&
22 -test_check_rsa2048_sk $PEERID
36 +test_expect_success "test RSA key sk export format" '
37 +SK=$(ipfs key export key_rsa) &&
38 +test_check_rsa2048_sk $SK
39 '
40
41 test_expect_success "test RSA key B36CID multihash format" '
@@ -33,9 +49,10 @@ PEERID=$(ipfs key gen -f=b36cid --type=ed25519 key_ed25519) &&
49 test_check_ed25519_b36cid_peerid $PEERID
50 '
51
36 -test_expect_success "test RSA key ED25519 sk export format" '
37 -PEERID=$(ipfs key export key_ed25519) &&
38 -test_check_ed25519_sk $PEERID
52 +test_expect_success "create and export an ED25519 key" '
53 +SK=$(ipfs key gen -e key_ed25519_2) &&
54 +test_check_ed25519_sk $SK &&
55 +ipfs key rm key_ed25519_2
56 '
57
58 test_expect_success "test ED25519 key B36CID multihash format" '
@@ -63,7 +80,7 @@ ipfs key rm key_ed25519
80 test $imphash = $gothash
81 '
82
66 - test_expect_success "key import can't export self" '
83 + test_expect_success "key export can't export self" '
84 test_must_fail ipfs key export self 2>&1 | tee key_exp_out &&
85 grep -q "Error: cannot export key with name" key_exp_out
86 '
@@ -77,10 +94,9 @@ ipfs key rm key_ed25519
94 echo bazed > list_exp &&
95 echo foobarsa >> list_exp &&
96 echo quxel >> list_exp &&
80 - echo self >> list_exp &&
81 - sort -o list_exp list_exp
82 - ipfs key list -f=b58mh | sort > list_out &&
83 - test_cmp list_exp list_out
97 + echo self >> list_exp
98 + ipfs key list -f=b58mh > list_out &&
99 + test_sort_cmp list_exp list_out
100 '
101
102 test_expect_success "key hashes show up in long list output" '
@@ -96,9 +112,10 @@ ipfs key rm key_ed25519
112 test_expect_success "key rm remove a key" '
113 ipfs key rm foobarsa
114 echo bazed > list_exp &&
115 + echo quxel >> list_exp &&
116 echo self >> list_exp
100 - ipfs key list -f=b58mh | sort > list_out &&
101 - test_cmp list_exp list_out
117 + ipfs key list -f=b58mh > list_out &&
118 + test_sort_cmp list_exp list_out
119 '
120
121 test_expect_success "key rm can't remove self" '
@@ -109,9 +126,10 @@ ipfs key rm key_ed25519
126 test_expect_success "key rename rename a key" '
127 ipfs key rename bazed fooed
128 echo fooed > list_exp &&
129 + echo quxel >> list_exp &&
130 echo self >> list_exp
113 - ipfs key list -f=b58mh | sort > list_out &&
114 - test_cmp list_exp list_out
131 + ipfs key list -f=b58mh > list_out &&
132 + test_sort_cmp list_exp list_out
133 '
134
135 test_expect_success "key rename rename key output succeeds" '