Skip to content

No Test for the Idempotency-Key UUID Validation Rejection #244

Description

@therealjhay

Category: Testing & Quality
Difficulty: High

Description:
The CreatePaymentBody Zod schema validates idempotencyKey as IdempotencyKeySchema = z.string().uuid(). If a non-UUID value is passed (e.g., "not-a-uuid"), the handler at line 618 calls CreatePaymentBody.parse(request.body) which will throw a ZodError caught by the global error handler, returning a 400 VALIDATION_ERROR. However, there is no test that verifies:

  • A non-UUID idempotency key returns 400 with VALIDATION_ERROR code
  • A UUID idempotency key longer than 255 characters is rejected (line 623–625)
  • A valid UUID key passes through to the idempotency check
  • A key that is exactly null or an empty string is treated as "no key provided"

The payment-idempotency.test.ts file rebuilds its own idempotency logic and does not test the Zod validation.

Location:
services/api-gateway/src/index.ts:617–625, shared/validation/schemas.ts:258–259

Acceptance Criteria:

  • Write integration tests for all idempotency key validation scenarios using the real gateway handlers
  • Test UUID validation: pass idempotencyKey: "not-a-uuid", expect 400
  • Test length validation: pass a UUID that is 256+ chars, expect 400
  • Test missing key: omit idempotencyKey, confirm payment is created without idempotency
  • Test max length constant: verify IDEMPOTENCY_KEY_MAX_LEN (255) matches the Prisma schema's implicit String? limit

Technical Notes:

  • Generate a 256-char string: 'a'.repeat(256).
  • An empty string key should be treated the same as missing key (the trim() check at line 129).

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions