repeat gateway subdomain test for all key types (#7542)
* repeat gateway subdomain test for all key types Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
Petar Maymounkov committed
Jul 20, 2020 at 10:20 UTC
6eb5db7e64a0736cd96461d3b622e20a2fbc7866
1 file changed
+85
-26
test/sharness/t0114-gateway-subdomains.sh
+85
-26
@@ -84,7 +84,11 @@ test_hostname_gateway_response_should_contain() {
84
## Start IPFS Node and prepare test CIDs
85
## ============================================================================
86
87
-test_init_ipfs
87
+test_expect_success "ipfs init" '
88
+ export IPFS_PATH="$(pwd)/.ipfs" &&
89
+ ipfs init --profile=test > /dev/null
90
+'
91
+
92
test_launch_ipfs_daemon --offline
93
94
# CIDv0to1 is necessary because raw-leaves are enabled by default during
@@ -109,25 +113,25 @@ test_expect_success "Add the test directory" '
113
'
114
115
test_expect_success "Publish test text file to IPNS using RSA keys" '
112
- PEERID=$(ipfs key gen -f=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n")
113
- IPNS_IDv0=$(echo "$PEERID" | ipfs cid format -v 0)
114
- IPNS_IDv1=$(echo "$PEERID" | ipfs cid format -v 1 --codec libp2p-key -b base36)
115
- IPNS_IDv1_DAGPB=$(echo "$IPNS_IDv0" | ipfs cid format -v 1 -b base36)
116
- test_check_peerid "${PEERID}" &&
116
+ RSA_KEY=$(ipfs key gen -f=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n")
117
+ RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0)
118
+ RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --codec libp2p-key -b base36)
119
+ RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36)
120
+ test_check_peerid "${RSA_KEY}" &&
121
ipfs name publish --key test_key_rsa --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out &&
118
- ipfs name resolve "$PEERID" > output &&
122
+ ipfs name resolve "$RSA_KEY" > output &&
123
printf "/ipfs/%s\n" "$CIDv1" > expected2 &&
124
test_cmp expected2 output
125
'
126
127
test_expect_success "Publish test text file to IPNS using ED25519 keys" '
124
- PEERID=$(ipfs key gen -f=b36cid --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n") &&
125
- IPNS_IDv0=$PEERID
126
- IPNS_IDv1=$PEERID
127
- IPNS_IDv1_DAGPB=$(echo "$IPNS_IDv0" | ipfs cid format -v 1 -b base32)
128
- test_check_peerid "${PEERID}" &&
128
+ ED25519_KEY=$(ipfs key gen -f=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n")
129
+ ED25519_IPNS_IDv0=$ED25519_KEY
130
+ ED25519_IPNS_IDv1=$(ipfs key list -l -f b36cid | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n")
131
+ ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --codec protobuf)
132
+ test_check_peerid "${ED25519_KEY}" &&
133
ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out &&
130
- ipfs name resolve "$PEERID" > output &&
134
+ ipfs name resolve "$ED25519_KEY" > output &&
135
printf "/ipfs/%s\n" "$CIDv1" > expected2 &&
136
test_cmp expected2 output
137
'
@@ -201,8 +205,13 @@ test_localhost_gateway_response_should_contain \
205
206
test_localhost_gateway_response_should_contain \
207
"request for localhost/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \
204
- "http://localhost:$GWAY_PORT/ipns/$IPNS_IDv0" \
205
- "Location: http://${IPNS_IDv1}.ipns.localhost:$GWAY_PORT/"
208
+ "http://localhost:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \
209
+ "Location: http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/"
210
+
211
+test_localhost_gateway_response_should_contain \
212
+ "request for localhost/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \
213
+ "http://localhost:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \
214
+ "Location: http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/"
215
216
# /ipns/<dnslink-fqdn>
217
@@ -281,13 +290,23 @@ test_expect_success "request for deep path resource at {cid}.ipfs.localhost/sub/
290
291
test_localhost_gateway_response_should_contain \
292
"request for {CIDv1-libp2p-key}.ipns.localhost returns expected payload" \
284
- "http://${IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \
293
+ "http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \
294
+ "$CID_VAL"
295
+
296
+test_localhost_gateway_response_should_contain \
297
+ "request for {CIDv1-libp2p-key}.ipns.localhost returns expected payload" \
298
+ "http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT" \
299
"$CID_VAL"
300
301
test_localhost_gateway_response_should_contain \
302
"localhost request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \
289
- "http://${IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \
290
- "Location: http://${IPNS_IDv1}.ipns.localhost:$GWAY_PORT/"
303
+ "http://${RSA_IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \
304
+ "Location: http://${RSA_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/"
305
+
306
+test_localhost_gateway_response_should_contain \
307
+ "localhost request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \
308
+ "http://${ED25519_IPNS_IDv1_DAGPB}.ipns.localhost:$GWAY_PORT" \
309
+ "Location: http://${ED25519_IPNS_IDv1}.ipns.localhost:$GWAY_PORT/"
310
311
# <dnslink-fqdn>.ipns.localhost
312
@@ -366,8 +385,14 @@ test_expect_success "request for http://example.com/ipfs/{CID} with X-Forwarded-
385
test_hostname_gateway_response_should_contain \
386
"request for example.com/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \
387
"example.com" \
369
- "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_IDv0" \
370
- "Location: http://${IPNS_IDv1}.ipns.example.com/"
388
+ "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \
389
+ "Location: http://${RSA_IPNS_IDv1}.ipns.example.com/"
390
+
391
+test_hostname_gateway_response_should_contain \
392
+ "request for example.com/ipns/{CIDv0} redirects to CIDv1 with libp2p-key multicodec in subdomain" \
393
+ "example.com" \
394
+ "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \
395
+ "Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/"
396
397
# example.com/ipns/<dnslink-fqdn>
398
@@ -418,15 +443,27 @@ test_expect_success "request for deep path resource {cid}.ipfs.example.com/sub/d
443
444
test_hostname_gateway_response_should_contain \
445
"request for {CIDv1-libp2p-key}.ipns.example.com returns expected payload" \
421
- "${IPNS_IDv1}.ipns.example.com" \
446
+ "${RSA_IPNS_IDv1}.ipns.example.com" \
447
+ "http://127.0.0.1:$GWAY_PORT" \
448
+ "$CID_VAL"
449
+
450
+test_hostname_gateway_response_should_contain \
451
+ "request for {CIDv1-libp2p-key}.ipns.example.com returns expected payload" \
452
+ "${ED25519_IPNS_IDv1}.ipns.example.com" \
453
"http://127.0.0.1:$GWAY_PORT" \
454
"$CID_VAL"
455
456
test_hostname_gateway_response_should_contain \
457
"hostname request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \
427
- "${IPNS_IDv1_DAGPB}.ipns.example.com" \
458
+ "${RSA_IPNS_IDv1_DAGPB}.ipns.example.com" \
459
"http://127.0.0.1:$GWAY_PORT" \
429
- "Location: http://${IPNS_IDv1}.ipns.example.com/"
460
+ "Location: http://${RSA_IPNS_IDv1}.ipns.example.com/"
461
+
462
+test_hostname_gateway_response_should_contain \
463
+ "hostname request for {CIDv1-dag-pb}.ipns.localhost redirects to CID with libp2p-key multicodec" \
464
+ "${ED25519_IPNS_IDv1_DAGPB}.ipns.example.com" \
465
+ "http://127.0.0.1:$GWAY_PORT" \
466
+ "Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/"
467
468
# API on subdomain gateway example.com
469
# ============================================================================
@@ -570,7 +607,13 @@ test_launch_ipfs_daemon --offline
607
# refuse requests to Paths that were not explicitly whitelisted for the hostname
608
test_hostname_gateway_response_should_contain \
609
"request for *.ipns.example.com returns HTTP 404 Not Found when /ipns is not on Paths whitelist" \
573
- "${IPNS_IDv1}.ipns.example.com" \
610
+ "${RSA_IPNS_IDv1}.ipns.example.com" \
611
+ "http://127.0.0.1:$GWAY_PORT" \
612
+ "404 Not Found"
613
+
614
+test_hostname_gateway_response_should_contain \
615
+ "request for *.ipns.example.com returns HTTP 404 Not Found when /ipns is not on Paths whitelist" \
616
+ "${ED25519_IPNS_IDv1}.ipns.example.com" \
617
"http://127.0.0.1:$GWAY_PORT" \
618
"404 Not Found"
619
@@ -612,7 +655,13 @@ test_hostname_gateway_response_should_contain \
655
test_hostname_gateway_response_should_contain \
656
"request for example.com/ipns/ returns HTTP 404 Not Found when /ipns is not on Paths whitelist" \
657
"example.com" \
615
- "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_IDv1" \
658
+ "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv1" \
659
+ "404 Not Found"
660
+
661
+test_hostname_gateway_response_should_contain \
662
+ "request for example.com/ipns/ returns HTTP 404 Not Found when /ipns is not on Paths whitelist" \
663
+ "example.com" \
664
+ "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv1" \
665
"404 Not Found"
666
667
## ============================================================================
@@ -685,7 +734,13 @@ test_hostname_gateway_response_should_contain \
734
test_hostname_gateway_response_should_contain \
735
"request for {dnslink-fqdn}/ipns/{peerid} returns 404 when path is not whitelisted" \
736
"$DNSLINK_FQDN" \
688
- "http://127.0.0.1:$GWAY_PORT/ipns/$IPNS_IDv0" \
737
+ "http://127.0.0.1:$GWAY_PORT/ipns/$RSA_IPNS_IDv0" \
738
+ "404 Not Found"
739
+
740
+test_hostname_gateway_response_should_contain \
741
+ "request for {dnslink-fqdn}/ipns/{peerid} returns 404 when path is not whitelisted" \
742
+ "$DNSLINK_FQDN" \
743
+ "http://127.0.0.1:$GWAY_PORT/ipns/$ED25519_IPNS_IDv0" \
744
"404 Not Found"
745
746
# DNSLink disabled
@@ -771,4 +826,8 @@ test_expect_success "request for http://fake.domain.com/ipfs/{CID} with X-Forwar
826
ipfs config --json Gateway.PublicGateways '{}'
827
test_kill_ipfs_daemon
828
829
+test_expect_success "clean up ipfs dir" '
830
+ rm -rf "$IPFS_PATH"
831
+'
832
+
833
test_done