Skip to content

Commit

Permalink
feat: make subdomain testing possible
Browse files Browse the repository at this point in the history
Add support for subdomain testing. We port the test from sharness 114 into the conformance test suite.

- the ability to use any URL (like dweb gateway).
- nice reporting, see reports in https://github.com/ipfs/gateway-conformance/actions/runs/4470741917/jobs/7854699679
  • Loading branch information
laurentsenta authored Mar 23, 2023
2 parents cc22701 + 48c8935 commit d38b8f9
Show file tree
Hide file tree
Showing 18 changed files with 994 additions and 144 deletions.
7 changes: 6 additions & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ inputs:
gateway-url:
description: "The URL of the IPFS Gateway implementation to be tested."
required: true
subdomain-url:
description: "The Subdomain URL of the IPFS Gateway implementation to be tested."
default: "http://example.com"
required: false
json:
description: "The path where the JSON test report should be generated."
required: true
Expand Down Expand Up @@ -33,14 +37,15 @@ runs:
uses: pl-strflt/docker-container-action@v1
env:
URL: ${{ inputs.gateway-url }}
SUBDOMAIN: ${{ inputs.subdomain-url }}
JSON: ${{ inputs.json }}
SPECS: ${{ inputs.specs }}
with:
repository: ${{ steps.github.outputs.action_repository }}
ref: ${{ steps.github.outputs.action_ref }}
dockerfile: Dockerfile
opts: --network=host
args: test --url="$URL" --json="$JSON" --specs="$SPECS" -- ${{ inputs.args }}
args: test --url="$URL" --json="$JSON" --specs="$SPECS" --subdomain-url="$SUBDOMAIN" -- ${{ inputs.args }}
- name: Create the XML
if: (inputs.xml || inputs.html || inputs.markdown) && (failure() || success())
uses: pl-strflt/gotest-json-to-junit-xml@v1
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
run:
shell: bash
steps:
- uses: ipfs/download-ipfs-distribution-action@v1
- uses: ipfs/start-ipfs-daemon-action@v1
- name: Setup Go
uses: actions/setup-go@v3
with:
Expand All @@ -24,17 +22,24 @@ jobs:
uses: ./gateway-conformance/.github/actions/extract-fixtures
with:
output: fixtures
- uses: ipfs/download-ipfs-distribution-action@v1
- name: Configure Kubo Gateway
run: |
ipfs init;
./gateway-conformance/kubo-config.example.sh;
- uses: ipfs/start-ipfs-daemon-action@v1
- name: Provision Kubo Gateway
run: find ./fixtures -name '*.car' -exec ipfs dag import {} \;
run: |
find ./fixtures -name '*.car' -exec ipfs dag import {} \;
- name: Run the tests
uses: ./gateway-conformance/.github/actions/test
with:
gateway-url: http://127.0.0.1:8080
subdomain-url: http://example.com
json: output.json
xml: output.xml
html: output.html
markdown: output.md
specs: -subdomain-gateway
args: -skip TestGatewayCar
- name: Set summary
if: (failure() || success())
Expand Down
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
all: test-kubo

test-cargateway: provision-cargateway fixtures.car gateway-conformance
./gateway-conformance test --json output.json --gateway-url http://127.0.0.1:8040 --specs -subdomain-gateway

test-kubo-subdomains: provision-kubo gateway-conformance
./kubo-config.example.sh
./gateway-conformance test --json output.json --gateway-url http://127.0.0.1:8080 --subdomain-url http://example.com:8080

test-kubo: provision-kubo fixtures.car gateway-conformance
./gateway-conformance test --json output.json --gateway-url http://127.0.0.1:8080 --specs -subdomain-gateway

provision-cargateway: ./fixtures.car
# cd go-libipfs/examples/car && go install
car -c ./fixtures.car &

test-cargateway: provision-cargateway
GATEWAY_URL=http://127.0.0.1:8040 make _test

provision-kubo:
find ./fixtures -name '*.car' -exec ipfs dag import {} \;

test-kubo: provision-kubo
GATEWAY_URL=http://127.0.0.1:8080 make _test

# tools
fixtures.car: gateway-conformance
./gateway-conformance extract-fixtures --merged=true --dir=.

gateway-conformance:
go build -o ./gateway-conformance ./cmd/gateway-conformance

_test: fixtures.car gateway-conformance
./gateway-conformance test --json output.json --gateway-url ${GATEWAY_URL}

test-docker: fixtures.car gateway-conformance
docker build -t gateway-conformance .
docker run --rm -v "${PWD}:/workspace" -w "/workspace" --network=host gateway-conformance test
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The `test` command is the main command of the tool. It is used to test a given I
| Input | Availability | Description | Default |
|---|---|---|---|
| gateway-url | Both | The URL of the IPFS Gateway implementation to be tested. | http://localhost:8080 |
| subdomain-url | Both | The Subdomain URL of the IPFS Gateway implementation to be tested. | http://example.com |
| 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 All @@ -45,6 +46,19 @@ If you provide a list containing both prefixed and unprefixed specs, the prefixe

This input should be used sparingly and with caution, as it involves interacting with the underlying internal processes, which may be subject to changes. It is recommended to use the `args` input only when you have a deep understanding of the tool's inner workings and need to fine-tune the testing process. Users should be mindful of the potential risks associated with using this input.

#### Subdomain Testing and `subdomain-url`

The `subdomain-url` parameter is utilized when testing subdomain support in your IPFS gateway. It can be set to any domain that your gateway permits.
During testing, the suite keeps connecting to the `gateway-url` while employing HTTP techniques to simulate requests as if they were sent to the subdomain.
This approach enables testing of local gateways during development or continuous integration (CI) scenarios.

A few examples:

| Use Case | gateway-url | subdomain-url |
|----------|-------------|---------------|
| CI & Dev | http://127.0.0.1:8080 | http://example.com |
| Production | https://dweb.link | https://dweb.link |

#### Usage

##### GitHub Action
Expand Down Expand Up @@ -148,4 +162,6 @@ Please let us know if you would like to see this feature implemented directly in
## In Development

- How to deal with subdomains & configuration (t0114 for example)?
- Some test relies on querying URLs like `http://$CIDv1.ipfs.example.com/`. While `http://$CIDv1.ipfs.localhost/` works by default, do we need / want to test with `.example.com`?
- Some test relies on querying URLs like `http://$CIDv1.ipfs.example.com/`. While `http://$CIDv1.ipfs.localhost/` works by default, do we need / want to test with `.example.com`?
- Debug logging
- Set the environment variable `GOLOG_LOG_LEVEL="conformance=debug"` to toggle debug logging.
12 changes: 12 additions & 0 deletions cmd/gateway-conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func copyFiles(inputPaths []string, outputDirectoryPath string) error {

func main() {
var gatewayURL string
var subdomainGatewayURL string
var jsonOutput string
var specs string
var directory string
Expand All @@ -78,6 +79,12 @@ func main() {
Value: "http://localhost:8080",
Destination: &gatewayURL,
},
&cli.StringFlag{
Name: "subdomain-url",
Usage: "The Subdomain URL of the IPFS Gateway implementation to be tested.",
Value: "http://example.com",
Destination: &subdomainGatewayURL,
},
&cli.StringFlag{
Name: "json-output",
Aliases: []string{"json", "j"},
Expand Down Expand Up @@ -107,6 +114,11 @@ func main() {
cmd := exec.Command("go", args...)
cmd.Dir = tooling.Home()
cmd.Env = append(os.Environ(), fmt.Sprintf("GATEWAY_URL=%s", gatewayURL))

if subdomainGatewayURL != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("SUBDOMAIN_GATEWAY_URL=%s", subdomainGatewayURL))
}

cmd.Stdout = out{output}
cmd.Stderr = os.Stderr
testErr := cmd.Run()
Expand Down
Binary file modified fixtures/t0114-gateway_subdomains.car
Binary file not shown.
12 changes: 12 additions & 0 deletions kubo-config.example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env bash
ipfs config --json Gateway.PublicGateways '{
"example.com": {
"UseSubdomains": true,
"Paths": ["/ipfs", "/ipns", "/api"]
},
"localhost": {
"UseSubdomains": true,
"InlineDNSLink": true,
"Paths": ["/ipfs", "/ipns", "/api"]
}
}'
4 changes: 2 additions & 2 deletions tests/t0113_gateway_symlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestGatewaySymlink(t *testing.T) {
{
Name: "Test the directory listing",
Request: test.CRequest{
Url: fmt.Sprintf("ipfs/%s?format=raw", fixture.MustGetCid()),
Path: fmt.Sprintf("ipfs/%s?format=raw", fixture.MustGetCid()),
},
Response: test.CResponse{
StatusCode: 200,
Expand All @@ -24,7 +24,7 @@ func TestGatewaySymlink(t *testing.T) {
{
Name: "Test the symlink",
Request: test.CRequest{
Url: fmt.Sprintf("ipfs/%s/bar", fixture.MustGetCid()),
Path: fmt.Sprintf("ipfs/%s/bar", fixture.MustGetCid()),
},
Response: test.CResponse{
StatusCode: 200,
Expand Down
Loading

0 comments on commit d38b8f9

Please sign in to comment.