Skip to content

Commit 887de89

Browse files
lidelaschmahmann
authored andcommitted
test(gateway): breadcrumb links in dir listing
This adds subdomain tests for breadcrumbs added in: #7536 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent 8ffb7ec commit 887de89

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

test/sharness/t0114-gateway-subdomains.sh

+22-14
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ test_expect_success "Add test text file" '
101101
echo CIDv0to1=${CIDv0to1}
102102
'
103103

104+
# Directory tree crafted to test for edge cases like "/ipfs/ipfs/ipns/bar"
104105
test_expect_success "Add the test directory" '
105-
mkdir -p testdirlisting/subdir1/subdir2 &&
106+
mkdir -p testdirlisting/ipfs/ipns &&
106107
echo "hello" > testdirlisting/hello &&
107-
echo "subdir2-bar" > testdirlisting/subdir1/subdir2/bar &&
108+
echo "text-file-content" > testdirlisting/ipfs/ipns/bar &&
108109
mkdir -p testdirlisting/api &&
109110
mkdir -p testdirlisting/ipfs &&
110111
echo "I am a txt file" > testdirlisting/api/file.txt &&
@@ -269,18 +270,18 @@ DIR_HOSTNAME="${DIR_CID}.ipfs.localhost:$GWAY_PORT"
269270
test_expect_success "valid file and subdirectory paths in directory listing at {cid}.ipfs.localhost" '
270271
curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME" > list_response &&
271272
test_should_contain "<a href=\"/hello\">hello</a>" list_response &&
272-
test_should_contain "<a href=\"/subdir1\">subdir1</a>" list_response
273+
test_should_contain "<a href=\"/ipfs\">ipfs</a>" list_response
273274
'
274275

275276
test_expect_success "valid parent directory path in directory listing at {cid}.ipfs.localhost/sub/dir" '
276-
curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/subdir1/subdir2/" > list_response &&
277-
test_should_contain "<a href=\"/subdir1/subdir2/./..\">..</a>" list_response &&
278-
test_should_contain "<a href=\"/subdir1/subdir2/bar\">bar</a>" list_response
277+
curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/ipfs/ipns/" > list_response &&
278+
test_should_contain "<a href=\"/ipfs/ipns/./..\">..</a>" list_response &&
279+
test_should_contain "<a href=\"/ipfs/ipns/bar\">bar</a>" list_response
279280
'
280281

281282
test_expect_success "request for deep path resource at {cid}.ipfs.localhost/sub/dir/file" '
282-
curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/subdir1/subdir2/bar" > list_response &&
283-
test_should_contain "subdir2-bar" list_response
283+
curl -s --resolve $DIR_HOSTNAME:127.0.0.1 "http://$DIR_HOSTNAME/ipfs/ipns/bar" > list_response &&
284+
test_should_contain "text-file-content" list_response
284285
'
285286

286287

@@ -422,18 +423,25 @@ DIR_FQDN="${DIR_CID}.ipfs.example.com"
422423
test_expect_success "valid file and directory paths in directory listing at {cid}.ipfs.example.com" '
423424
curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT > list_response &&
424425
test_should_contain "<a href=\"/hello\">hello</a>" list_response &&
425-
test_should_contain "<a href=\"/subdir1\">subdir1</a>" list_response
426+
test_should_contain "<a href=\"/ipfs\">ipfs</a>" list_response
426427
'
427428

428429
test_expect_success "valid parent directory path in directory listing at {cid}.ipfs.example.com/sub/dir" '
429-
curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/subdir1/subdir2/ > list_response &&
430-
test_should_contain "<a href=\"/subdir1/subdir2/./..\">..</a>" list_response &&
431-
test_should_contain "<a href=\"/subdir1/subdir2/bar\">bar</a>" list_response
430+
curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/ > list_response &&
431+
test_should_contain "<a href=\"/ipfs/ipns/./..\">..</a>" list_response &&
432+
test_should_contain "<a href=\"/ipfs/ipns/bar\">bar</a>" list_response
433+
'
434+
435+
# Note we test for sneaky subdir names {cid}.ipfs.example.com/ipfs/ipns/ :^)
436+
test_expect_success "valid breadcrumb links in the header of directory listing at {cid}.ipfs.example.com/sub/dir" '
437+
curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/ > list_response &&
438+
test_should_contain "Index of" list_response &&
439+
test_should_contain "/ipfs/<a href=\"//example.com/ipfs/${DIR_CID}\">${DIR_CID}</a>/<a href=\"//example.com/ipfs/${DIR_CID}/ipfs\">ipfs</a>/<a href=\"//example.com/ipfs/${DIR_CID}/ipfs/ipns\">ipns</a>" list_response
432440
'
433441

434442
test_expect_success "request for deep path resource {cid}.ipfs.example.com/sub/dir/file" '
435-
curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/subdir1/subdir2/bar > list_response &&
436-
test_should_contain "subdir2-bar" list_response
443+
curl -s -H "Host: $DIR_FQDN" http://127.0.0.1:$GWAY_PORT/ipfs/ipns/bar > list_response &&
444+
test_should_contain "text-file-content" list_response
437445
'
438446

439447
# *.ipns.example.com

0 commit comments

Comments
 (0)