MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestHandleCreateAPIKey_RejectsPastExpiresAt

Function TestHandleCreateAPIKey_RejectsPastExpiresAt

internal/auth/auth_test.go:244–255  ·  view source on GitHub ↗

TestHandleCreateAPIKey_RejectsPastExpiresAt: a past timestamp must be a 400 — silently swallowing it would issue a key that's already expired, which is worse UX than rejecting at create time.

(t *testing.T)

Source from the content-addressed store, hash-verified

242// be a 400 — silently swallowing it would issue a key that's already
243// expired, which is worse UX than rejecting at create time.
244func TestHandleCreateAPIKey_RejectsPastExpiresAt(t *testing.T) {
245 ua, _, token := setupUserAuth(t)
246
247 past := time.Now().Add(-1 * time.Hour).UTC().Format(time.RFC3339)
248 req := authedJSON("POST", "/api/keys", token, `{"name":"backdated","expires_at":"`+past+`"}`)
249 w := httptest.NewRecorder()
250 ua.HandleCreateAPIKey(w, req)
251
252 if w.Code != http.StatusBadRequest {
253 t.Errorf("status = %d, want 400; body=%s", w.Code, w.Body.String())
254 }
255}
256
257// TestHandleCreateAPIKey_RejectsMalformedExpiresAt: not-RFC-3339 →
258// 400, not "silently fall back to NULL." The handler chooses to fail

Callers

nothing calls this directly

Calls 4

setupUserAuthFunction · 0.85
HandleCreateAPIKeyMethod · 0.80
authedJSONFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected