mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-30 12:30:17 +00:00
test: enforce settings:write for config node mutations
This commit is contained in:
parent
ead8eb7087
commit
ad21be68f3
1 changed files with 33 additions and 0 deletions
|
|
@ -1189,6 +1189,39 @@ func TestConfigNodesWriteRequiresSettingsWriteScope(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestConfigNodeMutationsRequireSettingsWriteScope(t *testing.T) {
|
||||
rawToken := "config-node-mutate-token-123.12345678"
|
||||
record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsRead}, nil)
|
||||
cfg := newTestConfigWithTokens(t, record)
|
||||
router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
|
||||
|
||||
paths := []struct {
|
||||
method string
|
||||
path string
|
||||
body string
|
||||
}{
|
||||
{method: http.MethodPost, path: "/api/config/nodes/test-config", body: `{}`},
|
||||
{method: http.MethodPost, path: "/api/config/nodes/test-connection", body: `{}`},
|
||||
{method: http.MethodPut, path: "/api/config/nodes/node-1", body: `{}`},
|
||||
{method: http.MethodDelete, path: "/api/config/nodes/node-1", body: ""},
|
||||
{method: http.MethodPost, path: "/api/config/nodes/node-1/test", body: `{}`},
|
||||
{method: http.MethodPost, path: "/api/config/nodes/node-1/refresh-cluster", body: `{}`},
|
||||
}
|
||||
|
||||
for _, tc := range paths {
|
||||
req := httptest.NewRequest(tc.method, tc.path, strings.NewReader(tc.body))
|
||||
req.Header.Set("X-API-Token", rawToken)
|
||||
rec := httptest.NewRecorder()
|
||||
router.Handler().ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusForbidden {
|
||||
t.Fatalf("expected 403 for missing settings:write scope on %s %s, got %d", tc.method, tc.path, rec.Code)
|
||||
}
|
||||
if !strings.Contains(rec.Body.String(), config.ScopeSettingsWrite) {
|
||||
t.Fatalf("expected missing scope response to mention %q, got %q", config.ScopeSettingsWrite, rec.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecurityOIDCRequiresSettingsWriteScope(t *testing.T) {
|
||||
rawToken := "security-oidc-token-123.12345678"
|
||||
record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsRead}, nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue