mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 09:52:20 +08:00
fix publish fail on prexisting bad record
dont error out if prexisting record is bad, just grab its sequence number and continue on with the publish. License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -1,10 +1,14 @@
|
||||
package namesys
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
key "github.com/ipfs/go-ipfs/blocks/key"
|
||||
peer "github.com/ipfs/go-ipfs/p2p/peer"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
|
||||
u "github.com/ipfs/go-ipfs/util"
|
||||
@ -13,9 +17,10 @@ import (
|
||||
|
||||
func TestRoutingResolve(t *testing.T) {
|
||||
d := mockrouting.NewServer().Client(testutil.RandIdentityOrFatal(t))
|
||||
dstore := ds.NewMapDatastore()
|
||||
|
||||
resolver := NewRoutingResolver(d)
|
||||
publisher := NewRoutingPublisher(d)
|
||||
publisher := NewRoutingPublisher(d, dstore)
|
||||
|
||||
privk, pubk, err := testutil.RandTestKeyPair(512)
|
||||
if err != nil {
|
||||
@ -43,3 +48,90 @@ func TestRoutingResolve(t *testing.T) {
|
||||
t.Fatal("Got back incorrect value.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrexistingExpiredRecord(t *testing.T) {
|
||||
dstore := ds.NewMapDatastore()
|
||||
d := mockrouting.NewServer().ClientWithDatastore(context.Background(), testutil.RandIdentityOrFatal(t), dstore)
|
||||
|
||||
resolver := NewRoutingResolver(d)
|
||||
publisher := NewRoutingPublisher(d, dstore)
|
||||
|
||||
privk, pubk, err := testutil.RandTestKeyPair(512)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
id, err := peer.IDFromPublicKey(pubk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make an expired record and put it in the datastore
|
||||
h := path.FromString("/ipfs/QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN")
|
||||
eol := time.Now().Add(time.Hour * -1)
|
||||
err = PutRecordToRouting(context.Background(), privk, h, 0, eol, d, id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Now, with an old record in the system already, try and publish a new one
|
||||
err = publisher.Publish(context.Background(), privk, h)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = verifyCanResolve(resolver, id.Pretty(), h)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrexistingRecord(t *testing.T) {
|
||||
dstore := ds.NewMapDatastore()
|
||||
d := mockrouting.NewServer().ClientWithDatastore(context.Background(), testutil.RandIdentityOrFatal(t), dstore)
|
||||
|
||||
resolver := NewRoutingResolver(d)
|
||||
publisher := NewRoutingPublisher(d, dstore)
|
||||
|
||||
privk, pubk, err := testutil.RandTestKeyPair(512)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
id, err := peer.IDFromPublicKey(pubk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make a good record and put it in the datastore
|
||||
h := path.FromString("/ipfs/QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN")
|
||||
eol := time.Now().Add(time.Hour)
|
||||
err = PutRecordToRouting(context.Background(), privk, h, 0, eol, d, id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Now, with an old record in the system already, try and publish a new one
|
||||
err = publisher.Publish(context.Background(), privk, h)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = verifyCanResolve(resolver, id.Pretty(), h)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func verifyCanResolve(r Resolver, name string, exp path.Path) error {
|
||||
res, err := r.Resolve(context.Background(), name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if res != exp {
|
||||
return errors.New("got back wrong record!")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user