Skip to content

Commit 3e23e98

Browse files
authored
feat: improved subdomain-url handling (#211)
* fix: subdomain-url handling - removed implicit tests based on SubdomainLocalhostGatewayURL - subdomain tests are now run only against origins defined via `--subdomain-url` - DNSLink gateway tests are no longer tied to origin passed via `--subdomain-url` * fix(wip): avoid mangling Host header handling - splitting into subdomain and dnslink gateway variants - towards avoiding running everything three times - keep custom Host header when defined * refactor: remove subdomains from dnslink fixtures these concepts should not mix, and dnslinks should be testable independent of --subdomain-url i also added more useful export format for them, compatible with IPNS_NS_MAP used by Boxo/Kubo/Rainbow * refactor: handling Host header vs proxying towards fixing underlying issue * feat: make start-kubo-docker all-in-one command for running local kubo with all fixtures in * fix: correctly pass subdomain-url to go test * docs: skip and run examples * refactor: UnwrapSubdomainTests → proxy-gateway This replaces magic helpers.UnwrapSubdomainTests with explicit spec preset named proxy-gateway, which can be enabled/disabled the same way as other presets. While it was nice to run every test in both proxy modes, it was extremely noisy and hard to debug once things went wrong. By having explicit tests in *_proxy_test.go it is easy to skip them where proxy functionality is not relevant. Other: - Send meaningful User-Agent - Sent detached path in HTTP Connect proxy tunnel tests (instead of full URL – in tunnel mode we pretend we talk to remote server on the other end of tunnel, and not send full URL like it is done in plain proxy mode) * docs: fix/improve docker examples * refactor: require explicit gateway URLs This is important UX change. We no longer ship with default URLs. User has to provide explicit one, or the test suite will refuse to run. This ensures misconfigurations and testing different gateway endpoint than desired do not happen. Explicit is better than implicit.
1 parent c0dafe1 commit 3e23e98

28 files changed

+1368
-1055
lines changed

.github/workflows/test-kubo-e2e.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ jobs:
4646
- name: Provision Kubo Gateway
4747
run: |
4848
# Import car files
49-
cars=$(find ./fixtures -name '*.car')
50-
for car in $cars
51-
do
52-
ipfs dag import --pin-roots=false --stats "$car"
53-
done
49+
find ./fixtures -name '*.car' -exec ipfs dag import --pin-roots=false {} \;
5450
5551
# Import ipns records
5652
records=$(find ./fixtures -name '*.ipns-record')
@@ -63,7 +59,7 @@ jobs:
6359
uses: ./gateway-conformance/.github/actions/test
6460
with:
6561
gateway-url: http://127.0.0.1:8080
66-
subdomain-url: http://example.com
62+
subdomain-url: http://example.com:8080
6763
json: output.json
6864
xml: output.xml
6965
html: output.html

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/gateway-conformance
99
/dnslinks.json
1010
/*.ipns-record
11+
extracted-fixtures
1112

1213
# Logs
1314
logs
@@ -142,3 +143,4 @@ dist
142143

143144
# reports
144145
reports
146+
report.json

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.0] - 2024-05-27 ### Changed
8+
- Gateway URL
9+
- `--gateway-url` is no longer defaulting to predefined URL. User has to
10+
provide it via CLI or `GATEWAY_URL` environment variable or the test suite
11+
will refuse to start.
12+
- This aims to ensure no confusion about which gateway endpoint is being
13+
tested.
14+
- Docs and examples use `--gateway-url http://127.0.0.1:8080` to ensure no
15+
confusion with `localhost:8080` subdomain gateway feature in IPFS
16+
implementations like Kubo.
17+
- Subdomain URL and UX related to subdomain tests
18+
- The `--subdomain-url` is no longer set by default.
19+
- User has to provide the origin of the subdomain gateway via CLI or
20+
`SUBDOMAIN_GATEWAY_URL` to be used during subdomain tests. This aims to
21+
ensure no confusion about which domain name is being tested.
22+
- Simplified the way `--subdomain-url` works. We no longer run implicit tests
23+
against `http://localhost` in addition to the URL passed via
24+
`--subdomain-url`. To test more than one domain, run test multiple times.
25+
- DNSLink test fixtures changed
26+
- DNSLink fixtures no longer depend on `--subdomain-url` and use unrelated
27+
`*.example.org` domains instead.
28+
- `gateway-conformance extract-fixtures` creates `dnslinks.IPFS_NS_MAP` with
29+
content that can be directly set as `IPNS_NS_MAP` environment variable
30+
supported by various implementations, incl.
31+
[Kubo](https://github.com/ipfs/kubo/blob/master/docs/environment-variables.md#ipfs_ns_map)
32+
and
33+
[Rainbow](https://github.com/ipfs/rainbow/blob/main/docs/environment-variables.md#ipfs_ns_map).
34+
- Docker
35+
- The image can now be run under non-root user
36+
737
## [0.5.2] - 2024-05-20
838
### Changed
939
- Fixed: relaxed dag-cbor error check ([#205](https://github.com/ipfs/gateway-conformance/pull/205))

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM golang:1.20-alpine
22
WORKDIR /app
3-
ENV GATEWAY_CONFORMANCE_HOME=/app
3+
ENV GATEWAY_CONFORMANCE_HOME=/app \
4+
GOCACHE=/go/cache
45

56
COPY ./go.mod ./go.sum ./
67
RUN go mod download
@@ -9,4 +10,7 @@ COPY . .
910
ARG VERSION=dev
1011
RUN go build -ldflags="-X github.com/ipfs/gateway-conformance/tooling.Version=${VERSION}" -o ./gateway-conformance ./cmd/gateway-conformance
1112

13+
# Relaxed perms for cache dir to allow running under regular user
14+
RUN mkdir -p $GOCACHE && chmod -R 777 $GOCACHE
15+
1216
ENTRYPOINT ["/app/gateway-conformance"]

Makefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
GIT_COMMIT := $(shell git rev-parse --short HEAD)
22
DIRTY_SUFFIX := $(shell test -n "`git status --porcelain`" && echo "-dirty" || true)
33
CLI_VERSION := dev-$(GIT_COMMIT)$(DIRTY_SUFFIX)
4+
KUBO_VERSION ?= latest
5+
KUBO_DOCKER_NAME ?= kubo-$(KUBO_VERSION)-gateway-conformance
46

57
all: gateway-conformance
68

79
clean: clean-docker
810
rm -f ./gateway-conformance
911
rm -f *.ipns-record
1012
rm -f fixtures.car
11-
rm -f dnslinks.json
12-
rm -f ./reports/*
13+
rm -f dnslinks.*
14+
rm -f dnslink*.yml
15+
rm -rf ./reports/*
1316

1417
test-cargateway: provision-cargateway fixtures.car gateway-conformance
1518
./gateway-conformance test --json reports/output.json --gateway-url http://127.0.0.1:8040 --specs -subdomain-gateway
@@ -22,13 +25,27 @@ test-kubo: provision-kubo gateway-conformance
2225
./gateway-conformance test --json reports/output.json --gateway-url http://127.0.0.1:8080 --specs -subdomain-gateway
2326

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

2830
provision-kubo:
2931
find ./fixtures -name '*.car' -exec ipfs dag import --stats --pin-roots=false {} \;
3032
find ./fixtures -name '*.ipns-record' -exec sh -c 'ipfs routing put --allow-offline /ipns/$$(basename -s .ipns-record "{}" | cut -d'_' -f1) "{}"' \;
3133

34+
#start-kubo-docker: stop-kubo-docker gateway-conformance
35+
# ./gateway-conformance extract-fixtures --dir=.temp/fixtures
36+
# docker pull ipfs/kubo:$(KUBO_VERSION)
37+
# docker run -d --rm --net=host --name $(KUBO_DOCKER_NAME) -v "$(shell realpath .temp/fixtures)":/fixtures -v kubo-config.example.sh:/container-init.d/001-config.sh ipfs/kubo:$(KUBO_VERSION) daemon --init --offline
38+
# @until docker exec $(KUBO_DOCKER_NAME) ipfs --api=/ip4/127.0.0.1/tcp/5001 dag stat /ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >/dev/null 2>&1; do sleep 0.1; done
39+
# docker exec $(KUBO_DOCKER_NAME) find /fixtures -name '*.car' -exec ipfs dag import --stats --pin-roots=false {} \;
40+
# docker exec $(KUBO_DOCKER_NAME) find /fixtures -name '*.ipns-record' -exec sh -c 'ipfs routing put --allow-offline /ipns/$$(basename -s .ipns-record "{}" | cut -d'_' -f1) "{}"' \;
41+
# TODO: provision Kubo config at Gateway.PublicGateways to have subdomain gateway on example.com and also enable inlining on localhost
42+
# See: https://github.com/ipfs/kubo/blob/a07852a3f0294974b802923fb136885ad077384e/.github/workflows/gateway-conformance.yml#L22-L34
43+
# (this is not as trivial as it sounds because Kubo does not apply config inrealtime, and a restart is required.)
44+
45+
stop-kubo-docker: clean
46+
docker stop $(KUBO_DOCKER_NAME) || true
47+
docker rm -f $(KUBO_DOCKER_NAME) || true
48+
3249
# tools
3350
fixtures.car: gateway-conformance
3451
./gateway-conformance extract-fixtures --merged=true --dir=.

README.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
- [CLI](#cli)
2525
- [Docker](#docker)
2626
- [Github Action](#github-action)
27-
- [Web Dashboard](#web-dashboard)
2827
- [Commands](#commands)
2928
- [Examples](#examples)
3029
- [Releases](#releases)
3130
- [Development](#development)
3231
- [Test DSL Syntax](#test-dsl-syntax)
32+
- [Web Dashboard](#web-dashboard)
3333
- [License](#license)
3434

3535
<!-- /TOC -->
@@ -67,25 +67,32 @@ Two high level [commands](/docs/commands.md) exist:
6767
```console
6868
$ # Install the gateway-conformance binary
6969
$ go install github.com/ipfs/gateway-conformance/cmd/gateway-conformance@latest
70-
$ # run subdomain-gateway tests against endpoint at http://localhost:8080 output as JSON
71-
$ gateway-conformance test --gateway-url http://localhost:8080 --json report.json --specs +subdomain-gateway,-path-gateway -- -timeout 30m
70+
71+
$ # skip path gateway tests, and run subdomain-gateway tests against endpoint at http://127.0.0.1:8080 and use *.ipfs.example.com subdomains, output as JSON
72+
$ gateway-conformance test --gateway-url http://127.0.0.1:8080 --subdomain-url http://example.com:8080 --json report.json --specs +subdomain-gateway,-path-gateway -- -timeout 5m
7273
```
7374

74-
If you are looking for TLDR, see [examples](/docs/examples.md).
75+
> [!TIP]
76+
> If want skip individual tests, or only run specific ones based on a regex, see [`/docs/examples`](/docs/examples.md).
7577
7678
### Docker
7779

78-
Prebuilt image at `ghcr.io/ipfs/gateway-conformance` can be used for both `test` and `extract-fixtures` commands:
80+
The `gateway-conformace` requires golang runtime to be present to facilitate `go test`.
81+
If you want to run it on a box without having to instal golang runtime, prebuilt image at `ghcr.io/ipfs/gateway-conformance` is provided.
82+
83+
It can be used for both `test` and `extract-fixtures` commands:
7984

8085
```console
81-
$ # extract fixtures to ./fixtures directory
82-
$ docker run -v "${PWD}:/workspace" -w "/workspace" ghcr.io/ipfs/gateway-conformance:vA.B.C extract-fixtures --directory fixtures --merged false
86+
$ # extract fixtures to ./extracted-fixtures directory under the current user's permissions
87+
$ docker run -u "$(id -u):$(id -g)" -v "$(pwd):/workspace" -w "/workspace" ghcr.io/ipfs/gateway-conformance:latest extract-fixtures --directory extracted-fixtures
8388

84-
$ # run subdomain-gateway tests against endpoint at http://localhost:8080
85-
$ docker run --network host -v "${PWD}:/workspace" -w "/workspace" ghcr.io/ipfs/gateway-conformance:vA.B.C test --gateway-url http://localhost:8080 --json report.json --specs +subdomain-gateway,-path-gateway -- -timeout 30m
89+
$ # skip path gateway tests, and run subdomain-gateway tests against endpoint at http://127.0.0.1:8080 and use *.ipfs.example.com subdomains, output as JSON
90+
$ docker run --net=host -u "$(id -u):$(id -g)" -v "$(pwd):/workspace" -w "/workspace" ghcr.io/ipfs/gateway-conformance:latest test --gateway-url http://127.0.0.1:8080 --subdomain-url http://example.com:8080 --json report.json --specs +subdomain-gateway,-path-gateway -- -timeout 5m
8691
```
8792

88-
**NOTE:** replace `vA.B.C` with a [semantic version](https://github.com/ipfs/gateway-conformance/releases) version you want to test against
93+
> [!IMPORTANT]
94+
> - for stable CI/CD, replace `latest` with a [semantic version](https://github.com/ipfs/gateway-conformance/releases) version you want to test against
95+
> - `-u` ensures extracted fixtures and created report files can be read by your local user, make sure to adjust it to suit your use case
8996
9097
### Github Action
9198

@@ -94,22 +101,9 @@ Common operations are possible via reusable GitHub actions:
94101
- [`ipfs/gateway-conformance/.github/actions/extract-fixtures`](https://github.com/ipfs/gateway-conformance/blob/main/.github/actions/extract-fixtures/action.yml)
95102

96103
To learn how to integrate them in the CI of your project, see real world examples in:
97-
- [`kubo/../gateway-conformance.yml`](https://github.com/ipfs/kubo/blob/master/.github/workflows/gateway-conformance.yml) (fixtures imported into tested node)
98-
- [`boxo/../gateway-conformance.yml`](https://github.com/ipfs/boxo/blob/main/.github/workflows/gateway-conformance.yml) (fixtures imported into a sidecar kubo node that is peered with tested library)
99-
- [`rainbow/../gateway-conformance.yml`](https://github.com/ipfs/rainbow/blob/main/.github/workflows/gateway-conformance.yml) (fixtures imported into a kubo node that acts as a delegated block backend)
100-
101-
### Web Dashboard
102-
103-
Conformance test suite output can be plain text or JSON, which in turn can be
104-
represented as a web dashboard which aggregates results from many test runs and
105-
renders them on a static website.
106-
107-
The Implementation Dashboard instance at
108-
[conformance.ipfs.tech](https://conformance.ipfs.tech/) is a view that
109-
showcases some of well known and complete implementations of IPFS Gateways
110-
in the ecosystem.
111-
112-
Learn more at [`/docs/web-dashboard.md`](/docs/web-dashboard.md)
104+
- [`kubo/../gateway-conformance.yml`](https://github.com/ipfs/kubo/blob/master/.github/workflows/gateway-conformance.yml) (fixtures imported into tested kubo node that exposes HTTP gateway feature)
105+
- [`boxo/../gateway-conformance.yml`](https://github.com/ipfs/boxo/blob/main/.github/workflows/gateway-conformance.yml) (fixtures imported into a sidecar kubo node that is peered with small HTTP server used for testing `boxo/gateway` library)
106+
- [`rainbow/../gateway-conformance.yml`](https://github.com/ipfs/rainbow/blob/main/.github/workflows/gateway-conformance.yml) (fixtures imported into a kubo node that acts as a remote block provider, than tested against different `boxo/gateway` backends)
113107

114108
## Commands
115109

@@ -142,6 +136,19 @@ Interested in write a new test case?
142136
Test cases are written in Domain Specific Language (DLS) based on Golang.
143137
More details at [`/docs/test-dsl-syntax.md`](/docs/test-dsl-syntax.md)
144138

139+
### Web Dashboard
140+
141+
Conformance test suite output can be plain text or JSON, which in turn can be
142+
represented as a web dashboard which aggregates results from many test runs and
143+
renders them on a static website.
144+
145+
Experimental Implementation Dashboard instance at
146+
[conformance.ipfs.tech](https://conformance.ipfs.tech/) is a view that
147+
showcases some of well known and complete implementations of IPFS Gateways
148+
in the ecosystem.
149+
150+
Learn more at [`/docs/web-dashboard.md`](/docs/web-dashboard.md)
151+
145152
## License
146153

147154
This project is dual-licensed under Apache 2.0 and MIT terms:

0 commit comments

Comments
 (0)