Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Allow API tokens with OIDC enabled

rcourtman3fe152bba8a0
diff --git a/internal/api/oidc_token_auth_test.go b/internal/api/oidc_token_auth_test.go
new file mode 100644
index 0000000000..fff59e91b8
--- /dev/null
+++ b/internal/api/oidc_token_auth_test.go
@@ -0,0 +1,40 @@
+package api
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+)
+
+func TestAdminEndpointsAllowAPITokenWhenOIDCEnabled(t *testing.T) {
+ t.Setenv("ALLOW_ADMIN_BYPASS", "")
+ t.Setenv("PULSE_DEV", "")
+ t.Setenv("NODE_ENV", "")
+ resetAdminBypassState()
+
+ rawToken := "oidc-admin-token-123.12345678"
+ record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsRead}, nil)
+
+ dataDir := t.TempDir()
+ cfg := &config.Config{
+ DataPath: dataDir,
+ ConfigPath: dataDir,
+ OIDC: &config.OIDCConfig{
+ Enabled: true,
+ },
+ APITokens: []config.APITokenRecord{record},
+ }
+
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ req := httptest.NewRequest(http.MethodGet, "/api/system/settings", nil)
+ req.Header.Set("X-API-Token", rawToken)
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected 200 with API token, got %d", rec.Code)
+ }
+}