Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c4bf08f
docs(specs): spec 040 delivery as one Gameplane PR plus the sftp repo PR
claude Nov 23, 2026
701bb8e
feat(agent): stat, rename and streaming upload file routes (spec 040 …
claude Nov 23, 2026
d32f9a9
test(agent): count /files/stream as a transfer route in the timeout test
claude Nov 23, 2026
e0d85ab
test(agent): cover the new file routes' error paths
claude Nov 23, 2026
2bbb87c
feat(api): SFTP credentials, sessions, file-access helper and file ro…
claude Nov 23, 2026
4488829
fix(agent): close test responses and drop locate's unused create flag
claude Nov 23, 2026
6dd385e
fix(api): address lint on the SFTP credential code
claude Nov 23, 2026
3b6a696
fix(api): rename the SFTP service prefix constant and inherit the tes…
claude Nov 23, 2026
0d87a1f
test(api): ask for problem JSON in the new SFTP handler tests
claude Nov 23, 2026
2f3fa4e
test(api): cover the SFTP store, guard, audit source, file access and…
claude Nov 23, 2026
92d57cf
feat: SFTP chart, upload size setting and file-only pods for stopped …
claude Nov 23, 2026
7fca200
fix(api): keep the file pod alive during long transfers, answer 413 f…
claude Nov 23, 2026
0b1236c
test(api): use the inherited context in the SFTP session fault tests
claude Nov 23, 2026
b3be155
design: spec 040 SFTP screens (T004)
claude Nov 23, 2026
a759a19
feat(api): add POST /sftp/v1/sessions/end
claude Nov 23, 2026
4544075
design: polish spec 040 SFTP screens
claude Nov 23, 2026
ce4a312
design: float SFTP overlays over full pages
claude Nov 23, 2026
00bbd27
design: clearer files-starting state
claude Nov 23, 2026
e768bec
feat(api): admin SFTP credential routes for users
claude Nov 23, 2026
4e84c98
feat(sftp): per-cluster SFTP endpoint and service tokens
claude Nov 23, 2026
211fcaf
feat(web): personal SFTP page and admin SFTP drawer
claude Nov 23, 2026
25c799c
feat(web): cluster SFTP endpoint drawer on Clusters
claude Nov 23, 2026
d40528f
feat(web): stream dashboard uploads with per-file progress (040)
claude Nov 23, 2026
6880329
fix: spec 040 review follow-ups
claude Nov 23, 2026
0485c55
test(web): stub XMLHttpRequest in Files upload tests (approved rows 7-9)
claude Nov 23, 2026
e0e0669
fix(web): keep the default retry policy for file list errors
claude Nov 23, 2026
41b3fb8
Merge master into feat/040-sftp-access
claude Nov 23, 2026
a5f740f
chore: add the sftp component submodule (spec 040 T023)
claude Nov 23, 2026
08e782c
test(e2e): sftp bucket, docs and changelog for spec 040
claude Nov 23, 2026
a2db1f2
test(e2e): finish spec 040 e2e and docs
claude Nov 23, 2026
d605cef
Merge master into feat/040-sftp-access
claude Nov 23, 2026
6cee6d2
ci(e2e): build and load the sftp image and map the SFTP suites
claude Nov 23, 2026
ee0f60f
chore: restore the code-generator checksum in go.work.sum
claude Nov 23, 2026
1d1aa10
fix(api): name unused reactor parameters _ in the host-key tests
claude Nov 23, 2026
ad94cc0
fix(web): translate the SFTP literals and drive the upload queue from…
claude Nov 23, 2026
91bf3a7
design: re-apply spec 040 screens on master's design
claude Nov 23, 2026
21f6084
test(e2e): keep alice's SFTP connection open across the lifecycle sub…
claude Nov 23, 2026
16441f4
test(e2e): read SFTP cluster error ids from problem+json
claude Nov 23, 2026
9c999a5
fix: spec 040 review findings
claude Nov 23, 2026
07d4589
fix(api): satisfy noctx and unused-parameter in the SFTP stream test
claude Nov 23, 2026
7a7ced8
test(api): cover the SFTP cluster routes in the home-client mount checks
claude Nov 23, 2026
7fd0bc6
test(e2e): run the remote SFTP check inside TestMultiCluster_TokenRem…
claude Nov 23, 2026
809faa6
test(e2e): SFTP uploads stay atomic; amend SC-003
claude Nov 23, 2026
9d7cdab
test(api): give the SFTP envtest clusters the required kubeconfig sec…
claude Nov 23, 2026
00400e5
feat(api): report per-server write access in the SFTP server listing
claude Nov 23, 2026
99c3bf6
Merge origin/master into feat/040-sftp-access
claude Nov 23, 2026
0323e52
chore: bump sftp to refuse writes on read-only servers at open (sftp#2)
claude Nov 23, 2026
fdf8d6b
design: re-apply spec 040 screens on master's design.fig
claude Nov 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions .github/actions/build-e2e-images/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: build e2e images
description: >
Build the operator/api/agent/sentinel/capture-sidecar/telemetry-receiver/fakeoidc/mcp-server/audit-syslog-bridge/tunnel-frp
Build the operator/api/agent/sentinel/capture-sidecar/telemetry-receiver/fakeoidc/mcp-server/sftp/audit-syslog-bridge/tunnel-frp
(+ gameprobe) images the kind e2e suites load into the cluster, tagged
gameplane-test/<component>:e2e exactly like make e2e-images, via buildx bake
— then `docker save` all eleven into a single tar uploaded as an artifact
Expand All @@ -19,7 +19,7 @@ runs:
shell: bash
run: ./hack/submodules.sh init
- uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: bake e2e images (operator/api/agent/sentinel/capture-sidecar/telemetry-receiver/fakeoidc/mcp-server/audit-syslog-bridge/tunnel-frp)
- name: bake e2e images (operator/api/agent/sentinel/capture-sidecar/telemetry-receiver/fakeoidc/mcp-server/sftp/audit-syslog-bridge/tunnel-frp)
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7.3.0
with:
files: containers/docker-bake.hcl
Expand All @@ -34,6 +34,7 @@ runs:
e2e-telemetry-receiver.cache-from=type=gha,scope=e2e-telemetry-receiver-${{ inputs.arch }}
e2e-fakeoidc.cache-from=type=gha,scope=e2e-fakeoidc-${{ inputs.arch }}
e2e-mcp-server.cache-from=type=gha,scope=e2e-mcp-server-${{ inputs.arch }}
e2e-sftp.cache-from=type=gha,scope=e2e-sftp-${{ inputs.arch }}
e2e-audit-syslog-bridge.cache-from=type=gha,scope=e2e-audit-syslog-bridge-${{ inputs.arch }}
e2e-tunnel-frp.cache-from=type=gha,scope=e2e-tunnel-frp-${{ inputs.arch }}
e2e-operator.cache-to=type=gha,mode=max,scope=e2e-operator-${{ inputs.arch }}
Expand All @@ -44,6 +45,7 @@ runs:
e2e-telemetry-receiver.cache-to=type=gha,mode=max,scope=e2e-telemetry-receiver-${{ inputs.arch }}
e2e-fakeoidc.cache-to=type=gha,mode=max,scope=e2e-fakeoidc-${{ inputs.arch }}
e2e-mcp-server.cache-to=type=gha,mode=max,scope=e2e-mcp-server-${{ inputs.arch }}
e2e-sftp.cache-to=type=gha,mode=max,scope=e2e-sftp-${{ inputs.arch }}
e2e-audit-syslog-bridge.cache-to=type=gha,mode=max,scope=e2e-audit-syslog-bridge-${{ inputs.arch }}
e2e-tunnel-frp.cache-to=type=gha,mode=max,scope=e2e-tunnel-frp-${{ inputs.arch }}
- name: bake gameprobe image
Expand All @@ -67,6 +69,7 @@ runs:
gameplane-test/telemetry-receiver:e2e \
gameplane-test/fakeoidc:e2e \
gameplane-test/mcp-server:e2e \
gameplane-test/sftp:e2e \
gameplane-test/audit-syslog-bridge:e2e \
gameplane-test/tunnel-frp:e2e \
gameplane-test/gameprobe:e2e \
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ jobs:
- 'audit-syslog-bridge'
- 'tunnel'
- 'capture-sidecar'
- 'sftp'
- 'hack/trivy-scan-images.sh'
- 'hack/check-image-scan_test.sh'
# Narrower than e2etree on purpose: this backs a job that only
Expand Down Expand Up @@ -271,6 +272,7 @@ jobs:
- 'audit-syslog-bridge'
- 'tunnel'
- 'capture-sidecar'
- 'sftp'
- '.gitmodules'
- 'hack/submodules.sh'
- 'hack/check-submodule-freshness.sh'
Expand Down Expand Up @@ -320,6 +322,7 @@ jobs:
- 'audit-syslog-bridge'
- 'tunnel'
- 'capture-sidecar'
- 'sftp'
- '.hadolint.yaml'
- 'hack/check-hadolint_test.sh'
- 'hack/testdata/hadolint/**'
Expand Down Expand Up @@ -1238,6 +1241,8 @@ jobs:
run: bash charts/gameplane/tests/monitoring-rules.sh
- name: check MCP server RBAC scope
run: bash charts/gameplane/tests/mcp-server-rbac.sh
- name: check SFTP endpoint renders
run: bash charts/gameplane/tests/sftp.sh

standalone-compose:
name: standalone Compose smoke
Expand Down Expand Up @@ -1930,7 +1935,7 @@ jobs:
# The arm64 job below uses the same steps/settings except for the
# wake-hostport, network-isolation, management-placement,
# backup-preparation, monitoring, recovery and standalone drills, which run once on amd64.
bucket: [operator, api-auth, api-roles, api-rbac, api-agent, api-mods, telemetry, optional-components, restricted-workloads, wake-hostport, network-isolation, management-placement, backup-preparation, monitoring, recovery, standalone]
bucket: [operator, api-auth, api-roles, api-rbac, api-agent, api-mods, telemetry, optional-components, restricted-workloads, wake-hostport, network-isolation, management-placement, backup-preparation, monitoring, recovery, standalone, sftp]
arch: [amd64]
include:
- bucket: monitoring
Expand Down Expand Up @@ -1998,6 +2003,10 @@ jobs:
parallel: 1
test_timeout: 25m # Includes real projected-token rotation and node capture cleanup.
job_timeout: 60 # Boots a kind cluster, installs the chart, runs the bucket's suite.
- bucket: sftp
parallel: 1
test_timeout: 20m # chart enable, SFTP login, 32 MiB round trip, stopped-server and revocation checks
job_timeout: 60 # Boots a kind cluster, installs the chart, runs the bucket's suite.
env:
CLUSTER: gameplane-e2e
CTX: kind-gameplane-e2e
Expand Down Expand Up @@ -2929,7 +2938,7 @@ jobs:
'go-e2e-unit': (n) => n === 'go (test/e2e)',
'api-postgres': (n) => n === 'api (postgres)',
'e2e-buckets': (n) => n === 'e2e bucket coverage',
'e2e-go': (n) => /^e2e (operator|api-auth|api-roles|api-rbac|api-agent|api-mods|telemetry|optional-components|restricted-workloads|wake-hostport|network-isolation|management-placement|backup-preparation|monitoring|recovery|standalone) \//.test(n) && n.includes('/ amd64 '),
'e2e-go': (n) => /^e2e (operator|api-auth|api-roles|api-rbac|api-agent|api-mods|telemetry|optional-components|restricted-workloads|wake-hostport|network-isolation|management-placement|backup-preparation|monitoring|recovery|standalone|sftp) \//.test(n) && n.includes('/ amd64 '),
'e2e-go-arm64': (n) => /^e2e (operator|api-auth|api-roles|api-rbac|api-agent|api-mods|telemetry|optional-components|restricted-workloads) \//.test(n) && n.includes('/ arm64 '),
'e2e-multicluster': (n) => n.startsWith('e2e multicluster /') && n.includes('/ amd64 '),
'e2e-multicluster-arm64': (n) => n.startsWith('e2e multicluster /') && n.includes('/ arm64 '),
Expand Down Expand Up @@ -3082,7 +3091,7 @@ jobs:
const bucketSet = new Set();
for (const j of apiJobs) {
const n = j.name || '';
const m = n.match(/^e2e (operator|api-auth|api-roles|api-rbac|api-agent|api-mods|telemetry|optional-components|restricted-workloads|wake-hostport|network-isolation|management-placement|backup-preparation|monitoring|recovery|standalone) \//);
const m = n.match(/^e2e (operator|api-auth|api-roles|api-rbac|api-agent|api-mods|telemetry|optional-components|restricted-workloads|wake-hostport|network-isolation|management-placement|backup-preparation|monitoring|recovery|standalone|sftp) \//);
const executionGated = m && ['wake-hostport', 'recovery', 'standalone'].includes(m[1]);
if (m && !executionGated) bucketSet.add(m[1]);
// Partial selection can complete these legs without running
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/devcontainers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ on:
- 'audit-syslog-bridge'
- 'tunnel'
- 'capture-sidecar'
- 'sftp'
- 'web/package*.json'
- '.github/workflows/devcontainers.yaml'
push:
Expand All @@ -44,6 +45,7 @@ on:
- 'audit-syslog-bridge'
- 'tunnel'
- 'capture-sidecar'
- 'sftp'
- 'web/package*.json'
- '.github/workflows/devcontainers.yaml'

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/publish-edge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: publish-edge
# version-pinned install path; this is the rolling "edge" channel.
#
# Images: ghcr.io/<owner>/gameplane/{operator,api,web,agent,audit-syslog-bridge,
# telemetry-receiver,sentinel,capture-sidecar,mcp-server,tunnel-frp,
# telemetry-receiver,sentinel,capture-sidecar,mcp-server,sftp,tunnel-frp,
# tunnel-tailscale,tunnel-playit}:edge
# ...and an immutable :sha-<short> tag for pinning a specific commit.
# Consume with: helm install ... --set image.tag=edge
Expand All @@ -16,7 +16,7 @@ on:
branches: [master]
# Only rebuild when something that lands in an image changes. Docs/chart
# edits don't need a fresh image push. Every path here is a real `COPY`
# input of at least one of the 12 matrix images' Dockerfiles below (or a
# input of at least one of the 13 matrix images' Dockerfiles below (or a
# transitive Go module dependency of one) — a path missing from this list
# means a push that changes it publishes nothing to :edge until a later,
# unrelated push happens to also touch a listed path.
Expand All @@ -39,6 +39,8 @@ on:
- "capture-sidecar/**"
- "mcp-server"
- "mcp-server/**"
- "sftp"
- "sftp/**"
- "tunnel"
- "tunnel/**"
- "go.work"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- component: sentinel
- component: capture-sidecar
- component: mcp-server
- component: sftp
- component: tunnel-frp
dockerfile: tunnel/Dockerfile.frp
- component: tunnel-tailscale
Expand Down
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
url = https://github.com/GameplanePanel/capture-sidecar.git
branch = main
component = true
[submodule "sftp"]
path = sftp
url = https://github.com/GameplanePanel/sftp.git
branch = main
component = true
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ telemetry-receiver/ usage telemetry ingest
sentinel/ wake-on-connect proxy for sleeping pods
capture-sidecar/ SUBMODULE GameplanePanel/capture-sidecar (AF_PACKET BPF capture sidecar; own go.mod, not in go.work; image still built here)
mcp-server/ SUBMODULE GameplanePanel/mcp (read-only MCP server; own go.mod, not in go.work; image still built here)
sftp/ SUBMODULE GameplanePanel/sftp (SFTP endpoint for game server files, spec 040; own go.mod, not in go.work; image still built here)
tunnel/ SUBMODULE GameplanePanel/tunnel (relay client supervisor: frp, Tailscale, playit; own go.mod, not in go.work; image still built here)
web/ React 19 + strict TS + Vite dashboard; src/{routes,components,lib,router,styles,test}/
modules/ SUBMODULE GameplanePanel/module (OCI game templates)
Expand All @@ -53,15 +54,15 @@ go.work links all 12 Go modules (incl. test/e2e)
Makefile canonical task runner
```

After cloning: `git submodule update --init modules` (required for `make dev-up`) and `hack/submodules.sh init` (the split component submodules mcp-server, audit-syslog-bridge, tunnel, capture-sidecar; `make images`/`make dev-up` also init them on demand); add `git submodule update --init website` only when working on the website.
After cloning: `git submodule update --init modules` (required for `make dev-up`) and `hack/submodules.sh init` (the split component submodules mcp-server, audit-syslog-bridge, tunnel, capture-sidecar, sftp; `make images`/`make dev-up` also init them on demand); add `git submodule update --init website` only when working on the website.

## Commands (via Makefile; compile checks excepted, see rule 8)

- **Dev:** `make dev-up` (Kind + OCI registry :5001 + Helm), `make web-dev` (Vite, proxies in-cluster API), `make dev-load` (load built images; run `make images` first), `make dev-install` (Helm upgrade), `make dev-down`.
- **Build:** `make build` (all Go + web), `make build-go` (11 modules in GO_MODULES, all but test/e2e), `make build-web` (`npm ci && npm run build`), `make images`.
- **Codegen:** `make generate` (deepcopy), `make manifests` (CRD/RBAC YAML, synced to `charts/gameplane/charts/gameplane-crds/crds/` and `charts/gameplane/crd-manifests/`), `make modules-push`, `make tidy`.
- **Dev containers:** `make devcontainers` (regenerate every profile and the `website/` and `modules/` copies after editing `.devcontainer/versions.toml`, `.devcontainer/profiles.toml`, `.devcontainer/devcontainer-lock.json`, `.devcontainer/setup.sh` or a `system-deps.toml`), `make check-devcontainers` (drift check). Profile table: `docs/contributing.md`.
- **Tests (CI only — never run locally, see Rule 8):** `make test`, `make test-integration` (envtest operator+api), `make test-e2e` (~10–20 min), `make test-e2e-bucket BUCKET=(operator|api-auth|api-roles|api-rbac|api-agent|api-mods|ratelimit|bot-fast|bot-heavy|multicluster|upgrade|postgres-availability|postgres-pitr|postgres-ha|telemetry|capture-overhead|optional-components|restricted-workloads|wake-hostport|network-isolation|management-placement|backup-preparation|monitoring|recovery|standalone)`.
- **Tests (CI only — never run locally, see Rule 8):** `make test`, `make test-integration` (envtest operator+api), `make test-e2e` (~10–20 min), `make test-e2e-bucket BUCKET=(operator|api-auth|api-roles|api-rbac|api-agent|api-mods|ratelimit|bot-fast|bot-heavy|multicluster|upgrade|postgres-availability|postgres-pitr|postgres-ha|telemetry|capture-overhead|optional-components|restricted-workloads|wake-hostport|network-isolation|management-placement|backup-preparation|monitoring|recovery|standalone|sftp)`.
- **E2E conventions:** register new tests in `test/e2e/buckets.sh`; `t.Parallel()` + unique names; guard shared resources (`ociPushMu` for module pushes, `ensureResticRepo(t)` for shared backup repos). Rate limits per cluster: IP burst 10 (5/min), user burst 6 (3/min) — cap an API bucket at ~7 admin logins.
- **Lint:** `make lint` runs `check-doc-versions`, `check-links`, `check-features-sync`, `check-specs`, `check-telemetry-catalog`, `check-i18n`, `check-dev-load-images`, `check-coverage-gaps`, `check-devcontainers`, `test-up-registry`, `lint-go` and `lint-web`.

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ lint-web: ## Run web linters

# -------- images --------
# Standard-shaped images (Dockerfile path = <dir>/Dockerfile)
IMAGES := operator api web agent telemetry-receiver sentinel mcp-server capture-sidecar
IMAGES := operator api web agent telemetry-receiver sentinel mcp-server capture-sidecar sftp

# The full set of image names `make images` builds, by their docker tag
# names (not their Makefile target names — audit-syslog-bridge and the three
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ legacy default for custom deployments. See [storage and recovery](docs/standalon
| `audit-syslog-bridge/` | Go | Submodule (`GameplanePanel/audit-syslog-bridge`): HTTP-JSON to syslog relay [optional] for audit logging infrastructure. |
| `telemetry-receiver/` | Go | Collector [optional] for anonymous daily usage reports. |
| `mcp-server/` | Go | Submodule (`GameplanePanel/mcp`): strictly read-only Model Context Protocol server [optional] for AI tools. |
| `sftp/` | Go | Submodule (`GameplanePanel/sftp`): optional SFTP endpoint for game server files; every login and file operation goes through the Gameplane API. |

### Custom Resource Definitions (CRDs)

Expand Down Expand Up @@ -210,6 +211,7 @@ Gameplane extends Kubernetes using custom resources under `gameplane.local/v1alp
├── audit-syslog-bridge/ # Submodule: optional syslog relay for audit logs
├── telemetry-receiver/ # Optional anonymous usage telemetry receiver
├── mcp-server/ # Submodule: optional read-only MCP server (GameplanePanel/mcp)
├── sftp/ # Submodule: optional SFTP endpoint for game server files (GameplanePanel/sftp)
├── charts/gameplane/ # Helm deployment chart
├── deploy/kind/ # Local dev environment bootstrap scripts
├── deploy/standalone/ # API + dashboard Docker Compose deployment
Expand Down Expand Up @@ -273,7 +275,7 @@ Ed25519 key and do not have transparency log entries — verify them with
Requires: Go 1.27+, Node 20+, Docker, kind, kubectl, helm,
[oras](https://oras.land/docs/installation) (>= 1.2.0).

The game modules and the split components live in separate `GameplanePanel/*` repos, wired in here as submodules: `modules/` (`GameplanePanel/module`) and the component submodules `mcp-server/`, `audit-syslog-bridge/`, `tunnel/` and `capture-sidecar/` (`GameplanePanel/mcp`, `/audit-syslog-bridge`, `/tunnel`, `/capture-sidecar`). Clone with submodules (or initialize them after):
The game modules and the split components live in separate `GameplanePanel/*` repos, wired in here as submodules: `modules/` (`GameplanePanel/module`) and the component submodules `mcp-server/`, `audit-syslog-bridge/`, `tunnel/`, `capture-sidecar/` and `sftp/` (`GameplanePanel/mcp`, `/audit-syslog-bridge`, `/tunnel`, `/capture-sidecar`, `/sftp`). Clone with submodules (or initialize them after):

```sh
git clone --recurse-submodules <repo-url>
Expand Down
63 changes: 63 additions & 0 deletions agent/cmd/files_only_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/go-chi/chi/v5"

"github.com/GameplanePanel/gameplane/agent/internal/rcon"
"github.com/GameplanePanel/gameplane/agent/internal/status"
)

// newTestRoutes builds the protected routes the way main does, with no
// game attached: RCON is disabled and no game log, mods or caps are declared.
func newTestRoutes(t *testing.T, filesOnly bool) http.Handler {
t.Helper()
transport := rcon.Disabled{}
r := chi.NewRouter()
protectedRoutes{
dataRoot: t.TempDir(),
maxUploadBytes: 1 << 20,
rconClient: transport,
commands: rcon.NewCommands(transport),
gameName: "test-game",
statusSource: status.New(transport, nil),
filesOnly: filesOnly,
}.mount(r)
return r
}

func serve(t *testing.T, h http.Handler, method, target string) int {
t.Helper()
rr := httptest.NewRecorder()
req := httptest.NewRequestWithContext(context.Background(), method, target, nil)
h.ServeHTTP(rr, req)
return rr.Code
}

func TestFilesOnlyRouterServesOnlyFiles(t *testing.T) {
h := newTestRoutes(t, true)

for _, target := range []string{"/console", "/players", "/mods", "/logs/tail", "/status", "/lifecycle", "/actions"} {
if code := serve(t, h, http.MethodGet, target); code != http.StatusNotFound {
t.Errorf("files-only GET %s code=%d, want 404", target, code)
}
}
if code := serve(t, h, http.MethodGet, "/files/stat?path=/"); code == http.StatusNotFound {
t.Errorf("files-only GET /files/stat code=404, want the file routes mounted")
}
}

func TestFullRouterKeepsGameRoutes(t *testing.T) {
h := newTestRoutes(t, false)

if code := serve(t, h, http.MethodGet, "/status"); code == http.StatusNotFound {
t.Errorf("full GET /status code=404, want the status route mounted")
}
if code := serve(t, h, http.MethodGet, "/files/stat?path=/"); code == http.StatusNotFound {
t.Errorf("full GET /files/stat code=404, want the file routes mounted")
}
}
Loading
Loading