diff --git a/core/commands/name/publish.go b/core/commands/name/publish.go index 3175b45170ac..c74193b3f200 100644 --- a/core/commands/name/publish.go +++ b/core/commands/name/publish.go @@ -21,17 +21,17 @@ import ( var ( ErrAllowOffline = errors.New("cannot publish in offline mode by default,using `--allow-offline` to publish again") - ErrIpnsMount = errors.New("cannot manually publish while IPNS is mounted") + ErrIpnsMount = errors.New("cannot manually publish while IPNS is mounted") ErrIdentityLoad = errors.New("identity not loaded") ) const ( - ipfsPathOptionName = "ipfs-path" - resolveOptionName = "resolve" + ipfsPathOptionName = "ipfs-path" + resolveOptionName = "resolve" allowOfflineOptionName = "allow-offline" - lifeTimeOptionName = "lifetime" - ttlOptionName = "ttl" - keyOptionName = "key" + lifeTimeOptionName = "lifetime" + ttlOptionName = "ttl" + keyOptionName = "key" ) var PublishCmd = &cmds.Command{ @@ -97,7 +97,7 @@ Alternatively, publish an using a valid PeerID (as listed by allowOffline, _ := req.Options[allowOfflineOptionName].(bool) if !n.OnlineMode() { if !allowOffline { - res.SetError(ErrAllowOffline,cmdkit.ErrNormal) + res.SetError(ErrAllowOffline, cmdkit.ErrNormal) return } err := n.SetupOfflineRouting() diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index 7dbaa7f7988b..8865871b7ea3 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -12,10 +12,11 @@ test_init_ipfs # test publishing a hash + test_expect_success "'ipfs name publish' succeeds" ' PEERID=`ipfs id --format=""` && test_check_peerid "${PEERID}" && - ipfs name publish "/ipfs/$HASH_WELCOME_DOCS" >publish_out + ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS" >publish_out ' test_expect_success "publish output looks good" ' @@ -37,7 +38,7 @@ test_expect_success "resolve output looks good" ' test_expect_success "'ipfs name publish' succeeds" ' PEERID=`ipfs id --format=""` && test_check_peerid "${PEERID}" && - ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out + ipfs name publish --allow-offline "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out ' test_expect_success "publish a path looks good" ' @@ -65,7 +66,7 @@ test_expect_success "ipfs cat on published content succeeds" ' test_expect_failure "'ipfs name publish ' succeeds" ' PEERID=`ipfs id --format=""` && test_check_peerid "${PEERID}" && - echo ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" && + echo ipfs name publish --allow-offline "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" && ipfs name publish "${PEERID}" "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish ' @@ -82,7 +83,7 @@ test_expect_success "generate and verify a new key" ' ' test_expect_success "'ipfs name publish --key= ' succeeds" ' - ipfs name publish --key=${NEWID} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish + ipfs name publish --allow-offline --key=${NEWID} "/ipfs/$HASH_WELCOME_DOCS" >actual_node_id_publish ' test_expect_success "publish an explicit node ID as key name looks good" ' @@ -94,7 +95,7 @@ test_expect_success "publish an explicit node ID as key name looks good" ' # test publishing nothing test_expect_success "'ipfs name publish' fails" ' - printf '' | test_expect_code 1 ipfs name publish >publish_out 2>&1 + printf '' | test_expect_code 1 ipfs name publish --allow-offline >publish_out 2>&1 ' test_expect_success "publish output has the correct error" ' @@ -107,6 +108,17 @@ test_expect_success "'ipfs name publish --help' succeeds" ' test_launch_ipfs_daemon +test_expect_success "'ipfs name publish' succeeds" ' + PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && + ipfs name publish "/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 "empty request to name publish doesn't panic and returns error" ' curl "http://$API_ADDR/api/v0/name/publish" > curl_out || true && grep "argument \"ipfs-path\" is required" curl_out @@ -115,4 +127,15 @@ test_expect_success "empty request to name publish doesn't panic and returns err test_kill_ipfs_daemon +# Test daemon in offline mode +test_launch_ipfs_daemon --offline + +test_expect_success "'ipfs name publish' fails offline mode" ' + PEERID=`ipfs id --format=""` && + test_check_peerid "${PEERID}" && + test_expect_code 1 ipfs name publish "/ipfs/$HASH_WELCOME_DOCS" +' + +test_kill_ipfs_daemon + test_done diff --git a/test/sharness/t0110-gateway.sh b/test/sharness/t0110-gateway.sh index 7d519911bc68..8c5d4982fefa 100755 --- a/test/sharness/t0110-gateway.sh +++ b/test/sharness/t0110-gateway.sh @@ -62,7 +62,7 @@ test_expect_success "GET IPFS non existent file returns code expected (404)" ' ' test_expect_failure "GET IPNS path succeeds" ' - ipfs name publish "$HASH" && + ipfs name publish --allow-offline "$HASH" && PEERID=$(ipfs config Identity.PeerID) && test_check_peerid "$PEERID" && curl -sfo actual "http://127.0.0.1:$port/ipns/$PEERID" diff --git a/test/sharness/t0160-resolve.sh b/test/sharness/t0160-resolve.sh index d64c0eac5b7b..dacd05d9f848 100755 --- a/test/sharness/t0160-resolve.sh +++ b/test/sharness/t0160-resolve.sh @@ -19,7 +19,7 @@ test_resolve_setup_name() { test_expect_success "resolve: prepare name" ' id_hash=$(ipfs id -f="") && - ipfs name publish "$ref" && + ipfs name publish --allow-offline "$ref" && printf "$ref\n" >expected_nameval && ipfs name resolve >actual_nameval && test_cmp expected_nameval actual_nameval @@ -31,7 +31,7 @@ test_resolve_setup_name_fail() { test_expect_failure "resolve: prepare name" ' id_hash=$(ipfs id -f="") && - ipfs name publish "$ref" && + ipfs name publish --allow-offline "$ref" && printf "$ref" >expected_nameval && ipfs name resolve >actual_nameval && test_cmp expected_nameval actual_nameval