MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestModelDescriptorsRedaction

Function TestModelDescriptorsRedaction

controlplane/admin/models_api_test.go:23–74  ·  view source on GitHub ↗

TestModelDescriptorsRedaction is the no-DB guard for the load-bearing security invariant of the models explorer: secret-bearing columns must never appear as browsable columns. Because the listing scans into the typed model and marshals via json tags, a field tagged json:"-" is dropped — this test pi

(t *testing.T)

Source from the content-addressed store, hash-verified

21// (jsonFieldOrder) honors it. If someone retags Password/Ciphertext/S3SecretKey
22// to be serialized, this fails before the secret can leak through the UI.
23func TestModelDescriptorsRedaction(t *testing.T) {
24 descs := modelDescriptors()
25
26 // Registry must cover exactly the persisted models we expect.
27 wantKeys := map[string]bool{
28 "orgs": true, "org-teams": true, "org-users": true, "org-user-secrets": true, "managed-warehouses": true,
29 "cp-instances": true, "worker-records": true,
30 "org-connection-queue": true, "org-connection-leases": true,
31 "operators": true,
32 }
33 seen := map[string]bool{}
34 for _, d := range descs {
35 if seen[d.Key] {
36 t.Fatalf("duplicate descriptor key %q", d.Key)
37 }
38 seen[d.Key] = true
39 if d.Table == "" {
40 t.Errorf("descriptor %q has empty Table (missing TableName?)", d.Key)
41 }
42 if d.newSlice == nil || d.elem == nil {
43 t.Errorf("descriptor %q missing newSlice/elem", d.Key)
44 }
45 }
46 for k := range wantKeys {
47 if !seen[k] {
48 t.Errorf("registry missing expected model %q", k)
49 }
50 }
51 for k := range seen {
52 if !wantKeys[k] {
53 t.Errorf("registry has unexpected model %q (update test if intentional)", k)
54 }
55 }
56
57 // Sensitive columns must not be derivable for the UI.
58 mustHide := map[string][]string{
59 "org-users": {"password"},
60 "org-user-secrets": {"ciphertext"},
61 }
62 for _, d := range descs {
63 cols := jsonFieldOrder(d.elem)
64 lower := map[string]bool{}
65 for _, c := range cols {
66 lower[strings.ToLower(c)] = true
67 }
68 for _, bad := range mustHide[d.Key] {
69 if lower[strings.ToLower(bad)] {
70 t.Errorf("model %q exposes column %q — must be json:\"-\"", d.Key, bad)
71 }
72 }
73 }
74}
75
76// TestModelsAPIPostgres exercises the real query path against the config store:
77// sidebar counts, a config-schema listing, a runtime-schema listing (schema

Callers

nothing calls this directly

Calls 2

modelDescriptorsFunction · 0.85
jsonFieldOrderFunction · 0.85

Tested by

no test coverage detected