Skip to content

test : added unit tests for lib/github-token-encryption module - #8

Open
tmdeveloper007 wants to merge 2 commits into
mainfrom
#8423
Open

tmdeveloper007 wants to merge 2 commits into
mainfrom
#8423

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Owner

Summary of What Has Been Done

Created lib/github-token-encryption.test.ts with comprehensive unit tests covering:

encryptGitHubToken / decryptGitHubToken:

  • Produces valid GCM-format output (4 dot-separated base64 parts)
  • Round-trips correctly (encrypt then decrypt returns original)
  • Throws on empty string and non-string inputs
  • Throws on unrecognized encrypted token format
  • Tampered ciphertext causes decryption to throw
  • Different encryptions produce different ciphertexts (random IV)

parseAndEncryptTokens:

  • Encrypts multiple comma-separated tokens with sequential rotation indices
  • Throws on empty/whitespace-only string
  • Filters out empty tokens between commas
  • Warns on non-GitHub token prefixes
  • Does not warn for ghp_ and ghu_ prefixes

getNextToken:

  • Returns correct token and cycles through the array
  • Throws when no tokens are provided

isEncryptedToken:

  • Returns true for valid GCM format
  • Returns false for plain text, null, undefined, and empty string
  • Validates base64 validity of each GCM part

redactToken:

  • Shows first 4 + last 4 characters with "..." separator
  • Returns "***" for tokens shorter than 10 characters
  • Handles null and undefined safely

Mocked server-only and set GITHUB_TOKEN_ENCRYPTION_KEY in the test environment.

Changes Made

  • New file: lib/github-token-encryption.test.ts

Impact it Made

Adds direct unit test coverage for the GitHub token encryption module, ensuring security-critical logic is robust against edge cases.

Closes #8423.

Note: please assign this PR to the tmdeveloper007 account.

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