mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +08:00
Merge pull request #2340 from ipfs/fix/key-escape
fix dht command key escaping
This commit is contained in:
@ -573,7 +573,7 @@ func escapeDhtKey(s string) (key.Key, error) {
|
||||
return key.B58KeyDecode(s), nil
|
||||
case 3:
|
||||
k := key.B58KeyDecode(parts[2])
|
||||
return key.Key(path.Join(append(parts[:2], k.String()))), nil
|
||||
return key.Key(path.Join(append(parts[:2], string(k)))), nil
|
||||
default:
|
||||
return "", errors.New("invalid key")
|
||||
}
|
||||
|
31
core/commands/dht_test.go
Normal file
31
core/commands/dht_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/go-ipfs/namesys"
|
||||
tu "github.com/ipfs/go-ipfs/thirdparty/testutil"
|
||||
)
|
||||
|
||||
func TestKeyTranslation(t *testing.T) {
|
||||
pid := tu.RandPeerIDFatal(t)
|
||||
a, b := namesys.IpnsKeysForID(pid)
|
||||
|
||||
pkk, err := escapeDhtKey("/pk/" + pid.Pretty())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if pkk != a {
|
||||
t.Fatal("keys didnt match!")
|
||||
}
|
||||
|
||||
if ipnsk != b {
|
||||
t.Fatal("keys didnt match!")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user