From 2e5a05dc8fee068e5004161479304ae9160b5cbe Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 19 Oct 2022 15:49:18 +0200 Subject: [PATCH] test: path traversal and dag-pb output --- test/sharness/t0123-gateway-json-cbor.sh | 67 ++++++++++++++---- .../dag-cbor-traversal.car | Bin 0 -> 288 bytes .../dag-json-traversal.car | Bin 0 -> 358 bytes .../t0123-gateway-json-cbor/dag-pb.car | Bin 0 -> 392 bytes .../t0123-gateway-json-cbor/dag-pb.json | 23 ++++++ 5 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 test/sharness/t0123-gateway-json-cbor/dag-cbor-traversal.car create mode 100644 test/sharness/t0123-gateway-json-cbor/dag-json-traversal.car create mode 100644 test/sharness/t0123-gateway-json-cbor/dag-pb.car create mode 100644 test/sharness/t0123-gateway-json-cbor/dag-pb.json diff --git a/test/sharness/t0123-gateway-json-cbor.sh b/test/sharness/t0123-gateway-json-cbor.sh index ac446c3df7f4..831b5f82eadb 100755 --- a/test/sharness/t0123-gateway-json-cbor.sh +++ b/test/sharness/t0123-gateway-json-cbor.sh @@ -22,57 +22,65 @@ test_expect_success "Add the test directory" ' echo "$FILE_CID / $FILE_SIZE" ' -test_codec_unixfs () { +test_headers () { name=$1 format=$2 - test_expect_success "GET UnixFS $name with format=dag-$format has expected Content-Type" ' + test_expect_success "GET $name with format=dag-$format has expected Content-Type" ' curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 && test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output && test_should_not_contain "Content-Type: application/$format" curl_output ' - test_expect_success "GET UnixFS $name with 'Accept: application/vnd.ipld.dag-$format' has expected Content-Type" ' + test_expect_success "GET $name with 'Accept: application/vnd.ipld.dag-$format' has expected Content-Type" ' curl -sD - -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output && test_should_not_contain "Content-Type: application/$format" curl_output ' - test_expect_success "GET UnixFS $name with format=$format has expected Content-Type" ' + test_expect_success "GET $name with format=$format has expected Content-Type" ' curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=$format" > curl_output 2>&1 && test_should_contain "Content-Type: application/$format" curl_output && test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output ' - test_expect_success "GET UnixFS $name with 'Accept: application/$format' has expected Content-Type" ' + test_expect_success "GET $name with 'Accept: application/$format' has expected Content-Type" ' curl -sD - -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && test_should_contain "Content-Type: application/$format" curl_output && test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output ' +} + +test_headers "DAG-JSON" "json" +test_headers "DAG-CBOR" "cbor" - test_expect_success "GET UnixFS $name has expected output for file" ' +test_dag_pb () { + name=$1 + format=$2 + + test_expect_success "GET DAG-PB $name has expected output for file" ' curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 && ipfs dag get --output-codec dag-$format $FILE_CID > ipfs_dag_get_output 2>&1 && test_cmp ipfs_dag_get_output curl_output ' - test_expect_success "GET UnixFS $name has expected output for directory" ' + test_expect_success "GET DAG-PB $name has expected output for directory" ' curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output 2>&1 && ipfs dag get --output-codec dag-$format $DIR_CID > ipfs_dag_get_output 2>&1 && test_cmp ipfs_dag_get_output curl_output ' - test_expect_success "GET UnixFS $name with format=dag-$format and format=$format produce same output" ' + test_expect_success "GET DAG-PB $name with format=dag-$format and format=$format produce same output" ' curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output_1 2>&1 && curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=$format" > curl_output_2 2>&1 && test_cmp curl_output_1 curl_output_2 ' } -test_codec_unixfs "DAG-JSON" "json" -test_codec_unixfs "DAG-CBOR" "cbor" +test_dag_pb "DAG-JSON" "json" +test_dag_pb "DAG-CBOR" "cbor" -test_codec () { +test_cmp_dag_get () { name=$1 format=$2 @@ -91,8 +99,8 @@ test_codec () { ' } -test_codec "JSON" "json" -test_codec "CBOR" "cbor" +test_cmp_dag_get "JSON" "json" +test_cmp_dag_get "CBOR" "cbor" test_expect_success "GET JSON as CBOR produces DAG-CBOR output" ' CID=$(echo "{ \"test\": \"json\" }" | ipfs dag put --input-codec json --store-codec json) && @@ -108,6 +116,39 @@ test_expect_success "GET CBOR as JSON produces DAG-JSON output" ' test_cmp ipfs_dag_get_output curl_output ' +DAG_CBOR_TRAVERSAL_CID="bafyreiehxu373cu3v5gyxyxfsfjryscs7sq6fh3unqcqgqhdfn3n43vrgu" +DAG_JSON_TRAVERSAL_CID="baguqeeraoaeabj5hdfcmpkzfeiwtfwb3qbvfwzbiknqn7itcwsb2fdtu7eta" +DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke" + +test_expect_success "Add CARs for path traversal and DAG-PB representation tests" ' + ipfs dag import ../t0123-gateway-json-cbor/dag-cbor-traversal.car > import_output && + test_should_contain $DAG_CBOR_TRAVERSAL_CID import_output && + ipfs dag import ../t0123-gateway-json-cbor/dag-json-traversal.car > import_output && + test_should_contain $DAG_JSON_TRAVERSAL_CID import_output && + ipfs dag import ../t0123-gateway-json-cbor/dag-pb.car > import_output && + test_should_contain $DAG_PB_CID import_output +' + +test_expect_success "GET DAG-JSON traverses multiple links" ' + curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/bar?format=dag-json" > curl_output 2>&1 && + jq --sort-keys . curl_output > actual && + echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected && + test_cmp expected actual +' + +test_expect_success "GET DAG-CBOR traverses multiple links" ' + curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/bar?format=dag-json" > curl_output 2>&1 && + jq --sort-keys . curl_output > actual && + echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected && + test_cmp expected actual +' + +test_expect_success "GET DAG-PB has expected output" ' + curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_PB_CID?format=dag-json" > curl_output 2>&1 && + jq --sort-keys . curl_output > actual && + test_cmp ../t0123-gateway-json-cbor/dag-pb.json actual +' + test_kill_ipfs_daemon test_done \ No newline at end of file diff --git a/test/sharness/t0123-gateway-json-cbor/dag-cbor-traversal.car b/test/sharness/t0123-gateway-json-cbor/dag-cbor-traversal.car new file mode 100644 index 0000000000000000000000000000000000000000..40a0cd4013aea796f43ebb6296467ddc6870bb6b GIT binary patch literal 288 zcmcColv%u~eY+n$ofs_R5%g!_qxmH{tjrFNwaf11 zZ8S|UOD!tS%+F&CB1ZMX7^PH1FSG4-(A7cOxGHCCzW&B;+b`afe|8{O f5>m7p9BePfmi1PAF6cQD3GV`(l3b}in literal 0 HcmV?d00001 diff --git a/test/sharness/t0123-gateway-json-cbor/dag-json-traversal.car b/test/sharness/t0123-gateway-json-cbor/dag-json-traversal.car new file mode 100644 index 0000000000000000000000000000000000000000..fa56006d5f4ec6a6bb3fd4e4b46afb7df2eccde7 GIT binary patch literal 358 zcmcCslvCux`kTPSFTXxW6cAOY@?> zlAmhnWvNBQnfZB)MMNpDR!YmySF);B(pR!lN=i&GElf=pc0V zwZ?Jz%WkJ>wzbd7+;qtLdw$5V(g!?$tAX|uVOW_|Wt5*$T9H$fmY$erTwGCi+sBr4=&=4C6@0suiPjIsa# literal 0 HcmV?d00001 diff --git a/test/sharness/t0123-gateway-json-cbor/dag-pb.car b/test/sharness/t0123-gateway-json-cbor/dag-pb.car new file mode 100644 index 0000000000000000000000000000000000000000..a6bb076c7e323e449dfe3f6290adbe7e3826cf21 GIT binary patch literal 392 zcmcColv6N9G>c!tg+FvpA8Lzlk~eSLZrIRuTwwE~hlf;U z76qo4r4|)u=I1eXF%qL(NS8|mq^|IQa`O8b2I)OECVzyMewgCAPNpIter34l*}|*5 zT4#fWnA7s}C0vCJfyzUL6rzjWn-?3Nly$m#PLi+f!g;?F8kf!m7^ME`R`a{7@j*j~ z9jIKdq@qNEmy3ymF`6hVpl07>^l?*Z@mjj;ut>RWcE+qL>A(DBr2-c2SUERp>UaIG uLhMP2MPRe}KxP|(+(Sr@M`}(^zK%k9eo;<}B9|dCUVv)x3~&op