Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Complete Fleet growth analytics coverage (#7343)

Francesco Bonacci4da67bb61c26
diff --git a/libs/fleet/backend/auth/auth.go b/libs/fleet/backend/auth/auth.go
index c10ca48a5d..30883963a9 100644
--- a/libs/fleet/backend/auth/auth.go
+++ b/libs/fleet/backend/auth/auth.go
@@ -258,6 +258,8 @@ func validateKeycloak(raw string) (*User, error) {
Namespace: str(claims, "namespace"),
PrincipalType: PrincipalTypeUser,
Claims: map[string]string{
+ "sid": str(claims, "sid"),
+ "session_state": str(claims, "session_state"),
"preferred_username": str(claims, "preferred_username"),
"user_sub": str(claims, "user_sub"),
"user_groups": str(claims, "user_groups"),
diff --git a/libs/fleet/backend/handlers/analytics_test.go b/libs/fleet/backend/handlers/analytics_test.go
index 5965989b91..f087083efb 100644
--- a/libs/fleet/backend/handlers/analytics_test.go
+++ b/libs/fleet/backend/handlers/analytics_test.go
@@ -26,7 +26,8 @@ func TestRecordAnalyticsSessionCapturesSuccessfulSPALogin(t *testing.T) {
capture := &analyticsCapture{}
h := Handlers{Analytics: capture, AuthCfg: configAuthForAnalytics()}
request := httptest.NewRequest(http.MethodPost, "/api/analytics/session", nil)
- ctx := context.WithValue(request.Context(), auth.UserKey, &auth.User{ID: "subject-1", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser})
+ user := &auth.User{ID: "subject-1", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}
+ ctx := context.WithValue(request.Context(), auth.UserKey, user)
ctx = context.WithValue(ctx, middlewares.ContextKey("traceId"), "trace-1")
response := httptest.NewRecorder()
diff --git a/libs/fleet/backend/main.go b/libs/fleet/backend/main.go
index 05ab7e6ba2..6edcef7469 100644
--- a/libs/fleet/backend/main.go
+++ b/libs/fleet/backend/main.go
@@ -140,6 +140,7 @@ func setupRouter(c handlers.Handlers) http.Handler {
r := http.NewServeMux()
svcQualifier := c.FleetAttributionQualification()
+ loginObserver := productanalytics.LoginObserver(c.Analytics, c.AuthCfg.SPAClientID)
r.Handle("GET /healthz", onlyLog("/healthz", c.GetHealth))
r.Handle("GET /readyz", onlyLog("/readyz", c.GetReadiness))
@@ -237,9 +238,11 @@ func setupRouter(c handlers.Handlers) http.Handler {
r.Handle("/api/svc/{namespace}/{service}",
withAuthenticatedMiddlewares("/api/svc/{namespace}/{service}", c.Svc,
+ loginObserver,
productanalytics.RouteObserverWithQualification("/api/svc/{namespace}/{service}", c.Analytics, c.AuthCfg.SPAClientID, svcQualifier)))
r.Handle("/api/svc/{namespace}/{service}/{path...}",
withAuthenticatedMiddlewares("/api/svc/{namespace}/{service}/{path...}", c.Svc,
+ loginObserver,
productanalytics.RouteObserverWithQualification("/api/svc/{namespace}/{service}/{path...}", c.Analytics, c.AuthCfg.SPAClientID, svcQualifier)))
r.Handle("POST /api/signed-service-urls/{namespace}",
@@ -252,6 +255,7 @@ func setupRouter(c handlers.Handlers) http.Handler {
// K8s API access replaces the unauthenticated /k8s-api nginx location.
r.Handle("/api/k8s/{path...}",
withAuthenticatedMiddlewares("/api/k8s/{path...}", c.K8s,
+ loginObserver,
productanalytics.RouteObserver("/api/k8s/{path...}", c.Analytics, c.AuthCfg.SPAClientID)))
// Wrap the entire mux in the metrics middleware so every request
diff --git a/libs/fleet/backend/main_test.go b/libs/fleet/backend/main_test.go
index d640624665..f0d40ebc53 100644
--- a/libs/fleet/backend/main_test.go
+++ b/libs/fleet/backend/main_test.go
@@ -355,6 +355,53 @@ func requestWithAZP(t *testing.T, method, path string, body io.Reader, azp strin
return req
}
+type routerAnalyticsCapture struct {
+ mu sync.Mutex
+ events []productanalytics.Event
+}
+
+func (capture *routerAnalyticsCapture) Capture(event productanalytics.Event) {
+ capture.mu.Lock()
+ defer capture.mu.Unlock()
+ capture.events = append(capture.events, event)
+}
+
+func (capture *routerAnalyticsCapture) eventsNamed(name string) []productanalytics.Event {
+ capture.mu.Lock()
+ defer capture.mu.Unlock()
+ events := make([]productanalytics.Event, 0)
+ for _, event := range capture.events {
+ if event.Name == name {
+ events = append(events, event)
+ }
+ }
+ return events
+}
+
+func TestRouterEmitsOneCLILoginAcrossFleetRoutes(t *testing.T) {
+ capture := &routerAnalyticsCapture{}
+ router := setupRouter(handlers.Handlers{
+ Analytics: capture,
+ AuthCfg: config.AuthConfiguration{SPAClientID: "cyclops-cs-spa"},
+ })
+
+ for _, path := range []string{
+ "/api/k8s/api/v1/nodes",
+ "/api/svc/Not_A_Label/svc-a",
+ } {
+ response := httptest.NewRecorder()
+ router.ServeHTTP(response, requestWithAZP(t, http.MethodGet, path, nil, "cua-cli"))
+ }
+
+ logins := capture.eventsNamed(productanalytics.EventLoginSucceeded)
+ if len(logins) != 1 {
+ t.Fatalf("login events = %#v", logins)
+ }
+ if logins[0].Properties["source"] != productanalytics.SourceCLI || logins[0].Properties["identity_class"] != productanalytics.IdentityExternal {
+ t.Fatalf("login properties = %#v", logins[0].Properties)
+ }
+}
+
func bigEndianBytes(v int) []byte {
if v == 0 {
return []byte{0}
diff --git a/libs/fleet/backend/productanalytics/client.go b/libs/fleet/backend/productanalytics/client.go
index ef543e0b44..45f42d1bf5 100644
--- a/libs/fleet/backend/productanalytics/client.go
+++ b/libs/fleet/backend/productanalytics/client.go
@@ -92,13 +92,17 @@ func (client *Client) Capture(event Event) {
if event.Name == EventAttributionBound {
event.InsertID = "fleet-attribution:" + pseudonym
}
+ capturedAt := time.Now().UTC()
+ if event.Timestamp.IsZero() {
+ event.Timestamp = capturedAt
+ }
copied := cloneEvent(event)
copied.Properties["environment"] = client.config.Environment
copied.Properties["instrumentation_version"] = Version
if copied.SetOnce == nil {
copied.SetOnce = map[string]any{}
}
- copied.SetOnce[firstSeenProperty] = time.Now().UTC().Format(time.RFC3339)
+ copied.SetOnce[firstSeenProperty] = capturedAt.Format(time.RFC3339)
select {
case client.queue <- copied:
metrics.SetProductAnalyticsQueueDepth(len(client.queue))
@@ -164,7 +168,10 @@ func (client *Client) deliver(events []Event) {
if len(event.SetOnce) > 0 {
properties["$set_once"] = cloneMap(event.SetOnce)
}
- items = append(items, map[string]any{"event": event.Name, "distinct_id": event.DistinctID, "properties": properties})
+ items = append(items, map[string]any{
+ "event": event.Name, "distinct_id": event.DistinctID,
+ "timestamp": event.Timestamp.Format(time.RFC3339Nano), "properties": properties,
+ })
}
body, err := json.Marshal(map[string]any{"api_key": client.config.ProjectToken, "batch": items})
if err != nil {
diff --git a/libs/fleet/backend/productanalytics/client_test.go b/libs/fleet/backend/productanalytics/client_test.go
index 74d4d1dc89..f4b5bb5da9 100644
--- a/libs/fleet/backend/productanalytics/client_test.go
+++ b/libs/fleet/backend/productanalytics/client_test.go
@@ -46,6 +46,9 @@ func TestClientDeliversAllowlistedEvent(t *testing.T) {
if item["event"] != EventPoolCreate || item["distinct_id"] != PseudonymForUserID("subject-1", "identity-test-key") {
t.Fatalf("event payload = %#v", item)
}
+ if _, err := time.Parse(time.RFC3339Nano, item["timestamp"].(string)); err != nil {
+ t.Fatalf("timestamp = %#v: %v", item["timestamp"], err)
+ }
properties := item["properties"].(map[string]any)
if properties["environment"] != "production" || properties["instrumentation_version"] != Version || properties["$insert_id"] != "trace-1" {
t.Fatalf("properties = %#v", properties)
@@ -89,6 +92,47 @@ func TestClientSuppressesExcludedSubject(t *testing.T) {
_ = client.Shutdown(ctx)
}
+func TestClientDoesNotLeakRawLoginIdentity(t *testing.T) {
+ requests := make(chan map[string]any, 1)
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ defer r.Body.Close()
+ var payload map[string]any
+ if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
+ t.Fatal(err)
+ }
+ requests <- payload
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+ client := New(Config{
+ Enabled: true, Host: server.URL, ProjectToken: "phc_test", IdentityKey: "identity-test-key", Environment: "production",
+ QueueSize: 2, BatchSize: 1, FlushInterval: time.Hour, RequestTimeout: time.Second,
+ })
+ client.Capture(Event{
+ Name: EventLoginSucceeded, DistinctID: "subject-1",
+ Properties: map[string]any{"outcome": OutcomeSuccess, "source": SourceCLI, "principal_type": "user", "identity_class": IdentityExternal},
+ })
+ select {
+ case payload := <-requests:
+ encoded, _ := json.Marshal(payload)
+ if bytes.Contains(encoded, []byte("subject-1")) {
+ t.Fatalf("payload contains raw identity: %s", encoded)
+ }
+ item := payload["batch"].([]any)[0].(map[string]any)
+ properties := item["properties"].(map[string]any)
+ if _, exists := properties["$insert_id"]; exists {
+ t.Fatalf("login event unexpectedly contains $insert_id: %#v", properties)
+ }
+ case <-time.After(2 * time.Second):
+ t.Fatal("timed out waiting for login capture")
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ defer cancel()
+ if err := client.Shutdown(ctx); err != nil {
+ t.Fatal(err)
+ }
+}
+
func TestClientPseudonymizesAttributionIdentityAndStableInsertID(t *testing.T) {
requests := make(chan map[string]any, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/libs/fleet/backend/productanalytics/events.go b/libs/fleet/backend/productanalytics/events.go
index 375dc6e065..83c0d40c8f 100644
--- a/libs/fleet/backend/productanalytics/events.go
+++ b/libs/fleet/backend/productanalytics/events.go
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"strings"
+ "time"
"cyclops-cs-backend/auth"
)
@@ -38,6 +39,26 @@ func PseudonymForUserID(userID, key string) string {
return "u_" + hex.EncodeToString(mac.Sum(nil))
}
+// loginSessionKey returns an internal-only hash for suppressing repeated
+// observations from one authenticated CLI session.
+func loginSessionKey(user *auth.User) string {
+ if user == nil || user.ID == "" {
+ return ""
+ }
+ sessionID := ""
+ if user.Claims != nil {
+ sessionID = strings.TrimSpace(user.Claims["sid"])
+ if sessionID == "" {
+ sessionID = strings.TrimSpace(user.Claims["session_state"])
+ }
+ }
+ if sessionID == "" {
+ sessionID = user.ID
+ }
+ digest := sha256.Sum256([]byte(user.ID + "\x00" + sessionID))
+ return hex.EncodeToString(digest[:])
+}
+
const (
EventLoginSucceeded = "fleet_login_succeeded"
EventPaymentMethodSetup = "fleet_payment_method_setup"
@@ -59,6 +80,7 @@ const (
OutcomeSuccess = "success"
OutcomeFailure = "failure"
SourceSPA = "spa"
+ SourceCLI = "cli"
SourceUserKey = "user_key"
Version = "1"
)
@@ -99,6 +121,7 @@ type Event struct {
Name string
DistinctID string
InsertID string
+ Timestamp time.Time
Properties map[string]any
SetOnce map[string]any
}
@@ -120,6 +143,9 @@ func SourceForUser(user *auth.User, spaClientID string) (string, bool) {
if user.PrincipalType == auth.PrincipalTypeUserKey || strings.HasPrefix(user.AZP, "ukey-") {
return SourceUserKey, true
}
+ if user.AZP == "cua-cli" && user.PrincipalType == auth.PrincipalTypeUser {
+ return SourceCLI, true
+ }
if user.AZP == spaClientID || user.AZP == "oauth2-proxy" {
return SourceSPA, true
}
diff --git a/libs/fleet/backend/productanalytics/events_test.go b/libs/fleet/backend/productanalytics/events_test.go
index 41ecc13553..84bbccf654 100644
--- a/libs/fleet/backend/productanalytics/events_test.go
+++ b/libs/fleet/backend/productanalytics/events_test.go
@@ -1,6 +1,7 @@
package productanalytics
import (
+ "strings"
"testing"
"cyclops-cs-backend/auth"
@@ -14,6 +15,8 @@ func TestSourceForUser(t *testing.T) {
ok bool
}{
{name: "spa", user: &auth.User{ID: "user-1", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: SourceSPA, ok: true},
+ {name: "cli", user: &auth.User{ID: "user-1", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeUser}, want: SourceCLI, ok: true},
+ {name: "non-user cua-cli principal", user: &auth.User{ID: "user-1", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeGitHubOIDC}},
{name: "oauth proxy", user: &auth.User{ID: "user-1", AZP: "oauth2-proxy"}, want: SourceSPA, ok: true},
{name: "user key", user: &auth.User{ID: "user-1", AZP: "ukey-demo", PrincipalType: auth.PrincipalTypeUserKey}, want: SourceUserKey, ok: true},
{name: "github", user: &auth.User{ID: "user-1", AZP: "github-oidc", PrincipalType: auth.PrincipalTypeGitHubOIDC}},
@@ -64,6 +67,23 @@ func TestPseudonymForUserIDIsDeterministicAndKeyed(t *testing.T) {
}
}
+func TestLoginSessionKeyUsesTrustedSessionClaims(t *testing.T) {
+ user := &auth.User{ID: "user-1", Claims: map[string]string{"sid": "session-1", "session_state": "legacy-session"}}
+ first := loginSessionKey(user)
+ if first == "" || first != loginSessionKey(user) {
+ t.Fatalf("session key is not stable: %q", first)
+ }
+ if strings.Contains(first, "user-1") || strings.Contains(first, "session-1") {
+ t.Fatalf("session key contains raw identity material: %q", first)
+ }
+ if first == loginSessionKey(&auth.User{ID: "user-1", Claims: map[string]string{"sid": "session-2"}}) {
+ t.Fatalf("different sessions share key: %q", first)
+ }
+ if got := loginSessionKey(&auth.User{ID: "user-1"}); got == "" {
+ t.Fatal("missing-session fallback is empty")
+ }
+}
+
func TestValidateEventRejectsUnsafeProperties(t *testing.T) {
valid := Event{
Name: EventPoolCreate,
diff --git a/libs/fleet/backend/productanalytics/middleware.go b/libs/fleet/backend/productanalytics/middleware.go
index 48a5cc398c..fe04df8305 100644
--- a/libs/fleet/backend/productanalytics/middleware.go
+++ b/libs/fleet/backend/productanalytics/middleware.go
@@ -8,6 +8,7 @@ import (
"net"
"net/http"
"strings"
+ "sync"
"time"
"cyclops-cs-backend/auth"
@@ -22,6 +23,90 @@ type SvcQualificationResult struct {
}
type SvcQualification func(context.Context, *http.Request, int) SvcQualificationResult
+const (
+ loginSessionCacheCapacity = 4096
+ loginSessionCacheTTL = 12 * time.Hour
+)
+
+type loginSessionGate struct {
+ mu sync.Mutex
+ expires map[string]time.Time
+ capacity int
+ ttl time.Duration
+}
+
+func newLoginSessionGate(capacity int, ttl time.Duration) *loginSessionGate {
+ return &loginSessionGate{expires: make(map[string]time.Time), capacity: capacity, ttl: ttl}
+}
+
+func (gate *loginSessionGate) first(key string, now time.Time) bool {
+ if key == "" {
+ return false
+ }
+ gate.mu.Lock()
+ defer gate.mu.Unlock()
+ if expiry, exists := gate.expires[key]; exists && now.Before(expiry) {
+ return false
+ }
+ if len(gate.expires) >= gate.capacity {
+ for cachedKey, expiry := range gate.expires {
+ if !now.Before(expiry) {
+ delete(gate.expires, cachedKey)
+ }
+ }
+ }
+ if len(gate.expires) >= gate.capacity {
+ var oldestKey string
+ var oldestExpiry time.Time
+ for cachedKey, expiry := range gate.expires {
+ if oldestKey == "" || expiry.Before(oldestExpiry) {
+ oldestKey, oldestExpiry = cachedKey, expiry
+ }
+ }
+ delete(gate.expires, oldestKey)
+ }
+ gate.expires[key] = now.Add(gate.ttl)
+ return true
+}
+
+// LoginObserver records a successful authentication made with the public CLI
+// client. The CLI has no browser session to call the SPA-only analytics
+// endpoint, but a validated cua-cli token reaching a supported Fleet
+// control/data-plane route is sufficient proof of Fleet entry. The observer
+// runs after authentication and captures regardless of downstream
+// authorization or service status: those outcomes describe the request, not
+// whether the login succeeded.
+func LoginObserver(capturer Capturer, spaClientID string) auth.Middleware {
+ if capturer == nil {
+ capturer = Nop()
+ }
+ gate := newLoginSessionGate(loginSessionCacheCapacity, loginSessionCacheTTL)
+ return func(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ user := auth.GetUser(r.Context())
+ source, ok := SourceForUser(user, spaClientID)
+ if !ok || source != SourceCLI || !gate.first(loginSessionKey(user), time.Now()) {
+ next.ServeHTTP(w, r)
+ return
+ }
+ principalType := user.PrincipalType
+ if principalType == "" {
+ principalType = auth.PrincipalTypeUser
+ }
+ capturer.Capture(Event{
+ Name: EventLoginSucceeded, DistinctID: user.ID,
+ Properties: map[string]any{
+ "outcome": OutcomeSuccess,
+ "source": source,
+ "principal_type": principalType,
+ "identity_class": ClassifyIdentity(user),
+ },
+ })
+ next.ServeHTTP(w, r)
+ })
+ }
+}
+
func RouteObserver(route string, capturer Capturer, spaClientID string, qualifiers ...SvcQualifier) auth.Middleware {
var qualifier SvcQualification
if len(qualifiers) > 0 && qualifiers[0] != nil {
diff --git a/libs/fleet/backend/productanalytics/middleware_test.go b/libs/fleet/backend/productanalytics/middleware_test.go
index a377b85b7c..927007d7bb 100644
--- a/libs/fleet/backend/productanalytics/middleware_test.go
+++ b/libs/fleet/backend/productanalytics/middleware_test.go
@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"net/http/httptest"
+ "strings"
"testing"
"time"
@@ -18,6 +19,10 @@ type captureSink struct{ events []Event }
func (sink *captureSink) Capture(event Event) { sink.events = append(sink.events, event) }
+type captureFunc func(Event)
+
+func (capture captureFunc) Capture(event Event) { capture(event) }
+
type eventChannel chan Event
func (sink eventChannel) Capture(event Event) { sink <- event }
@@ -32,6 +37,89 @@ func observedRequest(method, route, path string, user *auth.User) *http.Request
return request.WithContext(ctx)
}
+func TestLoginObserverCapturesCLIAuthenticationOncePerSession(t *testing.T) {
+ sink := &captureSink{}
+ observer := LoginObserver(sink, "cyclops-cs-spa")
+ handler := observer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusForbidden)
+ }))
+ user := &auth.User{ID: "external-1", Email: "[email protected]", EmailVerified: true, AZP: "cua-cli", PrincipalType: auth.PrincipalTypeUser, Claims: map[string]string{"sid": "session-1"}}
+ handler.ServeHTTP(httptest.NewRecorder(), observedRequest(http.MethodPost, "/api/k8s/{path...}", "apis/cua.ai/v1/namespaces/ns-a/osgymworkspacepools", user))
+ observer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ })).ServeHTTP(httptest.NewRecorder(), observedRequest(http.MethodGet, "/api/svc/{namespace}/{service}", "", user))
+
+ if len(sink.events) != 1 {
+ t.Fatalf("events = %#v", sink.events)
+ }
+ event := sink.events[0]
+ if event.Name != EventLoginSucceeded || event.DistinctID != user.ID || event.InsertID != "" {
+ t.Fatalf("event = %#v", event)
+ }
+ if event.Properties["outcome"] != OutcomeSuccess || event.Properties["source"] != SourceCLI || event.Properties["identity_class"] != IdentityExternal {
+ t.Fatalf("properties = %#v", event.Properties)
+ }
+}
+
+func TestLoginObserverCapturesDifferentCLISessions(t *testing.T) {
+ sink := &captureSink{}
+ handler := LoginObserver(sink, "cyclops-cs-spa")(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ for _, sessionID := range []string{"session-1", "session-2"} {
+ user := &auth.User{ID: "external-1", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeUser, Claims: map[string]string{"sid": sessionID}}
+ handler.ServeHTTP(httptest.NewRecorder(), observedRequest(http.MethodGet, "/api/k8s/{path...}", "version", user))
+ }
+ if len(sink.events) != 2 {
+ t.Fatalf("events = %#v", sink.events)
+ }
+}
+
+func TestLoginSessionGateIsBoundedAndExpires(t *testing.T) {
+ gate := newLoginSessionGate(1, time.Hour)
+ now := time.Date(2026, time.September, 2, 0, 0, 0, 0, time.UTC)
+ if !gate.first("session-1", now) || gate.first("session-1", now) {
+ t.Fatal("same live session was not suppressed")
+ }
+ if !gate.first("session-2", now) || !gate.first("session-1", now) {
+ t.Fatal("capacity eviction did not admit the oldest session key")
+ }
+ if !gate.first("session-1", now.Add(2*time.Hour)) {
+ t.Fatal("expired session key remained suppressed")
+ }
+}
+
+func TestLoginObserverCapturesBeforeTheFleetRequest(t *testing.T) {
+ order := []string{}
+ sink := captureFunc(func(Event) { order = append(order, "login") })
+ handler := LoginObserver(sink, "cyclops-cs-spa")(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ order = append(order, "request")
+ w.WriteHeader(http.StatusOK)
+ }))
+ handler.ServeHTTP(httptest.NewRecorder(), observedRequest(http.MethodGet, "/api/k8s/{path...}", "version", &auth.User{ID: "cli-1", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeUser}))
+ if got := strings.Join(order, ","); got != "login,request" {
+ t.Fatalf("order = %q", got)
+ }
+}
+
+func TestLoginObserverIgnoresBrowserAndNonInteractivePrincipals(t *testing.T) {
+ for _, user := range []*auth.User{
+ {ID: "spa-1", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser},
+ {ID: "key-1", AZP: "ukey-demo", PrincipalType: auth.PrincipalTypeUserKey},
+ {ID: "github-1", AZP: "github-oidc", PrincipalType: auth.PrincipalTypeGitHubOIDC},
+ {ID: "github-2", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeGitHubOIDC},
+ } {
+ sink := &captureSink{}
+ handler := LoginObserver(sink, "cyclops-cs-spa")(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ handler.ServeHTTP(httptest.NewRecorder(), observedRequest(http.MethodGet, "/api/k8s/{path...}", "apis/cua.ai/v1/namespaces/ns-a/osgymworkspacepools", user))
+ if len(sink.events) != 0 {
+ t.Fatalf("user %#v captured %#v", user, sink.events)
+ }
+ }
+}
+
func TestRouteObserverEmitsActivationForAuthenticatedNonInternalIdentity(t *testing.T) {
users := []struct {
name string
diff --git a/libs/fleet/e2e/detail-shell.spec.ts b/libs/fleet/e2e/detail-shell.spec.ts
index 1bec7f948b..dadc6fb4b2 100644
--- a/libs/fleet/e2e/detail-shell.spec.ts
+++ b/libs/fleet/e2e/detail-shell.spec.ts
@@ -227,7 +227,7 @@ test("claim detail hides signed URL controls when creation is unavailable", asyn
await mockFleet(page, [], { unavailable: { create: true } })
await page.goto("/pools/demo-pool/demo-pool/claims/claim-abc123")
- await page.getByRole("button", { name: "Create signed URL" }).click()
+ await page.getByLabel("Signed URLs", { exact: true }).getByRole("button", { name: "Create signed URL" }).click()
await page.getByRole("button", { name: "Choose a service" }).click()
await page.getByRole("option", { name: "mcp" }).click()
await page.getByRole("button", { name: "Create signed URL" }).first().click()
diff --git a/libs/fleet/tests/design-package-boundary.test.mjs b/libs/fleet/tests/design-package-boundary.test.mjs
index 3f51a9a1c1..3c4f3566fe 100644
--- a/libs/fleet/tests/design-package-boundary.test.mjs
+++ b/libs/fleet/tests/design-package-boundary.test.mjs
@@ -71,12 +71,14 @@ test("frontend image builds from the repository root", async () => {
})
test("dashboard activates the shared theme through supported boundaries", async () => {
- const [entrypoint, shell, shellStyles, visualPreview] = await Promise.all([
- readFile(path.join(cyclopsRoot, "src/main.tsx"), "utf8"),
- readFile(path.join(cyclopsRoot, "src/App.tsx"), "utf8"),
- readFile(path.join(cyclopsRoot, "src/shell.css"), "utf8"),
- readFile(path.join(cyclopsRoot, "src/local-visual-preview.ts"), "utf8"),
- ])
+ const [entrypoint, shell, shellStyles, visualPreview, previewEnvironment] =
+ await Promise.all([
+ readFile(path.join(cyclopsRoot, "src/main.tsx"), "utf8"),
+ readFile(path.join(cyclopsRoot, "src/App.tsx"), "utf8"),
+ readFile(path.join(cyclopsRoot, "src/shell.css"), "utf8"),
+ readFile(path.join(cyclopsRoot, "src/local-visual-preview.ts"), "utf8"),
+ readFile(path.join(cyclopsRoot, "src/preview-environment.ts"), "utf8"),
+ ])
const allStyles = (await readCssTree(path.join(cyclopsRoot, "src"))).join(
"\n",
)
@@ -109,11 +111,11 @@ test("dashboard activates the shared theme through supported boundaries", async
assert.match(visualPreview, /import\.meta\.env\.DEV/)
assert.match(visualPreview, /VITE_CUA_LOCAL_VISUAL_PREVIEW === "true"/)
assert.match(
- visualPreview,
+ previewEnvironment,
/VITE_CUA_REVIEW_VISUAL_PREVIEW === "true"/,
)
assert.match(
- visualPreview,
+ previewEnvironment,
/\^cyclops-cs-pr-\\d\+\\\.tail204509\\\.ts\\\.net\$/,
)
})