test: add regression tests for Jira credential encryption at rest (#1797)#1838
test: add regression tests for Jira credential encryption at rest (#1797)#1838Ridanshi wants to merge 1 commit into
Conversation
…iyanshu-byte-coder#1797) Issue investigation ------------------- The Jira credential lifecycle was traced end-to-end: POST /api/integrations/jira/credentials → validates domain, email, token → testJiraConnection() (Jira /myself endpoint) → encryptToken(apiToken) -- AES-256-GCM via crypto.ts → supabase.upsert({ api_token: encrypted, token_iv: iv }) GET /api/integrations/jira/credentials → SELECT "id, jira_domain, email, project_key, is_active, created_at" → never selects api_token or token_iv GET /api/integrations/jira (Jira data) → SELECT * from jira_credentials → decryptToken(cred.api_token, cred.token_iv) → use decrypted token for Jira API call only The encryption-at-rest fix is already applied in the codebase. The api_token column stores the AES-256-GCM ciphertext and token_iv stores the random IV. The plaintext token is never persisted and never returned to clients. What was missing: zero regression tests existed for this behaviour. A future refactor could inadvertently introduce plaintext storage without any tests to catch it. test/jira-credentials.test.ts — 15 new tests: POST /credentials — encryption at rest * stores encrypted token, never the plaintext (regression for Priyanshu-byte-coder#1797) * response body never contains the token in any form * validates Jira connection before storing; if validation fails, encryptToken is never called * returns 401 for unauthenticated requests * returns 400 for invalid domain format * returns 400 for missing required fields GET /credentials — token never exposed * uses a column-restricted SELECT that excludes api_token and token_iv * response serialisation contains no token data (encrypted or plain) * returns empty array when no credentials exist DELETE /credentials * deletes a specific credential by ID * deletes all credentials when no ID is provided GET /jira — decryption and Jira API usage * decryptToken is called with the encrypted values from the DB; the outbound Jira API call uses the decrypted token * returns 500 when decryption fails; Jira API is never called * returns 404 when no active credentials exist * Jira metrics response never exposes any credential data Closes Priyanshu-byte-coder#1797
|
@Ridanshi is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| - | - | Generic High Entropy Secret | 12f2ecc | test/jira-credentials.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Closes #1797
Investigation result
Issue confirmed — and the encryption fix is already applied. The full Jira credential lifecycle was traced:
Storage path (
POST /api/integrations/jira/credentials)Read path (
GET /api/integrations/jira/credentials)Jira API usage (
GET /api/integrations/jira)The encryption uses AES-256-GCM (authenticated encryption) via the project's existing
encryptToken/decryptTokenhelpers insrc/lib/crypto.ts, keyed fromENCRYPTION_KEYin the environment. This matches the pattern already in use for WakaTime keys and GitHub OAuth tokens.What was missing
Zero regression tests existed for the credential lifecycle. A future refactor could reintroduce plaintext storage with nothing to catch it.
What this PR adds —
test/jira-credentials.test.ts(15 new tests)encryptTokennot called when Jira connectivity check fails; 401 for unauthenticated; 400 for invalid domain; 400 for missing fieldsapi_tokenandtoken_iv; serialised response contains no token data; empty array when no credentials existdecryptTokencalled with DB values; Jira API receives decrypted token; 500 when decryption fails (Jira API not called); 404 for missing credentials; metrics response exposes no credential dataAll 15 pass. The 10 pre-existing upstream failures (unrelated to this change) remain unchanged.