Skip to content

Commit 5c885e4

Browse files
committed
test: restore audit-failure log coverage, prune stale /metrics asserts
1 parent 1578f8c commit 5c885e4

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

internal/handler/audit_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package handler
33
import (
44
"context"
55
"errors"
6+
"log/slog"
67
"testing"
78

89
"github.com/freeCodeCamp/artemis/internal/pg"
@@ -36,10 +37,13 @@ func TestAudit_RecordsEvent(t *testing.T) {
3637
}
3738

3839
func TestAudit_FireAndLogOnFailure(t *testing.T) {
40+
logs := captureAccessLog(t)
3941
h := &Handlers{Audit: &fakeAudit{err: errors.New("db down")}}
4042
require.NotPanics(t, func() {
4143
h.audit(context.Background(), pg.AuditEvent{Action: "site.delete", Actor: "alice", Outcome: "success"})
4244
})
45+
assert.Equal(t, slog.LevelError, logs.levelOf(t, "audit.write.failed"),
46+
"a failed audit write must surface as an error log (never fails the response)")
4347
}
4448

4549
func TestAudit_DetachedFromRequestCancellation(t *testing.T) {

internal/handler/middleware.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ func Recoverer(next http.Handler) http.Handler {
199199
})
200200
}
201201

202-
// accessLogSkipPaths are request URIs that bypass AccessLog. Health
203-
// + readiness + metrics probes from k8s arrive every few seconds
204-
// and flood the log without operator value; status codes feed the
205-
// regular probe-result counters instead.
206202
var accessLogSkipPaths = map[string]struct{}{
207203
"/healthz": {},
208204
"/readyz": {},

internal/integration/public_block_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ import (
99
"time"
1010
)
1111

12-
// TestPublicRouteBlock asserts that the public Gateway HTTPRoute
13-
// rewrites /metrics + /readyz to /_artemis_blocked_path so external
14-
// callers see chi's catch-all 404 instead of operator-only payloads.
15-
// /healthz stays public for external liveness checks.
16-
//
1712
// The Gateway URLRewrite is configured in
1813
// k3s/gxy-management/apps/artemis/charts/artemis/templates/httproute.yaml.
1914
func TestPublicRouteBlock(t *testing.T) {
@@ -28,13 +23,6 @@ func TestPublicRouteBlock(t *testing.T) {
2823
}
2924
})
3025

31-
t.Run("metrics_returns_404", func(t *testing.T) {
32-
status, body := c.statusOnly(ctx, http.MethodGet, "/metrics", "", nil)
33-
if status != 404 {
34-
t.Fatalf("public /metrics: status=%d body=%s — want 404 (Gateway URLRewrite to /_artemis_blocked_path)", status, truncate(body, 200))
35-
}
36-
})
37-
3826
t.Run("healthz_stays_public_200", func(t *testing.T) {
3927
status, body := c.statusOnly(ctx, http.MethodGet, "/healthz", "", nil)
4028
if status != 200 {

0 commit comments

Comments
 (0)