Full rebrand across cosmetic branding, code identifiers, and infrastructure/data-plane naming, using the supplied Cairn OBS logo package. Cosmetic: favicon/logo swap (also closes a stale license-audit finding -- the old favicon was SvelteKit's unreplaced scaffold logo), new centered welcome landing page, larger/legible sidebar logo, page titles, CLAUDE.md/README/docs prose. Code identifiers: Go module path github.com/sentry/sentry -> github.com/cairnobs/cairnobs across all 13 modules and ~91 files (protoc regenerated); Rust crates sentry-agent/sentry-parser/sentry-search -> cairnobs-*; CLI sentryctl -> cairnobsctl; Terraform provider fully renamed (sentry_dashboard etc. -> cairnobs_dashboard, provider type, env vars); every session/auth cookie name; agent config paths and Windows service identity. Deliberately preserved: the gRPC wire protocol's protobuf packages (sentry.logs.v1, sentry.agent.v1) and their Go import directory (proto/sentry/...) -- renaming the wire-level package would break every currently-deployed agent binary (confirmed two real hosts, including mail.inbuxa.com, are actively streaming through this exact contract) until rebuilt and redeployed in lockstep with an ingest cutover. Only the Go module path wrapping the generated code changes. Infrastructure: every docker-compose container name (root and three component-level compose files); the Helm chart (directory, Chart.yaml, named-template helpers, all templates, values.yaml image repos); Kubernetes Operator (CRD group sentry.io -> cairnobs.io, both CRD YAML files, Go identifiers, RBAC markers); the coupled enterprise/tenantcrd package. Caught and fixed real path-coupling bugs along the way: the Helm chart's search/ingest volume mounts and the dev-only-credential detection constant vs. docker-compose.yml's literal values had to move together or a security warning would have silently stopped firing. Data plane: Postgres database sentry_metadata -> cairnobs_metadata and role sentry -> cairnobs; ClickHouse database sentry -> cairnobs; Kafka topic sentry.logs.raw -> cairnobs.logs.raw and its consumer groups. Source-level defaults, docker-compose.yml, and every migrate.sh/ provision script default updated together; already-applied migration files left untouched per this repo's immutable-migration convention. Verified at every layer: all 13 Go modules build/vet/test clean, both Rust workspaces (agent, search) build/clippy/test clean, npm run check/ build clean, docker compose config validates on all four compose files. Live-verified against a real docker stack multiple times through this work, including a final fresh-volume run confirming the actual renamed Postgres database/role, ClickHouse database, and Kafka topic all work end to end with a real login and query, zero console errors.
85 lines
2.4 KiB
Go
85 lines
2.4 KiB
Go
package localauth
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/cairnobs/cairnobs/api/authz"
|
|
)
|
|
|
|
func TestLoginLimiterAllowsUpToMax(t *testing.T) {
|
|
l := newLoginLimiter(3, time.Minute)
|
|
for i := 0; i < 3; i++ {
|
|
if !l.allow("1.2.3.4") {
|
|
t.Fatalf("attempt %d: want allowed", i+1)
|
|
}
|
|
}
|
|
if l.allow("1.2.3.4") {
|
|
t.Fatal("4th attempt within the window: want denied")
|
|
}
|
|
}
|
|
|
|
func TestLoginLimiterIsPerKey(t *testing.T) {
|
|
l := newLoginLimiter(1, time.Minute)
|
|
if !l.allow("1.2.3.4") {
|
|
t.Fatal("first attempt from 1.2.3.4: want allowed")
|
|
}
|
|
if !l.allow("5.6.7.8") {
|
|
t.Fatal("a different IP must have its own budget")
|
|
}
|
|
if l.allow("1.2.3.4") {
|
|
t.Fatal("second attempt from 1.2.3.4: want denied")
|
|
}
|
|
}
|
|
|
|
func TestLoginLimiterResetsAfterWindow(t *testing.T) {
|
|
l := newLoginLimiter(1, 10*time.Millisecond)
|
|
if !l.allow("1.2.3.4") {
|
|
t.Fatal("first attempt: want allowed")
|
|
}
|
|
if l.allow("1.2.3.4") {
|
|
t.Fatal("second attempt within the window: want denied")
|
|
}
|
|
time.Sleep(20 * time.Millisecond)
|
|
if !l.allow("1.2.3.4") {
|
|
t.Fatal("attempt after the window elapsed: want allowed")
|
|
}
|
|
}
|
|
|
|
func TestClientIPPrefersForwardedFor(t *testing.T) {
|
|
r := httptest.NewRequest(http.MethodPost, "/auth/login", nil)
|
|
r.RemoteAddr = "10.0.0.1:5555"
|
|
r.Header.Set("X-Forwarded-For", "203.0.113.9, 10.0.0.1")
|
|
if got := clientIP(r); got != "203.0.113.9" {
|
|
t.Errorf("clientIP() = %q, want %q", got, "203.0.113.9")
|
|
}
|
|
}
|
|
|
|
func TestClientIPFallsBackToRemoteAddr(t *testing.T) {
|
|
r := httptest.NewRequest(http.MethodPost, "/auth/login", nil)
|
|
r.RemoteAddr = "198.51.100.7:5555"
|
|
if got := clientIP(r); got != "198.51.100.7" {
|
|
t.Errorf("clientIP() = %q, want %q", got, "198.51.100.7")
|
|
}
|
|
}
|
|
|
|
// TestHandleLoginRateLimited is the regression test for the
|
|
// security-audit finding that POST /auth/login had no rate limiting at
|
|
// all -- repeated attempts from the same client must eventually get a
|
|
// 429, not another 401.
|
|
func TestHandleLoginRateLimited(t *testing.T) {
|
|
fs := newFakeStore()
|
|
mustCreateUser(t, fs, "alice", "hunter22", authz.RoleEditor)
|
|
_, mux := newTestHandler(t, fs)
|
|
|
|
var last *httptest.ResponseRecorder
|
|
for i := 0; i < loginRateLimitMax+1; i++ {
|
|
last = doRequest(t, mux, http.MethodPost, "/auth/login", `{"username":"alice","password":"wrong-password"}`, nil)
|
|
}
|
|
if last.Code != http.StatusTooManyRequests {
|
|
t.Fatalf("status after exceeding the limit = %d, want 429", last.Code)
|
|
}
|
|
}
|