Skip to content

Commit 74258c0

Browse files
committed
refactor: remove and update tests
1 parent be94a4e commit 74258c0

File tree

4 files changed

+1
-211
lines changed

4 files changed

+1
-211
lines changed

test/cli/gateway_test.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/ipfs/kubo/config"
1616
"github.com/ipfs/kubo/test/cli/harness"
17-
. "github.com/ipfs/kubo/test/cli/testutils"
1817
"github.com/libp2p/go-libp2p/core/peer"
1918
"github.com/multiformats/go-multiaddr"
2019
manet "github.com/multiformats/go-multiaddr/net"
@@ -344,76 +343,6 @@ func TestGateway(t *testing.T) {
344343
})
345344
})
346345

347-
t.Run("readonly API", func(t *testing.T) {
348-
t.Parallel()
349-
350-
client := node.GatewayClient()
351-
352-
fileContents := "12345"
353-
h.WriteFile("readonly/dir/test", fileContents)
354-
cids := node.IPFS("add", "-r", "-q", filepath.Join(h.Dir, "readonly/dir")).Stdout.Lines()
355-
356-
rootCID := cids[len(cids)-1]
357-
client.TemplateData = map[string]string{"RootCID": rootCID}
358-
359-
t.Run("Get IPFS directory file through readonly API succeeds", func(t *testing.T) {
360-
t.Parallel()
361-
resp := client.Get("/api/v0/cat?arg={{.RootCID}}/test")
362-
assert.Equal(t, 200, resp.StatusCode)
363-
assert.Equal(t, fileContents, resp.Body)
364-
})
365-
366-
t.Run("refs IPFS directory file through readonly API succeeds", func(t *testing.T) {
367-
t.Parallel()
368-
resp := client.Get("/api/v0/refs?arg={{.RootCID}}/test")
369-
assert.Equal(t, 200, resp.StatusCode)
370-
})
371-
372-
t.Run("test gateway API is sanitized", func(t *testing.T) {
373-
t.Parallel()
374-
for _, cmd := range []string{
375-
"add",
376-
"block/put",
377-
"bootstrap",
378-
"config",
379-
"dag/put",
380-
"dag/import",
381-
"dht",
382-
"diag",
383-
"id",
384-
"mount",
385-
"name/publish",
386-
"object/put",
387-
"object/new",
388-
"object/patch",
389-
"pin",
390-
"ping",
391-
"repo",
392-
"stats",
393-
"swarm",
394-
"file",
395-
"update",
396-
"bitswap",
397-
} {
398-
t.Run(cmd, func(t *testing.T) {
399-
cmd := cmd
400-
t.Parallel()
401-
assert.Equal(t, 404, client.Get("/api/v0/"+cmd).StatusCode)
402-
})
403-
}
404-
})
405-
})
406-
407-
t.Run("refs/local", func(t *testing.T) {
408-
t.Parallel()
409-
gatewayAddr := URLStrToMultiaddr(node.GatewayURL())
410-
res := node.RunIPFS("--api", gatewayAddr.String(), "refs", "local")
411-
assert.Contains(t,
412-
res.Stderr.Trimmed(),
413-
`Error: invalid path "local":`,
414-
)
415-
})
416-
417346
t.Run("raw leaves node", func(t *testing.T) {
418347
t.Parallel()
419348
contents := "This is RAW!"

test/sharness/t0002-docker-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test_expect_success "docker image runs" '
5050
'
5151

5252
test_expect_success "docker container gateway is up" '
53-
pollEndpoint -host=/ip4/127.0.0.1/tcp/8080 -http-url http://localhost:8080/api/v0/version -v -tries 30 -tout 1s
53+
pollEndpoint -host=/ip4/127.0.0.1/tcp/8080 -http-url http://localhost:8080/ipfs/bafkqaddimvwgy3zao5xxe3debi -v -tries 30 -tout 1s
5454
'
5555

5656
test_expect_success "docker container API is up" '

test/sharness/t0112-gateway-cors.sh

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -127,70 +127,6 @@ test_expect_success "Access-Control-Allow-Origin replaces the implicit list" '
127127
test_should_contain "< Access-Control-Allow-Origin: localhost" curl_output
128128
'
129129

130-
# Read-Only /api/v0 RPC API (legacy subset, exposed on the Gateway Port)
131-
# TODO: we want to remove it, but for now this guards the legacy behavior to not go any further
132-
133-
# also check this, as due to legacy reasons Kubo exposes small subset of /api/v0 on GW port
134-
test_expect_success "Assert the default API.HTTPHeaders config is empty" '
135-
echo "{}" > expected &&
136-
ipfs config --json API.HTTPHeaders > actual &&
137-
test_cmp expected actual
138-
'
139-
140-
# HTTP GET Request
141-
test_expect_success "Default CORS GET to {gw}/api/v0" '
142-
curl -svX GET -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?arg=$thash" >/dev/null 2>curl_output
143-
'
144-
# HTTP 403 is returned because Kubo has additional protections on top of regular CORS,
145-
# namely it only allows browser requests with localhost Origin header.
146-
test_expect_success "Default CORS GET response from {gw}/api/v0 is 403 Forbidden and has regular CORS headers" '
147-
test_should_contain "HTTP/1.1 403 Forbidden" curl_output &&
148-
test_should_contain "< Access-Control-" curl_output
149-
'
150-
151-
# HTTP OPTIONS Request
152-
test_expect_success "Default OPTIONS to {gw}/api/v0" '
153-
curl -svX OPTIONS -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?arg=$thash" 2>curl_output
154-
'
155-
# OPTIONS Response from the API should NOT contain CORS headers
156-
test_expect_success "OPTIONS response from {gw}/api/v0 has CORS headers" '
157-
test_should_contain "< Access-Control-" curl_output
158-
'
159-
160-
test_kill_ipfs_daemon
161-
162-
# TODO: /api/v0 with CORS headers set in API.HTTPHeaders does not really work,
163-
# as not all headers are correctly set. Below is only a basic regression test that documents
164-
# current state. Fixing CORS on /api/v0 (RPC and Gateway port) is tracked in https://github.com/ipfs/kubo/issues/7667
165-
166-
test_expect_success "Manually set API.HTTPHeaders config to be as relaxed as Gateway.HTTPHeaders" "
167-
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"https://example.com\"]'
168-
"
169-
# TODO: ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '[\"GET\",\"POST\"]' &&
170-
# TODO: ipfs config --json API.HTTPHeaders.Access-Control-Allow-Headers '[\"X-Requested-With\", \"Range\", \"User-Agent\"]'
171-
172-
test_launch_ipfs_daemon
173-
174-
# HTTP GET Request
175-
test_expect_success "Manually relaxed CORS GET to {gw}/api/v0" '
176-
curl -svX GET -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?arg=$thash" >/dev/null 2>curl_output
177-
'
178-
test_expect_success "Manually relaxed CORS GET response from {gw}/api/v0 is the same as Gateway" '
179-
test_should_contain "HTTP/1.1 200 OK" curl_output &&
180-
test_should_contain "< Access-Control-Allow-Origin: https://example.com" curl_output
181-
'
182-
# TODO: test_should_contain "< Access-Control-Allow-Methods: GET" curl_output
183-
184-
# HTTP OPTIONS Request
185-
test_expect_success "Manually relaxed OPTIONS to {gw}/api/v0" '
186-
curl -svX OPTIONS -H "Origin: https://example.com" "http://127.0.0.1:$GWAY_PORT/api/v0/cat?arg=$thash" 2>curl_output
187-
'
188-
# OPTIONS Response from the API should NOT contain CORS headers
189-
test_expect_success "Manually relaxed OPTIONS response from {gw}/api/v0 is the same as Gateway" '
190-
test_should_contain "< Access-Control-Allow-Origin: https://example.com" curl_output
191-
'
192-
# TODO: test_should_contain "< Access-Control-Allow-Methods: GET" curl_output
193-
194130
test_kill_ipfs_daemon
195131

196132
test_done

test/sharness/t0114-gateway-subdomains.sh

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,6 @@ test_localhost_gateway_response_should_contain \
203203

204204
# end Kubo specific end-to-end test
205205

206-
# API on localhost subdomain gateway
207-
208-
# /api/v0 present on the root hostname
209-
test_localhost_gateway_response_should_contain \
210-
"request for localhost/api" \
211-
"http://localhost:$GWAY_PORT/api/v0/refs?arg=${DIR_CID}&r=true" \
212-
"Ref"
213-
214-
# /api/v0 not mounted on content root subdomains
215-
test_localhost_gateway_response_should_contain \
216-
"request for {cid}.ipfs.localhost/api returns data if present on the content root" \
217-
"http://${DIR_CID}.ipfs.localhost:$GWAY_PORT/api/file.txt" \
218-
"I am a txt file"
219-
220-
test_localhost_gateway_response_should_contain \
221-
"request for {cid}.ipfs.localhost/api/v0/refs returns 404" \
222-
"http://${DIR_CID}.ipfs.localhost:$GWAY_PORT/api/v0/refs?arg=${DIR_CID}&r=true" \
223-
"404 Not Found"
224-
225206
## ============================================================================
226207
## Test subdomain-based requests to a local gateway with default config
227208
## (origin per content root at http://*.localhost)
@@ -308,14 +289,6 @@ test_localhost_gateway_response_should_contain \
308289
"http://$DNSLINK_FQDN.ipns.localhost:$GWAY_PORT" \
309290
"$CID_VAL"
310291

311-
# api.localhost/api
312-
313-
# Note: we use DIR_CID so refs -r returns some CIDs for child nodes
314-
test_localhost_gateway_response_should_contain \
315-
"request for api.localhost returns API response" \
316-
"http://api.localhost:$GWAY_PORT/api/v0/refs?arg=$DIR_CID&r=true" \
317-
"Ref"
318-
319292
## ============================================================================
320293
## Test DNSLink inlining on HTTP gateways
321294
## ============================================================================
@@ -518,54 +491,6 @@ test_hostname_gateway_response_should_contain \
518491
"http://127.0.0.1:$GWAY_PORT" \
519492
"Location: http://${ED25519_IPNS_IDv1}.ipns.example.com/"
520493

521-
# API on subdomain gateway example.com
522-
# ============================================================================
523-
524-
# present at the root domain
525-
test_hostname_gateway_response_should_contain \
526-
"request for example.com/api/v0/refs returns expected payload when /api is on Paths whitelist" \
527-
"example.com" \
528-
"http://127.0.0.1:$GWAY_PORT/api/v0/refs?arg=${DIR_CID}&r=true" \
529-
"Ref"
530-
531-
# not mounted on content root subdomains
532-
test_hostname_gateway_response_should_contain \
533-
"request for {cid}.ipfs.example.com/api returns data if present on the content root" \
534-
"$DIR_CID.ipfs.example.com" \
535-
"http://127.0.0.1:$GWAY_PORT/api/file.txt" \
536-
"I am a txt file"
537-
538-
test_hostname_gateway_response_should_contain \
539-
"request for {cid}.ipfs.example.com/api/v0/refs returns 404" \
540-
"$CIDv1.ipfs.example.com" \
541-
"http://127.0.0.1:$GWAY_PORT/api/v0/refs?arg=${DIR_CID}&r=true" \
542-
"404 Not Found"
543-
544-
# disable /api on example.com
545-
ipfs config --json Gateway.PublicGateways '{
546-
"example.com": {
547-
"UseSubdomains": true,
548-
"Paths": ["/ipfs", "/ipns"]
549-
}
550-
}' || exit 1
551-
# restart daemon to apply config changes
552-
test_kill_ipfs_daemon
553-
test_launch_ipfs_daemon_without_network
554-
555-
# not mounted at the root domain
556-
test_hostname_gateway_response_should_contain \
557-
"request for example.com/api/v0/refs returns 404 if /api not on Paths whitelist" \
558-
"example.com" \
559-
"http://127.0.0.1:$GWAY_PORT/api/v0/refs?arg=${DIR_CID}&r=true" \
560-
"404 Not Found"
561-
562-
# not mounted on content root subdomains
563-
test_hostname_gateway_response_should_contain \
564-
"request for {cid}.ipfs.example.com/api returns data if present on the content root" \
565-
"$DIR_CID.ipfs.example.com" \
566-
"http://127.0.0.1:$GWAY_PORT/api/file.txt" \
567-
"I am a txt file"
568-
569494
# DNSLink: <dnslink-fqdn>.ipns.example.com
570495
# (not really useful outside of localhost, as setting TLS for more than one
571496
# level of wildcard is a pain, but we support it if someone really wants it)

0 commit comments

Comments
 (0)