@cryptotaxi247 / kubo / commits / a6f446a4b

test: deterministic ipns fixtures during sharness gateway tests (#9667)

Laurent Senta committed May 3, 2023 at 15:01 UTC a6f446a4bab78b3d8b814474f1532f7bebcdc9c1
23 files changed +225 -102
core/commands/routing.go
+25 -9
@@ -10,6 +10,8 @@ import (
10
11 cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"
12
13 + iface "github.com/ipfs/boxo/coreiface"
14 + "github.com/ipfs/boxo/coreiface/options"
15 dag "github.com/ipfs/boxo/ipld/merkledag"
16 path "github.com/ipfs/boxo/path"
17 cid "github.com/ipfs/go-cid"
@@ -19,6 +21,16 @@ import (
21 routing "github.com/libp2p/go-libp2p/core/routing"
22 )
23
24 +var (
25 + errAllowOffline = errors.New("can't put while offline: pass `--allow-offline` to override")
26 +)
27 +
28 +const (
29 + dhtVerboseOptionName = "verbose"
30 + numProvidersOptionName = "num-providers"
31 + allowOfflineOptionName = "allow-offline"
32 +)
33 +
34 var RoutingCmd = &cmds.Command{
35 Helptext: cmds.HelpText{
36 Tagline: "Issue routing commands.",
@@ -34,14 +46,6 @@ var RoutingCmd = &cmds.Command{
46 },
47 }
48
37 -const (
38 - dhtVerboseOptionName = "verbose"
39 -)
40 -
41 -const (
42 - numProvidersOptionName = "num-providers"
43 -)
44 -
49 var findProvidersRoutingCmd = &cmds.Command{
50 Helptext: cmds.HelpText{
51 Tagline: "Find peers that can provide a specific value, given a key.",
@@ -420,6 +424,9 @@ identified by QmFoo.
424 cmds.StringArg("key", true, false, "The key to store the value at."),
425 cmds.FileArg("value-file", true, false, "A path to a file containing the value to store.").EnableStdin(),
426 },
427 + Options: []cmds.Option{
428 + cmds.BoolOption(allowOfflineOptionName, "When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing."),
429 + },
430 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
431 api, err := cmdenv.GetApi(env, req)
432 if err != nil {
@@ -437,13 +444,22 @@ identified by QmFoo.
444 return err
445 }
446
440 - err = api.Routing().Put(req.Context, req.Arguments[0], data)
447 + allowOffline, _ := req.Options[allowOfflineOptionName].(bool)
448 +
449 + opts := []options.RoutingPutOption{
450 + options.Put.AllowOffline(allowOffline),
451 + }
452 +
453 + err = api.Routing().Put(req.Context, req.Arguments[0], data, opts...)
454 if err != nil {
455 return err
456 }
457
458 id, err := api.Key().Self(req.Context)
459 if err != nil {
460 + if err == iface.ErrOffline {
461 + err = errAllowOffline
462 + }
463 return err
464 }
465
core/coreapi/routing.go
+10 -3
@@ -5,6 +5,7 @@ import (
5 "errors"
6
7 coreiface "github.com/ipfs/boxo/coreiface"
8 + caopts "github.com/ipfs/boxo/coreiface/options"
9 "github.com/ipfs/boxo/path"
10 peer "github.com/libp2p/go-libp2p/core/peer"
11 )
@@ -24,9 +25,15 @@ func (r *RoutingAPI) Get(ctx context.Context, key string) ([]byte, error) {
25 return r.routing.GetValue(ctx, dhtKey)
26 }
27
27 -func (r *RoutingAPI) Put(ctx context.Context, key string, value []byte) error {
28 - if !r.nd.IsOnline {
29 - return coreiface.ErrOffline
28 +func (r *RoutingAPI) Put(ctx context.Context, key string, value []byte, opts ...caopts.RoutingPutOption) error {
29 + options, err := caopts.RoutingPutOptions(opts...)
30 + if err != nil {
31 + return err
32 + }
33 +
34 + err = r.checkOnline(options.AllowOffline)
35 + if err != nil {
36 + return err
37 }
38
39 dhtKey, err := normalizeKey(key)
core/coreapi/test/api_test.go
+12 -10
@@ -31,7 +31,7 @@ const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
31
32 type NodeProvider struct{}
33
34 -func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
34 +func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, online bool, n int) ([]coreiface.CoreAPI, error) {
35 mn := mocknet.New()
36
37 nodes := make([]*core.IpfsNode, n)
@@ -82,7 +82,7 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
82 Routing: libp2p.DHTServerOption,
83 Repo: r,
84 Host: mock.MockHostOption(mn),
85 - Online: fullIdentity,
85 + Online: online,
86 ExtraOpts: map[string]bool{
87 "pubsub": true,
88 },
@@ -102,15 +102,17 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
102 return nil, err
103 }
104
105 - bsinf := bootstrap.BootstrapConfigWithPeers(
106 - []peer.AddrInfo{
107 - nodes[0].Peerstore.PeerInfo(nodes[0].Identity),
108 - },
109 - )
105 + if online {
106 + bsinf := bootstrap.BootstrapConfigWithPeers(
107 + []peer.AddrInfo{
108 + nodes[0].Peerstore.PeerInfo(nodes[0].Identity),
109 + },
110 + )
111
111 - for _, n := range nodes[1:] {
112 - if err := n.Bootstrap(bsinf); err != nil {
113 - return nil, err
112 + for _, n := range nodes[1:] {
113 + if err := n.Bootstrap(bsinf); err != nil {
114 + return nil, err
115 + }
116 }
117 }
118
core/coreapi/test/path_test.go
+1 -1
@@ -19,7 +19,7 @@ func TestPathUnixFSHAMTPartial(t *testing.T) {
19 defer cancel()
20
21 // Create a node
22 - apis, err := NodeProvider{}.MakeAPISwarm(ctx, true, 1)
22 + apis, err := NodeProvider{}.MakeAPISwarm(ctx, true, true, 1)
23 if err != nil {
24 t.Fatal(err)
25 }
docs/examples/kubo-as-a-library/go.mod
+1 -1
@@ -7,7 +7,7 @@ go 1.18
7 replace github.com/ipfs/kubo => ./../../..
8
9 require (
10 - github.com/ipfs/boxo v0.8.1
10 + github.com/ipfs/boxo v0.8.2-0.20230503105907-8059f183d866
11 github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
12 github.com/libp2p/go-libp2p v0.27.1
13 github.com/multiformats/go-multiaddr v0.9.0
docs/examples/kubo-as-a-library/go.sum
+2 -2
@@ -321,8 +321,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
321 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
322 github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
323 github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
324 -github.com/ipfs/boxo v0.8.1 h1:3DkKBCK+3rdEB5t77WDShUXXhktYwH99mkAsgajsKrU=
325 -github.com/ipfs/boxo v0.8.1/go.mod h1:xJ2hVb4La5WyD7GvKYE0lq2g1rmQZoCD2K4WNrV6aZI=
324 +github.com/ipfs/boxo v0.8.2-0.20230503105907-8059f183d866 h1:ThRTXD/EyoLb/jz+YW+ZlOLbjX9FyaxP0dEpgUp3cCE=
325 +github.com/ipfs/boxo v0.8.2-0.20230503105907-8059f183d866/go.mod h1:bORAHrH6hUtDZjbzTEaLrSpTdyhHKDIpjDRT+A14B7w=
326 github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
327 github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
328 github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
go.mod
+1 -1
@@ -16,7 +16,7 @@ require (
16 github.com/gogo/protobuf v1.3.2
17 github.com/google/uuid v1.3.0
18 github.com/hashicorp/go-multierror v1.1.1
19 - github.com/ipfs/boxo v0.8.1
19 + github.com/ipfs/boxo v0.8.2-0.20230503105907-8059f183d866
20 github.com/ipfs/go-block-format v0.1.2
21 github.com/ipfs/go-cid v0.4.1
22 github.com/ipfs/go-cidutil v0.1.0
go.sum
+2 -2
@@ -356,8 +356,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
356 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
357 github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
358 github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
359 -github.com/ipfs/boxo v0.8.1 h1:3DkKBCK+3rdEB5t77WDShUXXhktYwH99mkAsgajsKrU=
360 -github.com/ipfs/boxo v0.8.1/go.mod h1:xJ2hVb4La5WyD7GvKYE0lq2g1rmQZoCD2K4WNrV6aZI=
359 +github.com/ipfs/boxo v0.8.2-0.20230503105907-8059f183d866 h1:ThRTXD/EyoLb/jz+YW+ZlOLbjX9FyaxP0dEpgUp3cCE=
360 +github.com/ipfs/boxo v0.8.2-0.20230503105907-8059f183d866/go.mod h1:bORAHrH6hUtDZjbzTEaLrSpTdyhHKDIpjDRT+A14B7w=
361 github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
362 github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
363 github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
test/sharness/t0114-gateway-subdomains.sh
+18 -34
@@ -93,40 +93,29 @@ test_launch_ipfs_daemon_without_network
93
94 # Import test case
95 # See the static fixtures in ./t0114-gateway-subdomains/
96 -test_expect_success "Add the test fixtures" '
97 - ipfs dag import ../t0114-gateway-subdomains/fixtures.car
98 -'
99 -CID_VAL="hello"
96 +CID_VAL=hello
97 CIDv1=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am
98 CIDv0=QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
102 -# CIDv0to1 is necessary because raw-leaves are enabled by default during
103 -# "ipfs add" with CIDv1 and disabled with CIDv0
99 CIDv0to1=bafybeiffndsajwhk3lwjewwdxqntmjm4b5wxaaanokonsggenkbw6slwk4
100 CIDv1_TOO_LONG=bafkrgqhhyivzstcz3hhswshfjgy6ertgmnqeleynhwt4dlfsthi4hn7zgh4uvlsb5xncykzapi3ocd4lzogukir6ksdy6wzrnz6ohnv4aglcs
106 -DIR_CID=bafybeiht6dtwk3les7vqm6ibpvz6qpohidvlshsfyr7l5mpysdw2vmbbhe # ./testdirlisting
107 -
108 -test_expect_success "Publish test text file to IPNS using RSA keys" '
109 - RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n")
110 - RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0)
111 - RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --mc libp2p-key -b base36)
112 - RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36)
113 - test_check_peerid "${RSA_KEY}" &&
114 - ipfs name publish --key test_key_rsa --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out &&
115 - ipfs name resolve "$RSA_KEY" > output &&
116 - printf "/ipfs/%s\n" "$CIDv1" > expected2 &&
117 - test_cmp expected2 output
118 -'
101 +DIR_CID=bafybeiht6dtwk3les7vqm6ibpvz6qpohidvlshsfyr7l5mpysdw2vmbbhe
102 +
103 +RSA_KEY=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3
104 +RSA_IPNS_IDv0=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3
105 +RSA_IPNS_IDv1=k2k4r8m7xvggw5pxxk3abrkwyer625hg01hfyggrai7lk1m63fuihi7w
106 +RSA_IPNS_IDv1_DAGPB=k2jmtxu61bnhrtj301lw7zizknztocdbeqhxgv76l2q9t36fn9jbzipo
107
120 -test_expect_success "Publish test text file to IPNS using ED25519 keys" '
121 - ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n")
122 - ED25519_IPNS_IDv0=$ED25519_KEY
123 - ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=base36 | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n")
124 - ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --mc dag-pb)
125 - test_check_peerid "${ED25519_KEY}" &&
126 - ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out &&
127 - ipfs name resolve "$ED25519_KEY" > output &&
128 - printf "/ipfs/%s\n" "$CIDv1" > expected2 &&
129 - test_cmp expected2 output
108 +ED25519_KEY=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d
109 +ED25519_IPNS_IDv0=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d
110 +ED25519_IPNS_IDv1=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam
111 +ED25519_IPNS_IDv1_DAGPB=k50rm9yjlt0jey4fqg6wafvqprktgbkpgkqdg27tpqje6iimzxewnhvtin9hhq
112 +IPNS_ED25519_B58MH=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d
113 +IPNS_ED25519_B36CID=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam
114 +
115 +test_expect_success "Add the test fixtures" '
116 + ipfs dag import ../t0114-gateway-subdomains/fixtures.car &&
117 + ipfs routing put --allow-offline /ipns/${RSA_KEY} ../t0114-gateway-subdomains/${RSA_KEY}.ipns-record &&
118 + ipfs routing put --allow-offline /ipns/${ED25519_KEY} ../t0114-gateway-subdomains/${ED25519_KEY}.ipns-record
119 '
120
121 # ensure we start with empty Gateway.PublicGateways
@@ -588,11 +577,6 @@ test_expect_success \
577 ## https://github.com/ipfs/go-ipfs/issues/7318
578 ## ============================================================================
579
591 -# ed25519 fits under 63 char limit when represented in base36
592 -IPNS_KEY="test_key_ed25519"
593 -IPNS_ED25519_B58MH=$(ipfs key list -l --ipns-base b58mh | grep $IPNS_KEY | cut -d" " -f1 | tr -d "\n")
594 -IPNS_ED25519_B36CID=$(ipfs key list -l --ipns-base base36 | grep $IPNS_KEY | cut -d" " -f1 | tr -d "\n")
595 -
580 # local: *.localhost
581 test_localhost_gateway_response_should_contain \
582 "request for a ED25519 libp2p-key at localhost/ipns/{b58mh} returns Location HTTP header for DNS-safe subdomain redirect in browsers" \
test/sharness/t0114-gateway-subdomains/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record
Binary files /dev/null and b/test/sharness/t0114-gateway-subdomains/12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d.ipns-record differ
test/sharness/t0114-gateway-subdomains/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record
Binary files /dev/null and b/test/sharness/t0114-gateway-subdomains/QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3.ipns-record differ
test/sharness/t0114-gateway-subdomains/README.md
+61 -4
@@ -3,10 +3,16 @@
3 - fixtures.car
4 - raw CARv1
5
6 -generated with:
6 +- QmUKd....ipns-record
7 + - ipns record, encoded with protocol buffer
8 +
9 +- 12D3K....ipns-record
10 + - ipns record, encoded with protocol buffer
11 +
12 +Generated with:
13
14 ```sh
9 -# using ipfs version 0.18.1
15 +# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867)
16
17 # CIDv0to1 is necessary because raw-leaves are enabled by default during
18 # "ipfs add" with CIDv1 and disabled with CIDv0
@@ -17,6 +23,7 @@ CIDv0to1=$(echo "$CIDv0" | ipfs cid base32)
23 # sha512 will be over 63char limit, even when represented in Base36
24 CIDv1_TOO_LONG=$(echo $CID_VAL | ipfs add --cid-version 1 --hash sha2-512 -Q)
25
26 +echo CID_VAL=${CID_VAL}
27 echo CIDv1=${CIDv1}
28 echo CIDv0=${CIDv0}
29 echo CIDv0to1=${CIDv0to1}
@@ -32,7 +39,7 @@ echo "I am a txt file" > testdirlisting/api/file.txt &&
39 echo "I am a txt file" > testdirlisting/ipfs/file.txt &&
40 DIR_CID=$(ipfs add -Qr --cid-version 1 testdirlisting)
41
35 -echo DIR_CID=${DIR_CID}
42 +echo DIR_CID=${DIR_CID} # ./testdirlisting
43
44 ipfs files mkdir /t0114/
45 ipfs files cp /ipfs/${CIDv1} /t0114/
@@ -45,10 +52,60 @@ ROOT=`ipfs files stat /t0114/ --hash`
52
53 ipfs dag export ${ROOT} > ./fixtures.car
54
48 -# CID_VAL="hello"
55 +# Then the keys
56 +
57 +KEY_NAME=test_key_rsa_$RANDOM
58 +RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 ${KEY_NAME} | head -n1 | tr -d "\n")
59 +RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0)
60 +RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --mc libp2p-key -b base36)
61 +RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36)
62 +
63 +# publish a record valid for a 100 years
64 +ipfs name publish --key ${KEY_NAME} --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$CIDv1"
65 +ipfs routing get /ipns/${RSA_KEY} > ${RSA_KEY}.ipns-record
66 +
67 +echo RSA_KEY=${RSA_KEY}
68 +echo RSA_IPNS_IDv0=${RSA_IPNS_IDv0}
69 +echo RSA_IPNS_IDv1=${RSA_IPNS_IDv1}
70 +echo RSA_IPNS_IDv1_DAGPB=${RSA_IPNS_IDv1_DAGPB}
71 +
72 +KEY_NAME=test_key_ed25519_$RANDOM
73 +ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 ${KEY_NAME} | head -n1 | tr -d "\n")
74 +ED25519_IPNS_IDv0=$ED25519_KEY
75 +ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=base36 | grep ${KEY_NAME} | cut -d " " -f1 | tr -d "\n")
76 +ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --mc dag-pb)
77 +
78 +# ed25519 fits under 63 char limit when represented in base36
79 +IPNS_ED25519_B58MH=$(ipfs key list -l --ipns-base b58mh | grep $KEY_NAME | cut -d" " -f1 | tr -d "\n")
80 +IPNS_ED25519_B36CID=$(ipfs key list -l --ipns-base base36 | grep $KEY_NAME | cut -d" " -f1 | tr -d "\n")
81 +
82 +# publish a record valid for a 100 years
83 +ipfs name publish --key ${KEY_NAME} --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$CIDv1"
84 +ipfs routing get /ipns/${ED25519_KEY} > ${ED25519_KEY}.ipns-record
85 +
86 +echo ED25519_KEY=${ED25519_KEY}
87 +echo ED25519_IPNS_IDv0=${ED25519_IPNS_IDv0}
88 +echo ED25519_IPNS_IDv1=${ED25519_IPNS_IDv1}
89 +echo ED25519_IPNS_IDv1_DAGPB=${ED25519_IPNS_IDv1_DAGPB}
90 +echo IPNS_ED25519_B58MH=${IPNS_ED25519_B58MH}
91 +echo IPNS_ED25519_B36CID=${IPNS_ED25519_B36CID}
92 +
93 +# CID_VAL=hello
94 # CIDv1=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am
95 # CIDv0=QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN
96 # CIDv0to1=bafybeiffndsajwhk3lwjewwdxqntmjm4b5wxaaanokonsggenkbw6slwk4
97 # CIDv1_TOO_LONG=bafkrgqhhyivzstcz3hhswshfjgy6ertgmnqeleynhwt4dlfsthi4hn7zgh4uvlsb5xncykzapi3ocd4lzogukir6ksdy6wzrnz6ohnv4aglcs
98 # DIR_CID=bafybeiht6dtwk3les7vqm6ibpvz6qpohidvlshsfyr7l5mpysdw2vmbbhe # ./testdirlisting
99 +
100 +# RSA_KEY=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3
101 +# RSA_IPNS_IDv0=QmVujd5Vb7moysJj8itnGufN7MEtPRCNHkKpNuA4onsRa3
102 +# RSA_IPNS_IDv1=k2k4r8m7xvggw5pxxk3abrkwyer625hg01hfyggrai7lk1m63fuihi7w
103 +# RSA_IPNS_IDv1_DAGPB=k2jmtxu61bnhrtj301lw7zizknztocdbeqhxgv76l2q9t36fn9jbzipo
104 +
105 +# ED25519_KEY=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d
106 +# ED25519_IPNS_IDv0=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d
107 +# ED25519_IPNS_IDv1=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam
108 +# ED25519_IPNS_IDv1_DAGPB=k50rm9yjlt0jey4fqg6wafvqprktgbkpgkqdg27tpqje6iimzxewnhvtin9hhq
109 +# IPNS_ED25519_B58MH=12D3KooWLQzUv2FHWGVPXTXSZpdHs7oHbXub2G5WC8Tx4NQhyd2d
110 +# IPNS_ED25519_B36CID=k51qzi5uqu5dk3v4rmjber23h16xnr23bsggmqqil9z2gduiis5se8dht36dam
111 ```
test/sharness/t0116-gateway-cache.sh
+6 -12
@@ -25,24 +25,18 @@ test_launch_ipfs_daemon_without_network
25 # Caching of things like raw blocks, CARs, dag-json and dag-cbor
26 # is tested in their respective suites.
27
28 -# Import test case
29 -# See the static fixtures in ./t0116-gateway-cache/
30 -test_expect_success "Add the test directory" '
31 - ipfs dag import ../t0116-gateway-cache/fixtures.car
32 -'
28 ROOT1_CID=bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui # ./
29 ROOT2_CID=bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii # ./root2
30 ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3
31 ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4
32 FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html
33 +TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe
34
39 -test_expect_success "Prepare IPNS unixfs content path for testing" '
40 - TEST_IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 cache_test_key | head -n1 | tr -d "\n")
41 - ipfs name publish --key cache_test_key --allow-offline -Q "/ipfs/$ROOT1_CID" > name_publish_out &&
42 - test_check_peerid "${TEST_IPNS_ID}" &&
43 - ipfs name resolve "${TEST_IPNS_ID}" > output &&
44 - printf "/ipfs/%s\n" "$ROOT1_CID" > expected &&
45 - test_cmp expected output
35 +# Import test case
36 +# See the static fixtures in ./t0116-gateway-cache/
37 +test_expect_success "Add the test directory" '
38 + ipfs dag import ../t0116-gateway-cache/fixtures.car
39 + ipfs routing put --allow-offline /ipns/${TEST_IPNS_ID} ../t0116-gateway-cache/${TEST_IPNS_ID}.ipns-record
40 '
41
42 # GET /ipfs/
test/sharness/t0116-gateway-cache/README.md
+14 -6
@@ -6,7 +6,8 @@
6 generated with:
7
8 ```sh
9 -# using ipfs version 0.18.1
9 +# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867)
10 +
11 mkdir -p root2/root3/root4 &&
12 echo "hello" > root2/root3/root4/index.html &&
13 ROOT1_CID=$(ipfs add -Qrw --cid-version 1 root2)
@@ -15,11 +16,17 @@ ROOT3_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3 | cut -d "/" -f3)
16 ROOT4_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/root4 | cut -d "/" -f3)
17 FILE_CID=$(ipfs resolve -r /ipfs/$ROOT1_CID/root2/root3/root4/index.html | cut -d "/" -f3)
18
18 -echo ROOT1_CID=${ROOT1_CID}
19 -echo ROOT2_CID=${ROOT2_CID}
20 -echo ROOT3_CID=${ROOT3_CID}
21 -echo ROOT4_CID=${ROOT4_CID}
22 -echo FILE_CID=${FILE_CID}
19 +TEST_IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 cache_test_key | head -n1 | tr -d "\n")
20 +# publish a record valid for a 100 years
21 +ipfs name publish --key cache_test_key --allow-offline -Q --ttl=876600h --lifetime=876600h "/ipfs/$ROOT1_CID"
22 +ipfs routing get /ipns/${TEST_IPNS_ID} > ${TEST_IPNS_ID}.ipns-record
23 +
24 +echo ROOT1_CID=${ROOT1_CID} # ./
25 +echo ROOT2_CID=${ROOT2_CID} # ./root2
26 +echo ROOT3_CID=${ROOT3_CID} # ./root2/root3
27 +echo ROOT4_CID=${ROOT4_CID} # ./root2/root3/root4
28 +echo FILE_CID=${FILE_CID} # ./root2/root3/root4/index.html
29 +echo TEST_IPNS_ID=${TEST_IPNS_ID}
30
31 ipfs dag export ${ROOT1_CID} > ./fixtures.car
32
@@ -28,4 +35,5 @@ ipfs dag export ${ROOT1_CID} > ./fixtures.car
35 # ROOT3_CID=bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja # ./root2/root3
36 # ROOT4_CID=bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q # ./root2/root3/root4
37 # FILE_CID=bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am # ./root2/root3/root4/index.html
38 +# TEST_IPNS_ID=k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe
39 ```
test/sharness/t0116-gateway-cache/k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe.ipns-record
Binary files /dev/null and b/test/sharness/t0116-gateway-cache/k51qzi5uqu5dlxdsdu5fpuu7h69wu4ohp32iwm9pdt9nq3y5rpn3ln9j12zfhe.ipns-record differ
test/sharness/t0123-gateway-json-cbor.sh
+11 -11
@@ -163,6 +163,14 @@ test_expect_success "Add CARs for path traversal and DAG-PB representation tests
163 test_should_contain $DAG_PB_CID import_output
164 '
165
166 +IPNS_ID_DAG_JSON=k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2
167 +IPNS_ID_DAG_CBOR=k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l
168 +
169 +test_expect_success "Add ipns records for path traversal and DAG-PB representation tests" '
170 + ipfs routing put --allow-offline /ipns/${IPNS_ID_DAG_JSON} ../t0123-gateway-json-cbor/${IPNS_ID_DAG_JSON}.ipns-record &&
171 + ipfs routing put --allow-offline /ipns/${IPNS_ID_DAG_CBOR} ../t0123-gateway-json-cbor/${IPNS_ID_DAG_CBOR}.ipns-record
172 +'
173 +
174 test_expect_success "GET DAG-JSON traversal returns 501 if there is path remainder" '
175 curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo?format=dag-json" > curl_output 2>&1 &&
176 test_should_contain "501 Not Implemented" curl_output &&
@@ -197,6 +205,7 @@ test_native_dag () {
205 format=$2
206 disposition=$3
207 CID=$4
208 + IPNS_ID=$5
209
210 # GET without explicit format and Accept: text/html returns raw block
211
@@ -313,15 +322,6 @@ test_native_dag () {
322 # IPNS behavior (should be same as immutable /ipfs, but with different caching headers)
323 # To keep tests small we only confirm payload is the same, and then only test delta around caching headers.
324
316 - test_expect_success "Prepare IPNS with dag-$format" '
317 - IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 ${format}_test_key | head -n1 | tr -d "\n") &&
318 - ipfs name publish --key ${format}_test_key --allow-offline -Q "/ipfs/$CID" > name_publish_out &&
319 - test_check_peerid "${IPNS_ID}" &&
320 - ipfs name resolve "${IPNS_ID}" > output &&
321 - printf "/ipfs/%s\n" "$CID" > expected &&
322 - test_cmp expected output
323 - '
324 -
325 test_expect_success "GET $name from /ipns without explicit format returns the same payload as /ipfs" '
326 curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" -o ipfs_output &&
327 curl -sX GET "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_ID" -o ipns_output &&
@@ -369,8 +369,8 @@ test_native_dag () {
369
370 }
371
372 -test_native_dag "DAG-JSON" "json" "inline" "$DAG_JSON_TRAVERSAL_CID"
373 -test_native_dag "DAG-CBOR" "cbor" "attachment" "$DAG_CBOR_TRAVERSAL_CID"
372 +test_native_dag "DAG-JSON" "json" "inline" "$DAG_JSON_TRAVERSAL_CID" ${IPNS_ID_DAG_JSON}
373 +test_native_dag "DAG-CBOR" "cbor" "attachment" "$DAG_CBOR_TRAVERSAL_CID" ${IPNS_ID_DAG_CBOR}
374
375 test_kill_ipfs_daemon
376
test/sharness/t0123-gateway-json-cbor/README.md
+23 -1
@@ -14,7 +14,8 @@
14 generated with:
15
16 ```sh
17 -# using ipfs version 0.18.1
17 +# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867)
18 +
19 mkdir -p rootDir/ipfs &&
20 mkdir -p rootDir/ipns &&
21 mkdir -p rootDir/api &&
@@ -37,8 +38,29 @@ echo FILE_SIZE=${FILE_SIZE}
38
39 ipfs dag export ${DIR_CID} > fixtures.car
40
41 +DAG_CBOR_TRAVERSAL_CID="bafyreibs4utpgbn7uqegmd2goqz4bkyflre2ek2iwv743fhvylwi4zeeim"
42 +DAG_JSON_TRAVERSAL_CID="baguqeeram5ujjqrwheyaty3w5gdsmoz6vittchvhk723jjqxk7hakxkd47xq"
43 +DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke"
44 +
45 +test_native_dag() {
46 + NAME=$1
47 + CID=$2
48 +
49 + IPNS_ID=$(ipfs key gen --ipns-base=base36 --type=ed25519 ${NAME}_test_key | head -n1 | tr -d "\n")
50 + ipfs name publish --key ${NAME}_test_key --allow-offline --ttl=876600h --lifetime=876600h -Q "/ipfs/${CID}" > name_publish_out
51 +
52 + ipfs routing get /ipns/${IPNS_ID} > ${IPNS_ID}.ipns-record
53 +
54 + echo "IPNS_ID_${NAME}=${IPNS_ID}"
55 +}
56 +
57 +test_native_dag "DAG_JSON" "$DAG_JSON_TRAVERSAL_CID"
58 +test_native_dag "DAG_CBOR" "$DAG_CBOR_TRAVERSAL_CID"
59 +
60 # DIR_CID=bafybeiafyvqlazbbbtjnn6how5d6h6l6rxbqc4qgpbmteaiskjrffmyy4a # ./rootDir
61 # FILE_JSON_CID=bafkreibrppizs3g7axs2jdlnjua6vgpmltv7k72l7v7sa6mmht6mne3qqe # ./rootDir/ą/ę/t.json
62 # FILE_CID=bafkreialihlqnf5uwo4byh4n3cmwlntwqzxxs2fg5vanqdi3d7tb2l5xkm # ./rootDir/ą/ę/file-źł.txt
63 # FILE_SIZE=34
64 +# IPNS_ID_DAG_JSON=k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2
65 +# IPNS_ID_DAG_CBOR=k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l
66 ```
test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record
Binary files /dev/null and b/test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dghjous0agrwavl8vzl64xckoqzwqeqwudfr74kfd11zcyk3b7l.ipns-record differ
test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record
Binary files /dev/null and b/test/sharness/t0123-gateway-json-cbor/k51qzi5uqu5dhjghbwdvbo6mi40htrq6e2z4pwgp15pgv3ho1azvidttzh8yy2.ipns-record differ
test/sharness/t0124-gateway-ipns-record.sh
+11 -5
@@ -7,10 +7,16 @@ test_description="Test HTTP Gateway IPNS Record (application/vnd.ipfs.ipns-recor
7 test_init_ipfs
8 test_launch_ipfs_daemon
9
10 +# Import test case
11 +# See the static fixtures in ./t0124-gateway-ipns-record/
12 +IPNS_KEY=k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab
13 +FILE_CID=bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244 # A file containing Hello IPFS
14 +test_expect_success "Add the test directory & IPNS records" '
15 + ipfs dag import ../t0124-gateway-ipns-record/fixtures.car &&
16 + ipfs routing put /ipns/${IPNS_KEY} ../t0124-gateway-ipns-record/${IPNS_KEY}.ipns-record
17 +'
18 +
19 test_expect_success "Create and Publish IPNS Key" '
11 - FILE_CID=$(echo "Hello IPFS" | ipfs add --cid-version 1 -q) &&
12 - IPNS_KEY=$(ipfs key gen ipns-record) &&
13 - ipfs name publish /ipfs/$FILE_CID --key=ipns-record --ttl=30m &&
20 curl "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY" > curl_output_filename &&
21 test_should_contain "Hello IPFS" curl_output_filename
22 '
@@ -31,14 +37,14 @@ test_expect_success "GET KEY with format=ipns-record has expected HTTP headers"
37 curl -sD - "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY?format=ipns-record" > curl_output_filename 2>&1 &&
38 test_should_contain "Content-Disposition: attachment;" curl_output_filename &&
39 test_should_contain "Content-Type: application/vnd.ipfs.ipns-record" curl_output_filename &&
34 - test_should_contain "Cache-Control: public, max-age=1800" curl_output_filename
40 + test_should_contain "Cache-Control: public, max-age=3155760000" curl_output_filename
41 '
42
43 test_expect_success "GET KEY with 'Accept: application/vnd.ipfs.ipns-record' has expected HTTP headers" '
44 curl -H "Accept: application/vnd.ipfs.ipns-record" -sD - "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_KEY" > curl_output_filename 2>&1 &&
45 test_should_contain "Content-Disposition: attachment;" curl_output_filename &&
46 test_should_contain "Content-Type: application/vnd.ipfs.ipns-record" curl_output_filename &&
41 - test_should_contain "Cache-Control: public, max-age=1800" curl_output_filename
47 + test_should_contain "Cache-Control: public, max-age=3155760000" curl_output_filename
48 '
49
50 test_expect_success "GET KEY with expliciy ?filename= succeeds with modified Content-Disposition header" '
test/sharness/t0124-gateway-ipns-record/README.md new
+27
@@ -0,0 +1,27 @@
1 +# Dataset description/sources
2 +
3 +- fixtures.car
4 + - raw CARv1
5 +
6 +- k51....ipns-record
7 + - ipns record, encoded with protocol buffer
8 +
9 +generated with:
10 +
11 +```sh
12 +# using ipfs version 0.21.0-dev (03a98280e3e642774776cd3d0435ab53e5dfa867)
13 +FILE_CID=$(echo "Hello IPFS" | ipfs add --cid-version 1 -q)
14 +IPNS_KEY=$(ipfs key gen ipns-record)
15 +
16 +ipfs dag export ${FILE_CID} > fixtures.car
17 +
18 +# publish a record valid for a 100 years
19 +ipfs name publish --key=ipns-record --quieter --ttl=876600h --lifetime=876600h /ipfs/${FILE_CID}
20 +ipfs routing get /ipns/${IPNS_KEY} > ${IPNS_KEY}.ipns-record
21 +
22 +echo IPNS_KEY=${IPNS_KEY}
23 +echo FILE_CID=${FILE_CID} # A file containing "Hello IPFS"
24 +
25 +# IPNS_KEY=k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab
26 +# FILE_CID=bafkreidfdrlkeq4m4xnxuyx6iae76fdm4wgl5d4xzsb77ixhyqwumhz244 # A file containing Hello IPFS
27 +```
test/sharness/t0124-gateway-ipns-record/fixtures.car
Binary files /dev/null and b/test/sharness/t0124-gateway-ipns-record/fixtures.car differ
test/sharness/t0124-gateway-ipns-record/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record
Binary files /dev/null and b/test/sharness/t0124-gateway-ipns-record/k51qzi5uqu5dh71qgwangrt6r0nd4094i88nsady6qgd1dhjcyfsaqmpp143ab.ipns-record differ