| 146 | } |
| 147 | |
| 148 | func TestClaim_DifferentUsersIsolated(t *testing.T) { |
| 149 | pool := testutil.TestDB(t) |
| 150 | identStore := identity.NewStore(pool) |
| 151 | idemStore := idempotency.NewStore(pool) |
| 152 | ctx := context.Background() |
| 153 | |
| 154 | uA, _ := identStore.CreateOrGetUser(ctx, "user-a@example.com", "A", "google-a") |
| 155 | uB, _ := identStore.CreateOrGetUser(ctx, "user-b@example.com", "B", "google-b") |
| 156 | |
| 157 | hash := idempotency.HashBody([]byte(`{"x":1}`)) |
| 158 | |
| 159 | a, _ := idemStore.Claim(ctx, uA.ID, "shared", "/api/v1/send", hash) |
| 160 | if a.Outcome != idempotency.OutcomeAcquired { |
| 161 | t.Fatalf("A Outcome = %d", a.Outcome) |
| 162 | } |
| 163 | // Same key, different user — must not collide. |
| 164 | b, _ := idemStore.Claim(ctx, uB.ID, "shared", "/api/v1/send", hash) |
| 165 | if b.Outcome != idempotency.OutcomeAcquired { |
| 166 | t.Errorf("B Outcome = %d, want OutcomeAcquired (different user)", b.Outcome) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | func TestRelease_AllowsFreshClaim(t *testing.T) { |
| 171 | store, userID, _ := newStoreAndUser(t) |