Skip to content

Added unit test for validateKey util #4800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Maxiweb
Copy link

@Maxiweb Maxiweb commented Jul 6, 2025

This PR adds comprehensive unit tests for the following utility functions in utils/validateKey.ts:

  • validateChatflowAPIKey

  • validateAPIKey

-getAPIKeyWorkspaceID

Key Highlights
Mocks apikeyService and compareKeys to isolate and control test behavior.
Covers edge cases such as:

  • Missing or malformed Authorization headers

  • Missing or incorrect apikeyid

  • Key mismatches and successful matches

  • Absence of stored API keys

  • Introduces a helper function createMockRequest to streamline mock Request creation.

Purpose
Improves confidence in the API key validation logic by ensuring behavior is correctly handled under various request and data conditions. These tests lay the groundwork for better stability and regression prevention in future updates.

@Maxiweb Maxiweb marked this pull request as ready for review July 6, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant