From 942a53a700569741690d983d8406b0bc96f497d8 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Mon, 27 Mar 2023 16:46:12 +0200 Subject: [PATCH] feat: test plain code (broken) --- fixtures/t0123/plain-that-can-be-dag.cbor.car | Bin 0 -> 140 bytes fixtures/t0123/plain-that-can-be-dag.json.car | Bin 0 -> 150 bytes fixtures/t0123/plain.cbor.car | Bin 0 -> 113 bytes fixtures/t0123/plain.json.car | Bin 0 -> 124 bytes tests/t0123_gateway_json_cbor_test.go | 149 ++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 fixtures/t0123/plain-that-can-be-dag.cbor.car create mode 100644 fixtures/t0123/plain-that-can-be-dag.json.car create mode 100644 fixtures/t0123/plain.cbor.car create mode 100644 fixtures/t0123/plain.json.car diff --git a/fixtures/t0123/plain-that-can-be-dag.cbor.car b/fixtures/t0123/plain-that-can-be-dag.cbor.car new file mode 100644 index 0000000000000000000000000000000000000000..1091dd95ed967afcfd2ddd2999c3c3eb4a293a51 GIT binary patch literal 140 zcmcColvA$zIbN$x49A1rj<^S3c-M}1G?s{b5&wQRCPZYnIe z&NMZ>EVZaOGe3_pfEd*aQ%X{cODa?fauPH1bhC={^K?rx5=(TG6Z3QvbBgnIlTvk4 I64Svl0K@b{ zmBq^GWvNBQnfZB)kwhu4=HgT;Ni8l>vQkhg$Vtr1)6FW*&(kf*NG#D!PR!Fy%qh;- RO-j{GNlXXJC~?(t0RZ#jH@5%) literal 0 HcmV?d00001 diff --git a/fixtures/t0123/plain.cbor.car b/fixtures/t0123/plain.cbor.car new file mode 100644 index 0000000000000000000000000000000000000000..e92c6ded06e266402fc5b154dead3563775e46c6 GIT binary patch literal 113 zcmcColvVK2iooFH0>d&dkqav?oe=H5aE+NosM4l9hr|K~7?3o curl_output 2>&1 && + ipfs block get $CID > ipfs_block_output 2>&1 && + test_cmp ipfs_block_output curl_output && + test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && + test_should_contain "Content-Type: application/$format" headers + ' + */ + { + Name: fmt.Sprintf("GET %s without Accept or format= has expected %s Content-Type and body as-is", row.Name, row.Format), + Hint: ` + No explicit format, just codec in CID + `, + Request: Request(). + Path("ipfs/%s", plainCID), + Response: Expect(). + Status(200). + Headers( + Header("Content-Disposition"). + Equals(fmt.Sprintf("%s; filename=\"%s.%s\"", row.Disposition, plainCID, row.Format)), + Header("Content-Type"). + Equals(fmt.Sprintf("application/%s", row.Format)), + ).Body( + plainFixture.MustGetRawData(), + ), + }, + /** + # explicit format still gives correct output, just codec in CID + test_expect_success "GET $name with ?format= has expected $format Content-Type and body as-is" ' + CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && + curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=$format" > curl_output 2>&1 && + ipfs block get $CID > ipfs_block_output 2>&1 && + test_cmp ipfs_block_output curl_output && + test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && + test_should_contain "Content-Type: application/$format" headers + ' + */ + { + Name: fmt.Sprintf("GET %s with ?format= has expected %s Content-Type and body as-is", row.Name, row.Format), + Hint: ` + Explicit format still gives correct output, just codec in CID + `, + Request: Request(). + Path("ipfs/%s", plainCID). + Query("format", row.Format), + Response: Expect(). + Status(200). + Headers( + Header("Content-Disposition"). + Equals(fmt.Sprintf("%s; filename=\"%s.%s\"", row.Disposition, plainCID, row.Format)), + Header("Content-Type"). + Equals(fmt.Sprintf("application/%s", row.Format)), + ).Body( + plainFixture.MustGetRawData(), + ), + }, + /** + # explicit format still gives correct output, just codec in CID + test_expect_success "GET $name with Accept has expected $format Content-Type and body as-is" ' + CID=$(echo "{ \"test\": \"plain json\" }" | ipfs dag put --input-codec json --store-codec $format) && + curl -sD headers -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output 2>&1 && + ipfs block get $CID > ipfs_block_output 2>&1 && + test_cmp ipfs_block_output curl_output && + test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && + test_should_contain "Content-Type: application/$format" headers + ' + */ + { + Name: fmt.Sprintf("GET %s with Accept has expected %s Content-Type and body as-is", row.Name, row.Format), + Hint: ` + Explicit format still gives correct output, just codec in CID + `, + Request: Request(). + Path("ipfs/%s", plainCID). + Header("Accept", fmt.Sprintf("application/%s", row.Format)), + Response: Expect(). + Status(200). + Headers( + Header("Content-Disposition"). + Equals(fmt.Sprintf("%s; filename=\"%s.%s\"", row.Disposition, plainCID, row.Format)), + Header("Content-Type"). + Equals(fmt.Sprintf("application/%s", row.Format)), + ).Body( + plainFixture.MustGetRawData(), + ), + }, + /** + # explicit dag-* format passed, attempt to parse as dag* variant + ## Note: this works only for simple JSON that can be upgraded to DAG-JSON. + test_expect_success "GET $name with format=dag-$format interprets $format as dag-* variant and produces expected Content-Type and body" ' + CID=$(echo "{ \"test\": \"plain-json-that-can-also-be-dag-json\" }" | ipfs dag put --input-codec json --store-codec $format) && + curl -sD headers "http://127.0.0.1:$GWAY_PORT/ipfs/$CID?format=dag-$format" > curl_output_param 2>&1 && + ipfs dag get --output-codec dag-$format $CID > ipfs_dag_get_output 2>&1 && + test_cmp ipfs_dag_get_output curl_output_param && + test_should_contain "Content-Disposition: ${disposition}\; filename=\"${CID}.${format}\"" headers && + test_should_contain "Content-Type: application/vnd.ipld.dag-$format" headers && + curl -s -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$CID" > curl_output_accept 2>&1 && + test_cmp curl_output_param curl_output_accept + ' + */ + { + Name: fmt.Sprintf("GET %s with format=dag-%s interprets %s as dag-* variant and produces expected Content-Type and body", row.Name, row.Format, row.Format), + Hint: ` + Explicit dag-* format passed, attempt to parse as dag* variant + Note: this works only for simple JSON that can be upgraded to DAG-JSON. + `, + Request: Request(). + Path("ipfs/%s", plainOrDagCID). + Query("format", fmt.Sprintf("dag-%s", row.Format)), + Response: Expect(). + Status(200). + Headers( + Header("Content-Disposition"). + Equals(fmt.Sprintf("%s; filename=\"%s.%s\"", row.Disposition, plainOrDagCID, row.Format)), + Header("Content-Type"). + Equals(fmt.Sprintf("application/vnd.ipld.dag-%s", row.Format)), + ).Body( + plainFixture.MustGetRawData(), + ), + }, + } + + test.Run(t, tests.Build()) + } +}