Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow disabling Kubo 'localhost' testing #210

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand Down Expand Up @@ -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}"
cat "${JSON}" | node munge.js > "${REPORT}"
10 changes: 10 additions & 0 deletions cmd/gateway-conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
4 changes: 3 additions & 1 deletion tests/redirects_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions tests/subdomain_gateway_ipfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
`,
Expand All @@ -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
`,
Expand Down
10 changes: 8 additions & 2 deletions tests/subdomain_gateway_ipns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions tooling/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
Loading