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

Function TestHandleCreateAPIKey_AcceptsExpiresAt

internal/auth/auth_test.go:213–239  ·  view source on GitHub ↗

TestHandleCreateAPIKey_AcceptsExpiresAt: POST /api/keys with a future RFC 3339 timestamp persists it on the row.

(t *testing.T)

Source from the content-addressed store, hash-verified

211// TestHandleCreateAPIKey_AcceptsExpiresAt: POST /api/keys with a
212// future RFC 3339 timestamp persists it on the row.
213func TestHandleCreateAPIKey_AcceptsExpiresAt(t *testing.T) {
214 ua, store, token := setupUserAuth(t)
215 ctx := context.Background()
216
217 user, _ := store.CreateOrGetUser(ctx, "josh@test.com", "Josh", "google-sub-123")
218
219 expiresAt := time.Now().Add(48 * time.Hour).UTC().Truncate(time.Second)
220 body := `{"name":"ci","expires_at":"` + expiresAt.Format(time.RFC3339) + `"}`
221 req := authedJSON("POST", "/api/keys", token, body)
222 w := httptest.NewRecorder()
223 ua.HandleCreateAPIKey(w, req)
224
225 if w.Code != http.StatusCreated {
226 t.Fatalf("status = %d, want 201; body=%s", w.Code, w.Body.String())
227 }
228 var created identity.APIKey
229 json.NewDecoder(w.Body).Decode(&created)
230 if created.ExpiresAt == nil || !created.ExpiresAt.Equal(expiresAt) {
231 t.Errorf("created.ExpiresAt = %v, want %v", created.ExpiresAt, expiresAt)
232 }
233
234 // Round-trip through the DB to confirm it was actually persisted.
235 keys, _ := store.ListAPIKeys(ctx, user.ID)
236 if len(keys) != 1 || keys[0].ExpiresAt == nil || !keys[0].ExpiresAt.Equal(expiresAt) {
237 t.Errorf("persisted ExpiresAt mismatch: %+v", keys)
238 }
239}
240
241// TestHandleCreateAPIKey_RejectsPastExpiresAt: a past timestamp must
242// be a 400 — silently swallowing it would issue a key that's already

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected