mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
IPNS format keys in b36cid
This commit is contained in:
parent
086ea33827
commit
e384b5964a
@ -175,7 +175,7 @@ jobs:
|
||||
command: |
|
||||
npm init -y
|
||||
npm install ipfs@^0.48.1
|
||||
npm install ipfs-interop@^2.0.0
|
||||
npm install ipfs-interop@^2.0.1
|
||||
npm install mocha-circleci-reporter@0.0.3
|
||||
working_directory: ~/ipfs/go-ipfs/interop
|
||||
- run:
|
||||
|
||||
@ -104,7 +104,7 @@ var keyGenCmd = &cmds.Command{
|
||||
if sizefound {
|
||||
opts = append(opts, options.Key.Size(size))
|
||||
}
|
||||
if err = verifyFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -128,31 +128,6 @@ var keyGenCmd = &cmds.Command{
|
||||
Type: KeyOutput{},
|
||||
}
|
||||
|
||||
func verifyFormatLabel(formatLabel string) error {
|
||||
switch formatLabel {
|
||||
case "b58mh":
|
||||
return nil
|
||||
case "b36cid":
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid output format option")
|
||||
}
|
||||
|
||||
func formatID(id peer.ID, formatLabel string) string {
|
||||
switch formatLabel {
|
||||
case "b58mh":
|
||||
return id.Pretty()
|
||||
case "b36cid":
|
||||
if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return s
|
||||
}
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
|
||||
var keyExportCmd = &cmds.Command{
|
||||
Helptext: cmds.HelpText{
|
||||
Tagline: "Export a keypair",
|
||||
@ -320,7 +295,7 @@ var keyListCmd = &cmds.Command{
|
||||
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
|
||||
},
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
|
||||
if err := verifyFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -437,6 +412,31 @@ var keyRmCmd = &cmds.Command{
|
||||
Type: KeyOutputList{},
|
||||
}
|
||||
|
||||
func verifyIDFormatLabel(formatLabel string) error {
|
||||
switch formatLabel {
|
||||
case "b58mh":
|
||||
return nil
|
||||
case "b36cid":
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid output format option")
|
||||
}
|
||||
|
||||
func formatID(id peer.ID, formatLabel string) string {
|
||||
switch formatLabel {
|
||||
case "b58mh":
|
||||
return id.Pretty()
|
||||
case "b36cid":
|
||||
if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return s
|
||||
}
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
|
||||
func keyOutputListEncoders() cmds.EncoderFunc {
|
||||
return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *KeyOutputList) error {
|
||||
withID, _ := req.Options["l"].(bool)
|
||||
|
||||
@ -29,7 +29,7 @@ func (k *key) Name() string {
|
||||
|
||||
// Path returns the path of the key.
|
||||
func (k *key) Path() path.Path {
|
||||
return path.New(ipfspath.Join([]string{"/ipns", k.peerID.Pretty()}))
|
||||
return path.New(ipfspath.Join([]string{"/ipns", coreiface.FormatKeyID(k.peerID)}))
|
||||
}
|
||||
|
||||
// ID returns key PeerID
|
||||
|
||||
@ -76,7 +76,7 @@ func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.Nam
|
||||
}
|
||||
|
||||
return &ipnsEntry{
|
||||
name: pid.Pretty(),
|
||||
name: coreiface.FormatKeyID(pid),
|
||||
value: p,
|
||||
}, nil
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@ -54,7 +54,7 @@ require (
|
||||
github.com/ipfs/go-path v0.0.7
|
||||
github.com/ipfs/go-unixfs v0.2.4
|
||||
github.com/ipfs/go-verifcid v0.0.1
|
||||
github.com/ipfs/interface-go-ipfs-core v0.3.0
|
||||
github.com/ipfs/interface-go-ipfs-core v0.4.0
|
||||
github.com/ipld/go-car v0.1.0
|
||||
github.com/jbenet/go-is-domain v1.0.5
|
||||
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
|
||||
|
||||
2
go.sum
2
go.sum
@ -447,6 +447,8 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
|
||||
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
|
||||
github.com/ipfs/interface-go-ipfs-core v0.3.0 h1:oZdLLfh256gPGcYPURjivj/lv296GIcr8mUqZUnXOEI=
|
||||
github.com/ipfs/interface-go-ipfs-core v0.3.0/go.mod h1:Tihp8zxGpUeE3Tokr94L6zWZZdkRQvG5TL6i9MuNE+s=
|
||||
github.com/ipfs/interface-go-ipfs-core v0.4.0 h1:+mUiamyHIwedqP8ZgbCIwpy40oX7QcXUbo4CZOeJVJg=
|
||||
github.com/ipfs/interface-go-ipfs-core v0.4.0/go.mod h1:UJBcU6iNennuI05amq3FQ7g0JHUkibHFAfhfUIy927o=
|
||||
github.com/ipld/go-car v0.1.0 h1:AaIEA5ITRnFA68uMyuIPYGM2XXllxsu8sNjFJP797us=
|
||||
github.com/ipld/go-car v0.1.0/go.mod h1:RCWzaUh2i4mOEkB3W45Vc+9jnS/M6Qay5ooytiBHl3g=
|
||||
github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785 h1:fASnkvtR+SmB2y453RxmDD3Uvd4LonVUgFGk9JoDaZs=
|
||||
|
||||
@ -443,9 +443,13 @@ file_size() {
|
||||
$_STAT "$1"
|
||||
}
|
||||
|
||||
# len 46: 2048-bit RSA keys, b58mh-encoded
|
||||
# len 52: ED25519 keys, b58mh-encoded
|
||||
# len 56: 2048-bit RSA keys, b36cid-encoded
|
||||
# len 62: ED25519 keys, b36cid-encoded
|
||||
test_check_peerid() {
|
||||
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
|
||||
test "$peeridlen" = "46" -o "$peeridlen" = "52" -o "$peeridlen" = "62" || {
|
||||
test "$peeridlen" = "46" -o "$peeridlen" = "52" -o "$peeridlen" = "56" -o "$peeridlen" = "62" || {
|
||||
echo "Bad peerid '$1' with len '$peeridlen'"
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -8,209 +8,281 @@ test_description="Test ipfs repo operations"
|
||||
|
||||
. lib/test-lib.sh
|
||||
|
||||
test_init_ipfs
|
||||
test_name_with_self() {
|
||||
SELF_ALG=$1
|
||||
|
||||
# test publishing a hash
|
||||
test_expect_success "ipfs init (variant self $SELF_ALG)" '
|
||||
export IPFS_PATH="$(pwd)/.ipfs" &&
|
||||
case $SELF_ALG in
|
||||
default)
|
||||
ipfs init --profile=test > /dev/null
|
||||
;;
|
||||
rsa)
|
||||
ipfs init --profile=test -a=rsa > /dev/null
|
||||
;;
|
||||
ed25519)
|
||||
ipfs init --profile=test -a=ed25519 > /dev/null
|
||||
;;
|
||||
esac &&
|
||||
export PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
|
||||
test_check_peerid "${PEERID}"
|
||||
'
|
||||
|
||||
# test publishing a hash
|
||||
|
||||
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out
|
||||
'
|
||||
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
|
||||
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out
|
||||
'
|
||||
|
||||
test_expect_success "publish output looks good" '
|
||||
echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected1 &&
|
||||
test_cmp expected1 publish_out
|
||||
'
|
||||
test_expect_success "publish output looks good" '
|
||||
echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected1 &&
|
||||
test_cmp expected1 publish_out
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
|
||||
test_cmp expected2 output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
|
||||
test_cmp expected2 output
|
||||
'
|
||||
|
||||
# test publishing with -Q option
|
||||
# test publishing with -Q option
|
||||
|
||||
test_expect_success "'ipfs name publish --quieter' succeeds" '
|
||||
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name publish --quieter' succeeds" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
|
||||
'
|
||||
test_expect_success "publish --quieter output looks good" '
|
||||
echo "${PEERID}" >expected1 &&
|
||||
test_cmp expected1 publish_out
|
||||
'
|
||||
|
||||
test_expect_success "pubrmlish --quieter output looks good" '
|
||||
echo "${PEERID}" >expected1 &&
|
||||
test_cmp expected1 publish_out
|
||||
'
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
|
||||
test_cmp expected2 output
|
||||
'
|
||||
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
|
||||
test_cmp expected2 output
|
||||
'
|
||||
# now test with a path
|
||||
|
||||
# now test with a path
|
||||
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
|
||||
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name publish --allow-offline' succeeds" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
|
||||
'
|
||||
test_expect_success "publish a path looks good" '
|
||||
echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS/help" >expected3 &&
|
||||
test_cmp expected3 publish_out
|
||||
'
|
||||
|
||||
test_expect_success "publish a path looks good" '
|
||||
echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS/help" >expected3 &&
|
||||
test_cmp expected3 publish_out
|
||||
'
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s/help\n" "$HASH_WELCOME_DOCS" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s/help\n" "$HASH_WELCOME_DOCS" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
test_expect_success "ipfs cat on published content succeeds" '
|
||||
ipfs cat "/ipfs/$HASH_WELCOME_DOCS/help" >expected &&
|
||||
ipfs cat "/ipns/$PEERID" >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs cat on published content succeeds" '
|
||||
ipfs cat "/ipfs/$HASH_WELCOME_DOCS/help" >expected &&
|
||||
ipfs cat "/ipns/$PEERID" >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
# publish with an explicit node ID
|
||||
|
||||
# publish with an explicit node ID
|
||||
test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
|
||||
echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
|
||||
ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
|
||||
'
|
||||
|
||||
test_expect_failure "'ipfs name publish --allow-offline <local-id> <hash>' succeeds" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" &&
|
||||
ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
|
||||
'
|
||||
test_expect_failure "publish with our explicit node ID looks good" '
|
||||
echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
|
||||
test_cmp expected_node_id_publish actual_node_id_publish
|
||||
'
|
||||
|
||||
test_expect_failure "publish with our explicit node ID looks good" '
|
||||
echo "Published to ${PEERID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
|
||||
test_cmp expected_node_id_publish actual_node_id_publish
|
||||
'
|
||||
# test publishing with B36CID and B58MH resolve to the same B36CID
|
||||
|
||||
# publish with an explicit node ID as key name
|
||||
test_expect_success "verify self key output" '
|
||||
B58MH_ID=`ipfs key list -f=b58mh -l | grep self | cut -d " " -f1` &&
|
||||
B36CID_ID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
|
||||
test_check_peerid "${B58MH_ID}" &&
|
||||
test_check_peerid "${B36CID_ID}"
|
||||
'
|
||||
|
||||
test_expect_success "generate and verify a new key" '
|
||||
NEWID=`ipfs key gen -f=b58mh --type=rsa --size=2048 keyname` &&
|
||||
test_check_peerid "${NEWID}"
|
||||
'
|
||||
test_expect_success "'ipfs name publish --allow-offline --key=<peer-id> <hash>' succeeds" '
|
||||
ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id &&
|
||||
ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >b36cid_published_id
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name publis --allow-offline --key=<peer-id> <hash>' succeeds" '
|
||||
ipfs name publish --allow-offline --key=${NEWID} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
|
||||
'
|
||||
test_expect_success "publish an explicit node ID as two key in B58MH and B36CID, name looks good" '
|
||||
echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id &&
|
||||
test_cmp expected_published_id b58mh_published_id &&
|
||||
test_cmp expected_published_id b36cid_published_id
|
||||
'
|
||||
|
||||
test_expect_success "publish an explicit node ID as key name looks good" '
|
||||
echo "Published to ${NEWID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
|
||||
test_cmp expected_node_id_publish actual_node_id_publish
|
||||
'
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$B36CID_ID" >output
|
||||
'
|
||||
|
||||
# test IPNS + IPLD
|
||||
test_expect_success "'ipfs dag put' succeeds" '
|
||||
HELLO_HASH="$(echo "\"hello world\"" | ipfs dag put)" &&
|
||||
OBJECT_HASH="$(echo "{\"thing\": {\"/\": \"${HELLO_HASH}\" }}" | ipfs dag put)"
|
||||
'
|
||||
test_expect_success "'ipfs name publish --allow-offline /ipld/...' succeeds" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline "/ipld/$OBJECT_HASH/thing" >publish_out
|
||||
'
|
||||
test_expect_success "publish a path looks good" '
|
||||
echo "Published to ${PEERID}: /ipld/$OBJECT_HASH/thing" >expected3 &&
|
||||
test_cmp expected3 publish_out
|
||||
'
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipfs/%s\n" "$HASH_WELCOME_DOCS" >expected2 &&
|
||||
test_cmp expected2 output
|
||||
'
|
||||
|
||||
# test publishing nothing
|
||||
# test IPNS + IPLD
|
||||
|
||||
test_expect_success "'ipfs name publish' fails" '
|
||||
printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1
|
||||
'
|
||||
test_expect_success "'ipfs dag put' succeeds" '
|
||||
HELLO_HASH="$(echo "\"hello world\"" | ipfs dag put)" &&
|
||||
OBJECT_HASH="$(echo "{\"thing\": {\"/\": \"${HELLO_HASH}\" }}" | ipfs dag put)"
|
||||
'
|
||||
test_expect_success "'ipfs name publish --allow-offline /ipld/...' succeeds" '
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline "/ipld/$OBJECT_HASH/thing" >publish_out
|
||||
'
|
||||
test_expect_success "publish a path looks good" '
|
||||
echo "Published to ${PEERID}: /ipld/$OBJECT_HASH/thing" >expected3 &&
|
||||
test_cmp expected3 publish_out
|
||||
'
|
||||
test_expect_success "'ipfs name resolve' succeeds" '
|
||||
ipfs name resolve "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good (IPNS + IPLD)" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
|
||||
test_expect_success "publish output has the correct error" '
|
||||
grep "argument \"ipfs-path\" is required" publish_out
|
||||
'
|
||||
# test publishing nothing
|
||||
|
||||
test_expect_success "'ipfs name publish' fails" '
|
||||
printf '' | test_expect_code 1 ipfs name publish -Q --allow-offline >publish_out 2>&1
|
||||
'
|
||||
test_expect_success "'ipfs name publish' fails" '
|
||||
printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1
|
||||
'
|
||||
|
||||
test_expect_success "publish output has the correct error" '
|
||||
grep "argument \"ipfs-path\" is required" publish_out
|
||||
'
|
||||
test_expect_success "publish output has the correct error" '
|
||||
grep "argument \"ipfs-path\" is required" publish_out
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name publish --help' succeeds" '
|
||||
ipfs name publish --help
|
||||
'
|
||||
test_expect_success "'ipfs name publish' fails" '
|
||||
printf '' | test_expect_code 1 ipfs name publish -Q --allow-offline >publish_out 2>&1
|
||||
'
|
||||
|
||||
# test offline resolve
|
||||
test_expect_success "publish output has the correct error" '
|
||||
grep "argument \"ipfs-path\" is required" publish_out
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve --offline' succeeds" '
|
||||
ipfs name resolve --offline "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
test_expect_success "'ipfs name publish --help' succeeds" '
|
||||
ipfs name publish --help
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve --offline -n' succeeds" '
|
||||
ipfs name resolve --offline -n "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
# test offline resolve
|
||||
|
||||
test_launch_ipfs_daemon
|
||||
test_expect_success "'ipfs name resolve --offline' succeeds" '
|
||||
ipfs name resolve --offline "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good (offline resolve)" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve --offline' succeeds" '
|
||||
ipfs name resolve --offline "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
test_expect_success "'ipfs name resolve --offline -n' succeeds" '
|
||||
ipfs name resolve --offline -n "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good (offline resolve, -n)" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs name resolve --offline -n' succeeds" '
|
||||
ipfs name resolve --offline -n "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
test_launch_ipfs_daemon
|
||||
|
||||
test_expect_success "empty request to name publish doesn't panic and returns error" '
|
||||
curl -X POST "http://$API_ADDR/api/v0/name/publish" > curl_out || true &&
|
||||
grep "argument \"ipfs-path\" is required" curl_out
|
||||
'
|
||||
test_expect_success "'ipfs name resolve --offline' succeeds" '
|
||||
ipfs name resolve --offline "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good (with daemon)" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
|
||||
test_kill_ipfs_daemon
|
||||
test_expect_success "'ipfs name resolve --offline -n' succeeds" '
|
||||
ipfs name resolve --offline -n "$PEERID" >output
|
||||
'
|
||||
test_expect_success "resolve output looks good (with daemon, -n)" '
|
||||
printf "/ipld/%s/thing\n" "$OBJECT_HASH" >expected4 &&
|
||||
test_cmp expected4 output
|
||||
'
|
||||
|
||||
test_expect_success "empty request to name publish doesn't panic and returns error" '
|
||||
curl -X POST "http://$API_ADDR/api/v0/name/publish" > curl_out || true &&
|
||||
grep "argument \"ipfs-path\" is required" curl_out
|
||||
'
|
||||
|
||||
# Test daemon in offline mode
|
||||
test_launch_ipfs_daemon --offline
|
||||
test_kill_ipfs_daemon
|
||||
|
||||
test_expect_success "'ipfs name publish' fails offline mode" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS"
|
||||
'
|
||||
# Test daemon in offline mode
|
||||
test_launch_ipfs_daemon --offline
|
||||
|
||||
test_kill_ipfs_daemon
|
||||
test_expect_success "'ipfs name publish' fails offline mode" '
|
||||
test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS"
|
||||
'
|
||||
|
||||
test_kill_ipfs_daemon
|
||||
|
||||
test_expect_success "clean up ipfs dir" '
|
||||
rm -rf "$IPFS_PATH"
|
||||
'
|
||||
}
|
||||
test_name_with_self 'default'
|
||||
test_name_with_self 'rsa'
|
||||
test_name_with_self 'ed25519'
|
||||
|
||||
test_name_with_key() {
|
||||
GEN_ALG=$1
|
||||
|
||||
test_expect_success "ipfs init (key variant $GEN_ALG)" '
|
||||
export IPFS_PATH="$(pwd)/.ipfs" &&
|
||||
ipfs init --profile=test > /dev/null
|
||||
'
|
||||
|
||||
test_expect_success "'prepare keys" '
|
||||
case $GEN_ALG in
|
||||
rsa)
|
||||
export KEY=`ipfs key gen -f=b58mh --type=rsa --size=2048 key` &&
|
||||
export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1`
|
||||
;;
|
||||
ed25519_b58)
|
||||
export KEY=`ipfs key gen -f=b58mh --type=ed25519 key`
|
||||
export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1`
|
||||
;;
|
||||
ed25519_b36)
|
||||
export KEY=`ipfs key gen -f=b36cid --type=ed25519 key`
|
||||
export KEY_B36CID=$KEY
|
||||
;;
|
||||
esac &&
|
||||
test_check_peerid "${KEY}"
|
||||
'
|
||||
|
||||
# publish with an explicit node ID as key name
|
||||
|
||||
test_expect_success "'ipfs name publish --allow-offline --key=<peer-id> <hash>' succeeds" '
|
||||
ipfs name publish --allow-offline --key=${KEY} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish
|
||||
'
|
||||
|
||||
test_expect_success "publish an explicit node ID as key name looks good" '
|
||||
echo "Published to ${KEY_B36CID}: /ipfs/$HASH_WELCOME_DOCS" >expected_node_id_publish &&
|
||||
test_cmp expected_node_id_publish actual_node_id_publish
|
||||
'
|
||||
|
||||
# cleanup
|
||||
test_expect_success "clean up ipfs dir" '
|
||||
rm -rf "$IPFS_PATH"
|
||||
'
|
||||
}
|
||||
test_name_with_key 'rsa'
|
||||
test_name_with_key 'ed25519_b58'
|
||||
test_name_with_key 'ed25519_b36'
|
||||
|
||||
test_done
|
||||
|
||||
@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" '
|
||||
test_launch_ipfs_daemon --offline
|
||||
|
||||
test_expect_success "'ipfs name resolve' succeeds after ipfs id when daemon offline" '
|
||||
PEERID=`ipfs id --format="<id>"` &&
|
||||
PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` &&
|
||||
test_check_peerid "${PEERID}" &&
|
||||
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
|
||||
'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user