1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 11:52:21 +08:00

Merge pull request #1856 from ipfs/fix/id-self

allow ipfs id to work on self
This commit is contained in:
Juan Benet
2015-10-27 04:52:07 -04:00
2 changed files with 22 additions and 9 deletions

View File

@ -62,7 +62,18 @@ ipfs id supports the format option for output with the following keys:
return
}
if len(req.Arguments()) == 0 {
var id peer.ID
if len(req.Arguments()) > 0 {
id = peer.ID(b58.Decode(req.Arguments()[0]))
if len(id) == 0 {
res.SetError(cmds.ClientError("Invalid peer id"), cmds.ErrClient)
return
}
} else {
id = node.Identity
}
if id == node.Identity {
output, err := printSelf(node)
if err != nil {
res.SetError(err, cmds.ErrNormal)
@ -72,14 +83,6 @@ ipfs id supports the format option for output with the following keys:
return
}
pid := req.Arguments()[0]
id := peer.ID(b58.Decode(pid))
if len(id) == 0 {
res.SetError(cmds.ClientError("Invalid peer id"), cmds.ErrClient)
return
}
// TODO handle offline mode with polymorphism instead of conditionals
if !node.OnlineMode() {
res.SetError(errors.New(offlineIdErrorMessage), cmds.ErrClient)

View File

@ -28,6 +28,16 @@ test_expect_success 'disconnected: addrs local matches ipfs id' '
test_cmp expected actual
'
test_expect_success "ipfs id self works" '
myid=$(ipfs id -f="<id>") &&
ipfs id --timeout=1s $myid > output
'
test_expect_success "output looks good" '
grep $myid output &&
grep PublicKey output
'
test_kill_ipfs_daemon
test_done