IPNS format keys in b36cid
Petar Maymounkov committed
Jul 29, 2020 at 12:26 UTC
e384b5964a5415a57b2a9e014feb26e8edb4e346
9 files changed
+315
-237
.circleci/config.yml
+1
-1
@@ -175,7 +175,7 @@ jobs:
175
command: |
176
npm init -y
177
npm install ipfs@^0.48.1
178
- npm install ipfs-interop@^2.0.0
178
+ npm install ipfs-interop@^2.0.1
179
npm install mocha-circleci-reporter@0.0.3
180
working_directory: ~/ipfs/go-ipfs/interop
181
- run:
core/commands/keystore.go
+27
-27
@@ -104,7 +104,7 @@ var keyGenCmd = &cmds.Command{
104
if sizefound {
105
opts = append(opts, options.Key.Size(size))
106
}
107
- if err = verifyFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
107
+ if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
108
return err
109
}
110
@@ -128,31 +128,6 @@ var keyGenCmd = &cmds.Command{
128
Type: KeyOutput{},
129
}
130
131
-func verifyFormatLabel(formatLabel string) error {
132
- switch formatLabel {
133
- case "b58mh":
134
- return nil
135
- case "b36cid":
136
- return nil
137
- }
138
- return fmt.Errorf("invalid output format option")
139
-}
140
-
141
-func formatID(id peer.ID, formatLabel string) string {
142
- switch formatLabel {
143
- case "b58mh":
144
- return id.Pretty()
145
- case "b36cid":
146
- if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil {
147
- panic(err)
148
- } else {
149
- return s
150
- }
151
- default:
152
- panic("unreachable")
153
- }
154
-}
155
-
131
var keyExportCmd = &cmds.Command{
132
Helptext: cmds.HelpText{
133
Tagline: "Export a keypair",
@@ -320,7 +295,7 @@ var keyListCmd = &cmds.Command{
295
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
296
},
297
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
323
- if err := verifyFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
298
+ if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
299
return err
300
}
301
@@ -437,6 +412,31 @@ var keyRmCmd = &cmds.Command{
412
Type: KeyOutputList{},
413
}
414
415
+func verifyIDFormatLabel(formatLabel string) error {
416
+ switch formatLabel {
417
+ case "b58mh":
418
+ return nil
419
+ case "b36cid":
420
+ return nil
421
+ }
422
+ return fmt.Errorf("invalid output format option")
423
+}
424
+
425
+func formatID(id peer.ID, formatLabel string) string {
426
+ switch formatLabel {
427
+ case "b58mh":
428
+ return id.Pretty()
429
+ case "b36cid":
430
+ if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil {
431
+ panic(err)
432
+ } else {
433
+ return s
434
+ }
435
+ default:
436
+ panic("unreachable")
437
+ }
438
+}
439
+
440
func keyOutputListEncoders() cmds.EncoderFunc {
441
return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *KeyOutputList) error {
442
withID, _ := req.Options["l"].(bool)
core/coreapi/key.go
+1
-1
@@ -29,7 +29,7 @@ func (k *key) Name() string {
29
30
// Path returns the path of the key.
31
func (k *key) Path() path.Path {
32
- return path.New(ipfspath.Join([]string{"/ipns", k.peerID.Pretty()}))
32
+ return path.New(ipfspath.Join([]string{"/ipns", coreiface.FormatKeyID(k.peerID)}))
33
}
34
35
// ID returns key PeerID
core/coreapi/name.go
+1
-1
@@ -76,7 +76,7 @@ func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.Nam
76
}
77
78
return &ipnsEntry{
79
- name: pid.Pretty(),
79
+ name: coreiface.FormatKeyID(pid),
80
value: p,
81
}, nil
82
}
go.mod
+1
-1
@@ -54,7 +54,7 @@ require (
54
github.com/ipfs/go-path v0.0.7
55
github.com/ipfs/go-unixfs v0.2.4
56
github.com/ipfs/go-verifcid v0.0.1
57
- github.com/ipfs/interface-go-ipfs-core v0.3.0
57
+ github.com/ipfs/interface-go-ipfs-core v0.4.0
58
github.com/ipld/go-car v0.1.0
59
github.com/jbenet/go-is-domain v1.0.5
60
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
go.sum
+2
@@ -447,6 +447,8 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
447
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
448
github.com/ipfs/interface-go-ipfs-core v0.3.0 h1:oZdLLfh256gPGcYPURjivj/lv296GIcr8mUqZUnXOEI=
449
github.com/ipfs/interface-go-ipfs-core v0.3.0/go.mod h1:Tihp8zxGpUeE3Tokr94L6zWZZdkRQvG5TL6i9MuNE+s=
450
+github.com/ipfs/interface-go-ipfs-core v0.4.0 h1:+mUiamyHIwedqP8ZgbCIwpy40oX7QcXUbo4CZOeJVJg=
451
+github.com/ipfs/interface-go-ipfs-core v0.4.0/go.mod h1:UJBcU6iNennuI05amq3FQ7g0JHUkibHFAfhfUIy927o=
452
github.com/ipld/go-car v0.1.0 h1:AaIEA5ITRnFA68uMyuIPYGM2XXllxsu8sNjFJP797us=
453
github.com/ipld/go-car v0.1.0/go.mod h1:RCWzaUh2i4mOEkB3W45Vc+9jnS/M6Qay5ooytiBHl3g=
454
github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785 h1:fASnkvtR+SmB2y453RxmDD3Uvd4LonVUgFGk9JoDaZs=
test/sharness/lib/test-lib.sh
+5
-1
@@ -443,9 +443,13 @@ file_size() {
443
$_STAT "$1"
444
}
445
446
+# len 46: 2048-bit RSA keys, b58mh-encoded
447
+# len 52: ED25519 keys, b58mh-encoded
448
+# len 56: 2048-bit RSA keys, b36cid-encoded
449
+# len 62: ED25519 keys, b36cid-encoded
450
test_check_peerid() {
451
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
448
- test "$peeridlen" = "46" -o "$peeridlen" = "52" -o "$peeridlen" = "62" || {
452
+ test "$peeridlen" = "46" -o "$peeridlen" = "52" -o "$peeridlen" = "56" -o "$peeridlen" = "62" || {
453
echo "Bad peerid '$1' with len '$peeridlen'"
454
return 1
455
}
test/sharness/t0100-name.sh
+276
-204
@@ -8,209 +8,281 @@ test_description="Test ipfs repo operations"
8
9
. lib/test-lib.sh
10
11
-test_init_ipfs
12
-
13
-# test publishing a hash
14
-
15
-
16
-test_expect_success "'ipfs name publish --allow-offline' succeeds" '
17
- PEERID=`ipfs id --format="<id>"` &&
18
- test_check_peerid "${PEERID}" &&
19
- ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out
20
-'
21
-
22
-test_expect_success "publish output looks good" '
23
- echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected1 &&
24
- test_cmp expected1 publish_out
25
-'
26
-
27
-test_expect_success "'ipfs name resolve' succeeds" '
28
- ipfs name resolve "$PEERID" >output
29
-'
30
-
31
-test_expect_success "resolve output looks good" '
32
- printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
33
- test_cmp expected2 output
34
-'
35
-
36
-# test publishing with -Q option
37
-
38
-
39
-test_expect_success "'ipfs name publish --quieter' succeeds" '
40
- PEERID=`ipfs id --format="<id>"` &&
41
- test_check_peerid "${PEERID}" &&
42
- ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
43
-'
44
-
45
-test_expect_success "pubrmlish --quieter output looks good" '
46
- echo "${PEERID}" >expected1 &&
47
- test_cmp expected1 publish_out
48
-'
49
-
50
-test_expect_success "'ipfs name resolve' succeeds" '
51
- ipfs name resolve "$PEERID" >output
52
-'
53
-
54
-test_expect_success "resolve output looks good" '
55
- printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
56
- test_cmp expected2 output
57
-'
58
-
59
-# now test with a path
60
-
61
-test_expect_success "'ipfs name publish --allow-offline' succeeds" '
62
- PEERID=`ipfs id --format="<id>"` &&
63
- test_check_peerid "${PEERID}" &&
64
- ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
65
-'
66
-
67
-test_expect_success "publish a path looks good" '
68
- echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS/help" >expected3 &&
69
- test_cmp expected3 publish_out
70
-'
71
-
72
-test_expect_success "'ipfs name resolve' succeeds" '
73
- ipfs name resolve "$PEERID" >output
74
-'
75
-
76
-test_expect_success "resolve output looks good" '
77
- printf "/ipfs/%s/help\n" "$HASH_WELCOME_DOCS" >expected4 &&
78
- test_cmp expected4 output
79
-'
80
-
81
-test_expect_success "ipfs cat on published content succeeds" '
82
- ipfs cat "/ipfs/$HASH_WELCOME_DOCS/help" >expected &&
83
- ipfs cat "/ipns/$PEERID" >actual &&
84
- test_cmp expected actual
85
-'
86
-
87
-# publish with an explicit node ID
88
-
89
-test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
90
- PEERID=`ipfs id --format="<id>"` &&
91
- test_check_peerid "${PEERID}" &&
92
- echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
93
- ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
94
-'
95
-
96
-test_expect_failure "publish with our explicit node ID looks good" '
97
- echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
98
- test_cmp expected_node_id_publish actual_node_id_publish
99
-'
100
-
101
-# publish with an explicit node ID as key name
102
-
103
-test_expect_success "generate and verify a new key" '
104
- NEWID=`ipfs key gen -f=b58mh --type=rsa --size=2048 keyname` &&
105
- test_check_peerid "${NEWID}"
106
-'
107
-
108
-test_expect_success "'ipfs name publis --allow-offline --key=<peer-id> <hash>' succeeds" '
109
- ipfs name publish --allow-offline --key=${NEWID} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
110
-'
111
-
112
-test_expect_success "publish an explicit node ID as key name looks good" '
113
- echo "Published to ${NEWID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
114
- test_cmp expected_node_id_publish actual_node_id_publish
115
-'
116
-
117
-# test IPNS + IPLD
118
-test_expect_success "'ipfs dag put' succeeds" '
119
- HELLO_HASH="$(echo "\"hello world\"" | ipfs dag put)" &&
120
- OBJECT_HASH="$(echo "{\"thing\": {\"/\": \"${HELLO_HASH}\" }}" | ipfs dag put)"
121
-'
122
-test_expect_success "'ipfs name publish --allow-offline /ipld/...' succeeds" '
123
- PEERID=`ipfs id --format="<id>"` &&
124
- test_check_peerid "${PEERID}" &&
125
- ipfs name publish --allow-offline "/ipld/$OBJECT_HASH/thing" >publish_out
126
-'
127
-test_expect_success "publish a path looks good" '
128
- echo "Published to ${PEERID}: /ipld/$OBJECT_HASH/thing" >expected3 &&
129
- test_cmp expected3 publish_out
130
-'
131
-test_expect_success "'ipfs name resolve' succeeds" '
132
- ipfs name resolve "$PEERID" >output
133
-'
134
-test_expect_success "resolve output looks good" '
135
- printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
136
- test_cmp expected4 output
137
-'
138
-
139
-# test publishing nothing
140
-
141
-test_expect_success "'ipfs name publish' fails" '
142
- printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1
143
-'
144
-
145
-test_expect_success "publish output has the correct error" '
146
- grep "argument \"ipfs-path\" is required" publish_out
147
-'
148
-
149
-test_expect_success "'ipfs name publish' fails" '
150
- printf '' | test_expect_code 1 ipfs name publish -Q --allow-offline >publish_out 2>&1
151
-'
152
-
153
-test_expect_success "publish output has the correct error" '
154
- grep "argument \"ipfs-path\" is required" publish_out
155
-'
156
-
157
-test_expect_success "'ipfs name publish --help' succeeds" '
158
- ipfs name publish --help
159
-'
160
-
161
-# test offline resolve
162
-
163
-test_expect_success "'ipfs name resolve --offline' succeeds" '
164
- ipfs name resolve --offline "$PEERID" >output
165
-'
166
-test_expect_success "resolve output looks good" '
167
- printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
168
- test_cmp expected4 output
169
-'
170
-
171
-test_expect_success "'ipfs name resolve --offline -n' succeeds" '
172
- ipfs name resolve --offline -n "$PEERID" >output
173
-'
174
-test_expect_success "resolve output looks good" '
175
- printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
176
- test_cmp expected4 output
177
-'
178
-
179
-test_launch_ipfs_daemon
180
-
181
-test_expect_success "'ipfs name resolve --offline' succeeds" '
182
- ipfs name resolve --offline "$PEERID" >output
183
-'
184
-test_expect_success "resolve output looks good" '
185
- printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
186
- test_cmp expected4 output
187
-'
188
-
189
-test_expect_success "'ipfs name resolve --offline -n' succeeds" '
190
- ipfs name resolve --offline -n "$PEERID" >output
191
-'
192
-test_expect_success "resolve output looks good" '
193
- printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
194
- test_cmp expected4 output
195
-'
196
-
197
-test_expect_success "empty request to name publish doesn't panic and returns error" '
198
- curl -X POST "http://$API_ADDR/api/v0/name/publish" > curl_out || true &&
199
- grep "argument \"ipfs-path\" is required" curl_out
200
-'
201
-
202
-test_kill_ipfs_daemon
203
-
204
-
205
-# Test daemon in offline mode
206
-test_launch_ipfs_daemon --offline
207
-
208
-test_expect_success "'ipfs name publish' fails offline mode" '
209
- PEERID=`ipfs id --format="<id>"` &&
210
- test_check_peerid "${PEERID}" &&
211
- test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS"
212
-'
213
-
214
-test_kill_ipfs_daemon
11
+test_name_with_self() {
12
+ SELF_ALG=$1
13
+
14
+ test_expect_success "ipfs init (variant self $SELF_ALG)" '
15
+ export IPFS_PATH="$(pwd)/.ipfs" &&
16
+ case $SELF_ALG in
17
+ default)
18
+ ipfs init --profile=test > /dev/null
19
+ ;;
20
+ rsa)
21
+ ipfs init --profile=test -a=rsa > /dev/null
22
+ ;;
23
+ ed25519)
24
+ ipfs init --profile=test -a=ed25519 > /dev/null
25
+ ;;
26
+ esac &&
27
+ export PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
28
+ test_check_peerid "${PEERID}"
29
+ '
30
+
31
+ # test publishing a hash
32
+
33
+ test_expect_success "'ipfs name publish --allow-offline' succeeds" '
34
+ ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out
35
+ '
36
+
37
+ test_expect_success "publish output looks good" '
38
+ echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected1 &&
39
+ test_cmp expected1 publish_out
40
+ '
41
+
42
+ test_expect_success "'ipfs name resolve' succeeds" '
43
+ ipfs name resolve "$PEERID" >output
44
+ '
45
+
46
+ test_expect_success "resolve output looks good" '
47
+ printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
48
+ test_cmp expected2 output
49
+ '
50
+
51
+ # test publishing with -Q option
52
+
53
+ test_expect_success "'ipfs name publish --quieter' succeeds" '
54
+ ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
55
+ '
56
+
57
+ test_expect_success "publish --quieter output looks good" '
58
+ echo "${PEERID}" >expected1 &&
59
+ test_cmp expected1 publish_out
60
+ '
61
+
62
+ test_expect_success "'ipfs name resolve' succeeds" '
63
+ ipfs name resolve "$PEERID" >output
64
+ '
65
+
66
+ test_expect_success "resolve output looks good" '
67
+ printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
68
+ test_cmp expected2 output
69
+ '
70
+
71
+ # now test with a path
72
+
73
+ test_expect_success "'ipfs name publish --allow-offline' succeeds" '
74
+ ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
75
+ '
76
+
77
+ test_expect_success "publish a path looks good" '
78
+ echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS/help" >expected3 &&
79
+ test_cmp expected3 publish_out
80
+ '
81
+
82
+ test_expect_success "'ipfs name resolve' succeeds" '
83
+ ipfs name resolve "$PEERID" >output
84
+ '
85
+
86
+ test_expect_success "resolve output looks good" '
87
+ printf "/ipfs/%s/help\n" "$HASH_WELCOME_DOCS" >expected4 &&
88
+ test_cmp expected4 output
89
+ '
90
+
91
+ test_expect_success "ipfs cat on published content succeeds" '
92
+ ipfs cat "/ipfs/$HASH_WELCOME_DOCS/help" >expected &&
93
+ ipfs cat "/ipns/$PEERID" >actual &&
94
+ test_cmp expected actual
95
+ '
96
+
97
+ # publish with an explicit node ID
98
+
99
+ test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
100
+ echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
101
+ ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
102
+ '
103
+
104
+ test_expect_failure "publish with our explicit node ID looks good" '
105
+ echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
106
+ test_cmp expected_node_id_publish actual_node_id_publish
107
+ '
108
+
109
+ # test publishing with B36CID and B58MH resolve to the same B36CID
110
+
111
+ test_expect_success "verify self key output" '
112
+ B58MH_ID=`ipfs key list -f=b58mh -l | grep self | cut -d " " -f1` &&
113
+ B36CID_ID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
114
+ test_check_peerid "${B58MH_ID}" &&
115
+ test_check_peerid "${B36CID_ID}"
116
+ '
117
+
118
+ test_expect_success "'ipfs name publish --allow-offline --key=<peer-id> <hash>' succeeds" '
119
+ ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id &&
120
+ ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >b36cid_published_id
121
+ '
122
+
123
+ test_expect_success "publish an explicit node ID as two key in B58MH and B36CID, name looks good" '
124
+ echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id &&
125
+ test_cmp expected_published_id b58mh_published_id &&
126
+ test_cmp expected_published_id b36cid_published_id
127
+ '
128
+
129
+ test_expect_success "'ipfs name resolve' succeeds" '
130
+ ipfs name resolve "$B36CID_ID" >output
131
+ '
132
+
133
+ test_expect_success "resolve output looks good" '
134
+ printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
135
+ test_cmp expected2 output
136
+ '
137
+
138
+ # test IPNS + IPLD
139
+
140
+ test_expect_success "'ipfs dag put' succeeds" '
141
+ HELLO_HASH="$(echo "\"hello world\"" | ipfs dag put)" &&
142
+ OBJECT_HASH="$(echo "{\"thing\": {\"/\": \"${HELLO_HASH}\" }}" | ipfs dag put)"
143
+ '
144
+ test_expect_success "'ipfs name publish --allow-offline /ipld/...' succeeds" '
145
+ test_check_peerid "${PEERID}" &&
146
+ ipfs name publish --allow-offline "/ipld/$OBJECT_HASH/thing" >publish_out
147
+ '
148
+ test_expect_success "publish a path looks good" '
149
+ echo "Published to ${PEERID}: /ipld/$OBJECT_HASH/thing" >expected3 &&
150
+ test_cmp expected3 publish_out
151
+ '
152
+ test_expect_success "'ipfs name resolve' succeeds" '
153
+ ipfs name resolve "$PEERID" >output
154
+ '
155
+ test_expect_success "resolve output looks good (IPNS + IPLD)" '
156
+ printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
157
+ test_cmp expected4 output
158
+ '
159
+
160
+ # test publishing nothing
161
+
162
+ test_expect_success "'ipfs name publish' fails" '
163
+ printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1
164
+ '
165
+
166
+ test_expect_success "publish output has the correct error" '
167
+ grep "argument \"ipfs-path\" is required" publish_out
168
+ '
169
+
170
+ test_expect_success "'ipfs name publish' fails" '
171
+ printf '' | test_expect_code 1 ipfs name publish -Q --allow-offline >publish_out 2>&1
172
+ '
173
+
174
+ test_expect_success "publish output has the correct error" '
175
+ grep "argument \"ipfs-path\" is required" publish_out
176
+ '
177
+
178
+ test_expect_success "'ipfs name publish --help' succeeds" '
179
+ ipfs name publish --help
180
+ '
181
+
182
+ # test offline resolve
183
+
184
+ test_expect_success "'ipfs name resolve --offline' succeeds" '
185
+ ipfs name resolve --offline "$PEERID" >output
186
+ '
187
+ test_expect_success "resolve output looks good (offline resolve)" '
188
+ printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
189
+ test_cmp expected4 output
190
+ '
191
+
192
+ test_expect_success "'ipfs name resolve --offline -n' succeeds" '
193
+ ipfs name resolve --offline -n "$PEERID" >output
194
+ '
195
+ test_expect_success "resolve output looks good (offline resolve, -n)" '
196
+ printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
197
+ test_cmp expected4 output
198
+ '
199
+
200
+ test_launch_ipfs_daemon
201
+
202
+ test_expect_success "'ipfs name resolve --offline' succeeds" '
203
+ ipfs name resolve --offline "$PEERID" >output
204
+ '
205
+ test_expect_success "resolve output looks good (with daemon)" '
206
+ printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
207
+ test_cmp expected4 output
208
+ '
209
+
210
+ test_expect_success "'ipfs name resolve --offline -n' succeeds" '
211
+ ipfs name resolve --offline -n "$PEERID" >output
212
+ '
213
+ test_expect_success "resolve output looks good (with daemon, -n)" '
214
+ printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
215
+ test_cmp expected4 output
216
+ '
217
+
218
+ test_expect_success "empty request to name publish doesn't panic and returns error" '
219
+ curl -X POST "http://$API_ADDR/api/v0/name/publish" > curl_out || true &&
220
+ grep "argument \"ipfs-path\" is required" curl_out
221
+ '
222
+
223
+ test_kill_ipfs_daemon
224
+
225
+ # Test daemon in offline mode
226
+ test_launch_ipfs_daemon --offline
227
+
228
+ test_expect_success "'ipfs name publish' fails offline mode" '
229
+ test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS"
230
+ '
231
+
232
+ test_kill_ipfs_daemon
233
+
234
+ test_expect_success "clean up ipfs dir" '
235
+ rm -rf "$IPFS_PATH"
236
+ '
237
+}
238
+test_name_with_self 'default'
239
+test_name_with_self 'rsa'
240
+test_name_with_self 'ed25519'
241
+
242
+test_name_with_key() {
243
+ GEN_ALG=$1
244
+
245
+ test_expect_success "ipfs init (key variant $GEN_ALG)" '
246
+ export IPFS_PATH="$(pwd)/.ipfs" &&
247
+ ipfs init --profile=test > /dev/null
248
+ '
249
+
250
+ test_expect_success "'prepare keys" '
251
+ case $GEN_ALG in
252
+ rsa)
253
+ export KEY=`ipfs key gen -f=b58mh --type=rsa --size=2048 key` &&
254
+ export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1`
255
+ ;;
256
+ ed25519_b58)
257
+ export KEY=`ipfs key gen -f=b58mh --type=ed25519 key`
258
+ export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1`
259
+ ;;
260
+ ed25519_b36)
261
+ export KEY=`ipfs key gen -f=b36cid --type=ed25519 key`
262
+ export KEY_B36CID=$KEY
263
+ ;;
264
+ esac &&
265
+ test_check_peerid "${KEY}"
266
+ '
267
+
268
+ # publish with an explicit node ID as key name
269
+
270
+ test_expect_success "'ipfs name publish --allow-offline --key=<peer-id> <hash>' succeeds" '
271
+ ipfs name publish --allow-offline --key=${KEY} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
272
+ '
273
+
274
+ test_expect_success "publish an explicit node ID as key name looks good" '
275
+ echo "Published to ${KEY_B36CID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
276
+ test_cmp expected_node_id_publish actual_node_id_publish
277
+ '
278
+
279
+ # cleanup
280
+ test_expect_success "clean up ipfs dir" '
281
+ rm -rf "$IPFS_PATH"
282
+ '
283
+}
284
+test_name_with_key 'rsa'
285
+test_name_with_key 'ed25519_b58'
286
+test_name_with_key 'ed25519_b36'
287
288
test_done
test/sharness/t0600-issues-and-regressions-online.sh
+1
-1
@@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" '
62
test_launch_ipfs_daemon --offline
63
64
test_expect_success "'ipfs name resolve' succeeds after ipfs id when daemon offline" '
65
- PEERID=`ipfs id --format="<id>"` &&
65
+ PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
66
test_check_peerid "${PEERID}" &&
67
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
68
'