1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 19:44:01 +08:00

fixes to routing put command (#10205)

* fix(commands): routing put command returns the IPNS ID rather than the host's ID

* fix(commands): routing put command errors with the allow-offline hint if the error is an offline error

* fix: test expects correct error message

---------

Co-authored-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
Adin Schmahmann
2023-11-08 01:07:10 -05:00
committed by GitHub
parent 068f17650d
commit 9371d18b53
3 changed files with 6 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import (
iface "github.com/ipfs/boxo/coreiface"
"github.com/ipfs/boxo/coreiface/options"
dag "github.com/ipfs/boxo/ipld/merkledag"
"github.com/ipfs/boxo/ipns"
cid "github.com/ipfs/go-cid"
cmds "github.com/ipfs/go-ipfs-cmds"
ipld "github.com/ipfs/go-ipld-format"
@ -451,12 +452,12 @@ identified by QmFoo.
options.Put.AllowOffline(allowOffline),
}
err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
ipnsName, err := ipns.NameFromString(req.Arguments[0])
if err != nil {
return err
}
id, err := api.Key().Self(req.Context)
err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
if err != nil {
if err == iface.ErrOffline {
err = errAllowOffline
@ -466,7 +467,7 @@ identified by QmFoo.
return res.Emit(routing.QueryEvent{
Type: routing.Value,
ID: id.ID(),
ID: ipnsName.Peer(),
})
},
Encoders: cmds.EncoderMap{

View File

@ -131,7 +131,7 @@ func TestLegacyDHT(t *testing.T) {
node.WriteBytes("foo", []byte("foo"))
res := node.RunIPFS("dht", "put", "/ipns/"+node.PeerID().String(), "foo")
assert.Equal(t, 1, res.ExitCode())
assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
})
})
}

View File

@ -111,7 +111,7 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
node.WriteBytes("foo", []byte("foo"))
res := node.RunIPFS("routing", "put", "/ipns/"+node.PeerID().String(), "foo")
assert.Equal(t, 1, res.ExitCode())
assert.Contains(t, res.Stderr.String(), "this action must be run in online mode")
assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
})
})
})