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

Function TestCreateAPIKey

internal/identity/store_test.go:175–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func TestCreateAPIKey(t *testing.T) {
176 pool := testutil.TestDB(t)
177 store := identity.NewStore(pool)
178 ctx := context.Background()
179
180 user, err := store.CreateOrGetUser(ctx, "apikey-owner@example.com", "Owner", "google-apikey-create")
181 if err != nil {
182 t.Fatalf("CreateOrGetUser: %v", err)
183 }
184
185 key, err := store.CreateAPIKey(ctx, user.ID, "test key", nil)
186 if err != nil {
187 t.Fatalf("CreateAPIKey: %v", err)
188 }
189 if !strings.HasPrefix(key.ID, "apk_") {
190 t.Errorf("ID should start with apk_, got %q", key.ID)
191 }
192 if !strings.HasPrefix(key.PlaintextKey, "e2a_") {
193 t.Errorf("PlaintextKey should start with e2a_, got %q", key.PlaintextKey)
194 }
195 if key.UserID != user.ID {
196 t.Errorf("UserID = %q, want %q", key.UserID, user.ID)
197 }
198 if key.Name != "test key" {
199 t.Errorf("Name = %q, want %q", key.Name, "test key")
200 }
201}
202
203func TestListAPIKeys(t *testing.T) {
204 pool := testutil.TestDB(t)

Callers

nothing calls this directly

Calls 4

CreateOrGetUserMethod · 0.95
CreateAPIKeyMethod · 0.95
TestDBFunction · 0.92
NewStoreFunction · 0.92

Tested by

no test coverage detected