Skip to content

Commit 2e5a05d

Browse files
committed
test: path traversal and dag-pb output
1 parent 9eba2a9 commit 2e5a05d

File tree

5 files changed

+77
-13
lines changed

5 files changed

+77
-13
lines changed

test/sharness/t0123-gateway-json-cbor.sh

+54-13
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,65 @@ test_expect_success "Add the test directory" '
2222
echo "$FILE_CID / $FILE_SIZE"
2323
'
2424

25-
test_codec_unixfs () {
25+
test_headers () {
2626
name=$1
2727
format=$2
2828

29-
test_expect_success "GET UnixFS $name with format=dag-$format has expected Content-Type" '
29+
test_expect_success "GET $name with format=dag-$format has expected Content-Type" '
3030
curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 &&
3131
test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output &&
3232
test_should_not_contain "Content-Type: application/$format" curl_output
3333
'
3434

35-
test_expect_success "GET UnixFS $name with 'Accept: application/vnd.ipld.dag-$format' has expected Content-Type" '
35+
test_expect_success "GET $name with 'Accept: application/vnd.ipld.dag-$format' has expected Content-Type" '
3636
curl -sD - -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 &&
3737
test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output &&
3838
test_should_not_contain "Content-Type: application/$format" curl_output
3939
'
4040

41-
test_expect_success "GET UnixFS $name with format=$format has expected Content-Type" '
41+
test_expect_success "GET $name with format=$format has expected Content-Type" '
4242
curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=$format" > curl_output 2>&1 &&
4343
test_should_contain "Content-Type: application/$format" curl_output &&
4444
test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output
4545
'
4646

47-
test_expect_success "GET UnixFS $name with 'Accept: application/$format' has expected Content-Type" '
47+
test_expect_success "GET $name with 'Accept: application/$format' has expected Content-Type" '
4848
curl -sD - -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 &&
4949
test_should_contain "Content-Type: application/$format" curl_output &&
5050
test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output
5151
'
52+
}
53+
54+
test_headers "DAG-JSON" "json"
55+
test_headers "DAG-CBOR" "cbor"
5256

53-
test_expect_success "GET UnixFS $name has expected output for file" '
57+
test_dag_pb () {
58+
name=$1
59+
format=$2
60+
61+
test_expect_success "GET DAG-PB $name has expected output for file" '
5462
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 &&
5563
ipfs dag get --output-codec dag-$format $FILE_CID > ipfs_dag_get_output 2>&1 &&
5664
test_cmp ipfs_dag_get_output curl_output
5765
'
5866

59-
test_expect_success "GET UnixFS $name has expected output for directory" '
67+
test_expect_success "GET DAG-PB $name has expected output for directory" '
6068
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output 2>&1 &&
6169
ipfs dag get --output-codec dag-$format $DIR_CID > ipfs_dag_get_output 2>&1 &&
6270
test_cmp ipfs_dag_get_output curl_output
6371
'
6472

65-
test_expect_success "GET UnixFS $name with format=dag-$format and format=$format produce same output" '
73+
test_expect_success "GET DAG-PB $name with format=dag-$format and format=$format produce same output" '
6674
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output_1 2>&1 &&
6775
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=$format" > curl_output_2 2>&1 &&
6876
test_cmp curl_output_1 curl_output_2
6977
'
7078
}
7179

72-
test_codec_unixfs "DAG-JSON" "json"
73-
test_codec_unixfs "DAG-CBOR" "cbor"
80+
test_dag_pb "DAG-JSON" "json"
81+
test_dag_pb "DAG-CBOR" "cbor"
7482

75-
test_codec () {
83+
test_cmp_dag_get () {
7684
name=$1
7785
format=$2
7886

@@ -91,8 +99,8 @@ test_codec () {
9199
'
92100
}
93101

94-
test_codec "JSON" "json"
95-
test_codec "CBOR" "cbor"
102+
test_cmp_dag_get "JSON" "json"
103+
test_cmp_dag_get "CBOR" "cbor"
96104

97105
test_expect_success "GET JSON as CBOR produces DAG-CBOR output" '
98106
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" '
108116
test_cmp ipfs_dag_get_output curl_output
109117
'
110118

119+
DAG_CBOR_TRAVERSAL_CID="bafyreiehxu373cu3v5gyxyxfsfjryscs7sq6fh3unqcqgqhdfn3n43vrgu"
120+
DAG_JSON_TRAVERSAL_CID="baguqeeraoaeabj5hdfcmpkzfeiwtfwb3qbvfwzbiknqn7itcwsb2fdtu7eta"
121+
DAG_PB_CID="bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke"
122+
123+
test_expect_success "Add CARs for path traversal and DAG-PB representation tests" '
124+
ipfs dag import ../t0123-gateway-json-cbor/dag-cbor-traversal.car > import_output &&
125+
test_should_contain $DAG_CBOR_TRAVERSAL_CID import_output &&
126+
ipfs dag import ../t0123-gateway-json-cbor/dag-json-traversal.car > import_output &&
127+
test_should_contain $DAG_JSON_TRAVERSAL_CID import_output &&
128+
ipfs dag import ../t0123-gateway-json-cbor/dag-pb.car > import_output &&
129+
test_should_contain $DAG_PB_CID import_output
130+
'
131+
132+
test_expect_success "GET DAG-JSON traverses multiple links" '
133+
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/bar?format=dag-json" > curl_output 2>&1 &&
134+
jq --sort-keys . curl_output > actual &&
135+
echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected &&
136+
test_cmp expected actual
137+
'
138+
139+
test_expect_success "GET DAG-CBOR traverses multiple links" '
140+
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/bar?format=dag-json" > curl_output 2>&1 &&
141+
jq --sort-keys . curl_output > actual &&
142+
echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected &&
143+
test_cmp expected actual
144+
'
145+
146+
test_expect_success "GET DAG-PB has expected output" '
147+
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_PB_CID?format=dag-json" > curl_output 2>&1 &&
148+
jq --sort-keys . curl_output > actual &&
149+
test_cmp ../t0123-gateway-json-cbor/dag-pb.json actual
150+
'
151+
111152
test_kill_ipfs_daemon
112153

113154
test_done
Binary file not shown.
Binary file not shown.
392 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"Data": {
3+
"/": {
4+
"bytes": "CAE"
5+
}
6+
},
7+
"Links": [
8+
{
9+
"Hash": {
10+
"/": "bafybeidryarwh34ygbtyypbu7qjkl4euiwxby6cql6uvosonohkq2kwnkm"
11+
},
12+
"Name": "foo",
13+
"Tsize": 69
14+
},
15+
{
16+
"Hash": {
17+
"/": "bafkreic3ondyhizrzeoufvoodehinugpj3ecruwokaygl7elezhn2khqfa"
18+
},
19+
"Name": "foo.txt",
20+
"Tsize": 13
21+
}
22+
]
23+
}

0 commit comments

Comments
 (0)