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.

test: require auth for logs and update status

rcourtmaned0f85149d6a
diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.go
index 4b82d65971..dec2b20444 100644
--- a/internal/api/security_regression_test.go
+++ b/internal/api/security_regression_test.go
@@ -506,6 +506,26 @@ func TestLogEndpointsRequireSettingsReadScope(t *testing.T) {
}
}
+func TestLogEndpointsRequireAuthInAPIMode(t *testing.T) {
+ record := newTokenRecord(t, "log-auth-token-123.12345678", []string{config.ScopeSettingsRead}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ paths := []string{
+ "/api/logs/stream",
+ "/api/logs/download",
+ }
+
+ for _, path := range paths {
+ req := httptest.NewRequest(http.MethodGet, path, nil)
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+ if rec.Code != http.StatusUnauthorized {
+ t.Fatalf("expected 401 without auth on %s, got %d", path, rec.Code)
+ }
+ }
+}
+
func TestLogLevelReadRequiresSettingsReadScope(t *testing.T) {
rawToken := "log-level-read-token-123.12345678"
record := newTokenRecord(t, rawToken, []string{config.ScopeMonitoringRead}, nil)
@@ -568,6 +588,19 @@ func TestUpdateReadEndpointsRequireSettingsReadScope(t *testing.T) {
}
}
+func TestUpdateStatusRequiresAuthInAPIMode(t *testing.T) {
+ record := newTokenRecord(t, "update-auth-token-123.12345678", []string{config.ScopeSettingsRead}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ req := httptest.NewRequest(http.MethodGet, "/api/updates/status", nil)
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+ if rec.Code != http.StatusUnauthorized {
+ t.Fatalf("expected 401 without auth, got %d", rec.Code)
+ }
+}
+
func TestUpdateApplyRequiresSettingsWriteScope(t *testing.T) {
rawToken := "updates-write-token-123.12345678"
record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsRead}, nil)