diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 739a60bc9..84860f248 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -8,6 +8,10 @@ inputs: description: "The Subdomain URL of the IPFS Gateway implementation to be tested." default: "http://example.com" required: false + enable-kubo-localhost-subdomains: + description: "When set to `false`, the action will disable the querying of `localhost` (without a port) for subdomains." + default: "true" + required: false accept-test-failure: # see https://github.com/orgs/community/discussions/15452 description: "When set to `true`, the action will not fail (become red) if the tests fail. Use the reports to determine the outcome of the tests." @@ -46,6 +50,7 @@ runs: env: URL: ${{ inputs.gateway-url }} SUBDOMAIN: ${{ inputs.subdomain-url }} + ENABLE_KUBO_LOCALHOST_SUBDOMAINS: ${{ inputs.enable-kubo-localhost-subdomains }} JSON: ${{ inputs.json }} SPECS: ${{ inputs.specs }} JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} @@ -55,7 +60,7 @@ runs: dockerfile: Dockerfile allow-exit-codes: ${{ inputs.accept-test-failure == 'false' && '0' || '0,1' }} opts: --network=host - args: test --url="$URL" --json="$JSON" --specs="$SPECS" --subdomain-url="$SUBDOMAIN" --job-url="$JOB_URL" -- ${{ inputs.args }} + args: test --url="$URL" --json="$JSON" --specs="$SPECS" --subdomain-url="$SUBDOMAIN" --job-url="$JOB_URL" --enable-kubo-localhost-subdomains="$ENABLE_KUBO_LOCALHOST_SUBDOMAINS" -- ${{ inputs.args }} build-args: | VERSION:${{ steps.github.outputs.action_ref }} - name: Create the XML @@ -87,4 +92,4 @@ runs: run: | # TODO: checkout here. wget 'https://raw.githubusercontent.com/singulargarden/gateway-conformance/main/munge.js' -O munge.js - cat "${JSON}" | node munge.js > "${REPORT}" \ No newline at end of file + cat "${JSON}" | node munge.js > "${REPORT}" diff --git a/cmd/gateway-conformance/main.go b/cmd/gateway-conformance/main.go index 994ea8455..d7ab0ea89 100644 --- a/cmd/gateway-conformance/main.go +++ b/cmd/gateway-conformance/main.go @@ -71,6 +71,7 @@ func copyFiles(inputPaths []string, outputDirectoryPath string) error { func main() { var gatewayURL string var subdomainGatewayURL string + var enableKuboLocalhostSubdomains bool var jsonOutput string var jobURL string var specs string @@ -101,6 +102,12 @@ func main() { Value: "http://example.com", Destination: &subdomainGatewayURL, }, + &cli.BoolFlag{ + Name: "enable-kubo-localhost-subdomains", + Usage: "Enable testing subdomains by querying no-port 'localhost' which depends on setting Kubo's `Gateway.PublicGateways` config.", + Value: true, + Destination: &enableKuboLocalhostSubdomains, + }, &cli.StringFlag{ Name: "json-output", Aliases: []string{"json", "j"}, @@ -150,6 +157,9 @@ func main() { if subdomainGatewayURL != "" { cmd.Env = append(cmd.Env, fmt.Sprintf("SUBDOMAIN_GATEWAY_URL=%s", subdomainGatewayURL)) } + if enableKuboLocalhostSubdomains { + cmd.Env = append(cmd.Env, fmt.Sprintf("ENABLE_KUBO_LOCALHOST_SUBDOMAINS=%t", enableKuboLocalhostSubdomains)) + } cmd.Stdout = out{ Writer: output, diff --git a/docs/commands.md b/docs/commands.md index 58f60c555..5b9de8557 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -32,6 +32,7 @@ The `test` command is the main command of the tool. It is used to test a given I |---|---|---|---| | gateway-url | Both | The URL of the IPFS Gateway implementation to be tested. | http://localhost:8080 | | subdomain-url | Both | The URL to be used in Subdomain feature tests based on Host HTTP header. | http://example.com | +| enable-kubo-localhost-subdomains | Both | If you cannot listen on `localhost` for subdomains like Kubo does, set this to false | `true` | | json | Both | The path where the JSON test report should be generated. | `./report.json` | | xml | GitHub Action | The path where the JUnit XML test report should be generated. | `./report.xml` | | html | GitHub Action | The path where the one-page HTML test report should be generated. | `./report.html` | diff --git a/tests/redirects_file_test.go b/tests/redirects_file_test.go index c9f7eca3e..a99a26eea 100644 --- a/tests/redirects_file_test.go +++ b/tests/redirects_file_test.go @@ -29,7 +29,9 @@ func TestRedirectsFileSupport(t *testing.T) { // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ SubdomainGatewayURL, - SubdomainLocalhostGatewayURL, + } + if EnableKuboLocalhostSubdomains { + gatewayURLs = append(gatewayURLs, SubdomainLocalhostGatewayURL) } for _, gatewayURL := range gatewayURLs { diff --git a/tests/subdomain_gateway_ipfs_test.go b/tests/subdomain_gateway_ipfs_test.go index f0a61c69f..25d8f909e 100644 --- a/tests/subdomain_gateway_ipfs_test.go +++ b/tests/subdomain_gateway_ipfs_test.go @@ -22,7 +22,10 @@ func TestUnixFSDirectoryListingOnSubdomainGateway(t *testing.T) { // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ SubdomainGatewayURL, - SubdomainLocalhostGatewayURL, + } + + if EnableKuboLocalhostSubdomains { + gatewayURLs = append(gatewayURLs, SubdomainLocalhostGatewayURL) } tests := SugarTests{} @@ -128,7 +131,10 @@ func TestGatewaySubdomains(t *testing.T) { // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ SubdomainGatewayURL, - SubdomainLocalhostGatewayURL, + } + + if EnableKuboLocalhostSubdomains { + gatewayURLs = append(gatewayURLs, SubdomainLocalhostGatewayURL) } for _, gatewayURL := range gatewayURLs { @@ -141,7 +147,7 @@ func TestGatewaySubdomains(t *testing.T) { { Name: "request for example.com/ipfs/{CIDv1} redirects to subdomain", Hint: ` - path requests to gateways with subdomain support + path requests to gateways with subdomain support should not return payload directly, but redirect to URL with proper origin isolation `, @@ -166,7 +172,7 @@ func TestGatewaySubdomains(t *testing.T) { { Name: "request for example.com/ipfs/{DirCID} redirects to subdomain", Hint: ` - path requests to gateways with subdomain support + path requests to gateways with subdomain support should not return payload directly, but redirect to URL with proper origin isolation `, diff --git a/tests/subdomain_gateway_ipns_test.go b/tests/subdomain_gateway_ipns_test.go index 58211eacc..19dd266be 100644 --- a/tests/subdomain_gateway_ipns_test.go +++ b/tests/subdomain_gateway_ipns_test.go @@ -29,7 +29,10 @@ func TestGatewaySubdomainAndIPNS(t *testing.T) { // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ SubdomainGatewayURL, - SubdomainLocalhostGatewayURL, + } + + if EnableKuboLocalhostSubdomains { + gatewayURLs = append(gatewayURLs, SubdomainLocalhostGatewayURL) } ipnsRecords := []*ipns.IpnsRecord{ @@ -169,7 +172,10 @@ func TestSubdomainGatewayDNSLinkInlining(t *testing.T) { // We're going to run the same test against multiple gateways (localhost, and a subdomain gateway) gatewayURLs := []string{ SubdomainGatewayURL, - SubdomainLocalhostGatewayURL, + } + + if EnableKuboLocalhostSubdomains { + gatewayURLs = append(gatewayURLs, SubdomainLocalhostGatewayURL) } dnsLinks := dnslink.MustOpenDNSLink("subdomain_gateway/dnslink.yml") diff --git a/tooling/test/config.go b/tooling/test/config.go index 506c03785..31abe947f 100644 --- a/tooling/test/config.go +++ b/tooling/test/config.go @@ -25,6 +25,11 @@ var SubdomainGatewayURL = strings.TrimRight( GetEnv("SUBDOMAIN_GATEWAY_URL", "http://example.com"), "/") +// EnableKuboLocalhostSubdomains is a flag that enables testing subdomains by querying no-port 'localhost' +// you can read more about why this is needed at https://github.com/ipfs/gateway-conformance/issues/185#issuecomment-2127598223 +// default is true +var EnableKuboLocalhostSubdomains = GetEnv("ENABLE_KUBO_LOCALHOST_SUBDOMAINS", "true") == "true" + var GatewayHost = "" var SubdomainGatewayHost = "" var SubdomainGatewayScheme = ""