mirror of
https://github.com/hanzoai/cloud.git
synced 2026-11-23 21:00:04 +00:00
Port all applicable OSS core framework, web console, and secret-detection fixes into github.com/hanzoai/cloud while preserving the strict public/OSS module boundary (zero private imports, plans, or secrets): - OIDC Discovery 1.0 & multi-issuer trust (sdk/discovery.go, sdk/oidctest, sdk/brand, sdk/auth_identity.go, sdk/config.go, sdk/deps.go, sdk/durable.go, sdk/token_validator.go, sdk/middleware_identity.go): trust issuers and JWKS named by each brand's discovery document; propagate VerifiedIdentity.Issuer, VerifiedIdentity.BillingAccount, and CallerIssuer. - Delegated-token liveness & confined sub-scopes (sdk/delegation.go, sdk/confined.go, sdk/middleware_identity.go, sdk/delegation_confined_test.go): never negative-cache IAM introspection active=false answers for 30s; allow /v1/decisions and opt-in confined `research` and `workflow:gpu` sub-scopes (blocking grants/authorize and non-gpu namespaces). - Unified fault fingerprinting & job-ID normalization (sdk/fault, sdk/errmap.go, sdk/hooks.go): RFC 9457 fingerprint extension member on all non-2xx responses, hex/alnum job-ID normalization, and ReportFault(fault.Fault) hook. - Tier & plan peer normalization (sdk/peers.go, sdk/tier_peer.go, sdk/tier_plan.go, sdk/tier_peer_test.go): add PlanOf/Plan(), check Plan in TierAllows, and normalize composite "<org>/<user>" namespaces to "<org>". - Shared retry helper (sdk/retry), S3 bucket affix clamping (sdk/object/naming.go), and system-role prompt separation test (sdk/infer/http_test.go). - Web console strict MIME pinning & no-store 404s (webui.go, webui_test.go): pin .js/.mjs/.cjs/.css/.wasm/.json/.map/.svg MIME types for distroless images and return uncached 404 for missing bundler chunks under assets/, _next/static/, _astro/, and _app/immutable/. - Secret detection catalog upgrade (clients/security/detect): expand to 26 rules with excludePrefixes and unit tests. - Dependencies & CI: bump github.com/hanzoai/iam v1.34.198 and github.com/hanzoai/tasks v1.53.12 (both served by proxy.golang.org); run the CI check job on pull requests to main.
126 lines
4.2 KiB
Go
126 lines
4.2 KiB
Go
package cloud
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"testing/fstest"
|
|
|
|
"github.com/hanzoai/cloud/console"
|
|
"github.com/zap-proto/zip"
|
|
)
|
|
|
|
func get(t *testing.T, app *zip.App, path string) (*http.Response, string) {
|
|
t.Helper()
|
|
req, err := http.NewRequest("GET", "http://x"+path, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
res, err := app.Fiber().Test(req)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, _ := io.ReadAll(res.Body)
|
|
return res, string(b)
|
|
}
|
|
|
|
func TestTmpConsole(t *testing.T) {
|
|
app := zip.New(zip.Config{})
|
|
mountHealth(app)
|
|
app.Raw(http.MethodGet, "/v1/kv/:key", func(c *zip.Ctx) error { return c.JSON(200, map[string]string{"k": c.Param("key")}) })
|
|
if err := mountConsole(app); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
cases := []struct {
|
|
path string
|
|
status int
|
|
ctype string
|
|
want string
|
|
}{
|
|
{"/", 200, "text/html", "<title>cloud console</title>"},
|
|
{"/console.css", 200, "text/css", "--accent"},
|
|
{"/console.js", 200, "javascript", "openapi.json"},
|
|
{"/kv", 200, "text/html", "<title>"},
|
|
{"/deep/client/route", 200, "text/html", "console.js"},
|
|
{"/../webui.go", 200, "text/html", "<title>"},
|
|
{"/healthz", 200, "application/json", `{"status":"ok"}`},
|
|
{"/readyz", 200, "application/json", `{"status":"ok"}`},
|
|
{"/v1/nope", 404, "application/json", `{"error":{"code":"not_found","message":"no such route"}}`},
|
|
{"/v1", 404, "application/json", "not_found"},
|
|
{"/zap/x", 404, "application/json", "not_found"},
|
|
{"/v1/kv/abc", 200, "application/json", `"k":"abc"`},
|
|
}
|
|
for _, c := range cases {
|
|
res, body := get(t, app, c.path)
|
|
if res.StatusCode != c.status {
|
|
t.Errorf("%s: status %d want %d", c.path, res.StatusCode, c.status)
|
|
}
|
|
if ct := res.Header.Get("Content-Type"); !strings.Contains(ct, c.ctype) {
|
|
t.Errorf("%s: content-type %q want %q", c.path, ct, c.ctype)
|
|
}
|
|
if !strings.Contains(body, c.want) {
|
|
t.Errorf("%s: body %q missing %q", c.path, body[:min(len(body), 120)], c.want)
|
|
}
|
|
}
|
|
|
|
if err := serveFS(zip.New(zip.Config{}), fstest.MapFS{"other.txt": {Data: []byte("x")}}); err == nil {
|
|
t.Error("serveFS accepted an FS with no index.html")
|
|
}
|
|
|
|
_ = console.FS()
|
|
}
|
|
|
|
func TestPinnedWebMIMETypesAndMissingChunk404(t *testing.T) {
|
|
bundle := fstest.MapFS{
|
|
"index.html": {Data: []byte("<!doctype html><title>app</title>")},
|
|
"_next/static/chunks/mod-DeKYn5x6.mjs": {Data: []byte("export const ok = true;")},
|
|
"assets/shim-KSQZTTM6.cjs": {Data: []byte("module.exports = 1;")},
|
|
"assets/core.wasm": {Data: []byte{0x00, 0x61, 0x73, 0x6d}},
|
|
"assets/app.css": {Data: []byte("body{color:#fff}")},
|
|
"assets/logo.svg": {Data: []byte("<svg/>")},
|
|
"assets/app.js.map": {Data: []byte("{}")},
|
|
}
|
|
app := zip.New(zip.Config{})
|
|
if err := serveFS(app, bundle); err != nil {
|
|
t.Fatalf("serveFS: %v", err)
|
|
}
|
|
|
|
for target, wantCT := range map[string]string{
|
|
"/_next/static/chunks/mod-DeKYn5x6.mjs": "text/javascript; charset=utf-8",
|
|
"/assets/shim-KSQZTTM6.cjs": "text/javascript; charset=utf-8",
|
|
"/assets/core.wasm": "application/wasm",
|
|
"/assets/app.css": "text/css; charset=utf-8",
|
|
"/assets/logo.svg": "image/svg+xml",
|
|
"/assets/app.js.map": "application/json; charset=utf-8",
|
|
} {
|
|
res, _ := get(t, app, target)
|
|
if res.StatusCode != http.StatusOK {
|
|
t.Fatalf("GET %s status = %d, want 200", target, res.StatusCode)
|
|
}
|
|
if got := res.Header.Get("Content-Type"); got != wantCT {
|
|
t.Errorf("GET %s Content-Type = %q, want %q", target, got, wantCT)
|
|
}
|
|
}
|
|
|
|
// Missing chunks under bundler build-output subtrees must 404 (no-store)
|
|
// instead of falling back to 200 text/html.
|
|
for _, target := range []string{
|
|
"/_next/static/chunks/stale-0j34vdo5b19hg.js",
|
|
"/assets/index-DeKYn5x6.js",
|
|
"/pay/_next/static/chunks/main.js",
|
|
"/_astro/hoisted.abc123.js",
|
|
"/_app/immutable/entry/app.js",
|
|
"/v1/missing-endpoint",
|
|
} {
|
|
res, _ := get(t, app, target)
|
|
if res.StatusCode != http.StatusNotFound {
|
|
t.Errorf("GET %s status = %d, want 404", target, res.StatusCode)
|
|
}
|
|
if got := res.Header.Get("Cache-Control"); got != "no-store, max-age=0" {
|
|
t.Errorf("GET %s Cache-Control = %q, want %q", target, got, "no-store, max-age=0")
|
|
}
|
|
}
|
|
}
|