Skip to content

Conversation

@kdaviduik
Copy link
Contributor

@kdaviduik kdaviduik commented Jan 26, 2026

WHY are these changes introduced?

E2E tests need access to real gift card codes, but hardcoding them in test files is a security risk. This PR adds infrastructure to load test secrets from the encrypted secrets.ejson file at runtime.

WHAT is this pull request doing?

Adds a test-secrets.ts module that decrypts and loads secrets from the e2e-testing section of secrets.ejson. Uses a single code path for both local development and CI:

  • Local: Uses ejson keydir at /opt/ejson/keys (standard convention)
  • CI: Uses EJSON_PRIVATE_KEY env var passed via --key-from-stdin

Example usage in E2E tests:

import {getRequiredSecret} from '../../fixtures/test-secrets';

const GIFT_CARD_CODE_1 = getRequiredSecret('gift_card_code_1');
const GIFT_CARD_CODE_2 = getRequiredSecret('gift_card_code_2');

Security considerations:

  • Uses execFileSync (not execSync) to prevent shell injection
  • Private key passed via stdin, never on command line or disk
  • Secrets decrypted in-memory only, never written to files

HOW to test your changes?

  1. Ensure ejson is configured locally (/opt/ejson/keys/{public_key} contains private key)
  2. Import and call getRequiredSecret('gift_card_code_1') from a test file
  3. Verify the decrypted value is returned

Post-merge steps

  • Add EJSON_PRIVATE_KEY to GitHub repository secrets (Settings → Secrets → Actions)

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor Author

kdaviduik commented Jan 26, 2026

@kdaviduik kdaviduik marked this pull request as ready for review January 26, 2026 19:42
@kdaviduik kdaviduik requested a review from a team as a code owner January 26, 2026 19:42
@shopify
Copy link
Contributor

shopify bot commented Jan 26, 2026

Oxygen deployed a preview of your kd-set-up-secrets-for-e2e branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment January 30, 2026 3:50 AM

Learn more about Hydrogen's GitHub integration.

@kdaviduik kdaviduik force-pushed the kd-set-up-secrets-for-e2e branch from b865765 to 4e260be Compare January 27, 2026 02:13
@kdaviduik kdaviduik force-pushed the 2025-10-sfapi-caapi-update branch from 04f9469 to bce6ffc Compare January 27, 2026 02:28
@kdaviduik kdaviduik force-pushed the kd-set-up-secrets-for-e2e branch from 4e260be to d6bf802 Compare January 27, 2026 02:28
@fredericoo fredericoo changed the base branch from 2025-10-sfapi-caapi-update to graphite-base/3414 January 27, 2026 11:10
@kdaviduik kdaviduik force-pushed the kd-set-up-secrets-for-e2e branch from d6bf802 to 4f0b3ea Compare January 27, 2026 17:35
Copy link
Contributor

@fredericoo fredericoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@fredericoo fredericoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtb but needs a rebase

Copy link
Contributor

@fredericoo fredericoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good!

@kdaviduik kdaviduik changed the base branch from graphite-base/3414 to main January 30, 2026 03:48
Add infrastructure for securely loading test secrets from secrets.ejson
using EJSON encryption. This enables E2E tests to use real gift card codes
without hardcoding them in test files.

Example usage in an E2E test file:

```typescript
import {getRequiredSecret} from '../../fixtures/test-secrets';

const GIFT_CARD_CODE_1 = getRequiredSecret('gift_card_code_1');
const GIFT_CARD_CODE_2 = getRequiredSecret('gift_card_code_2');
```

How it works:
- Secrets stored encrypted in secrets.ejson under `e2e-testing` section
- Local dev: Uses ejson keydir at /opt/ejson/keys (standard convention)
- CI: Uses EJSON_PRIVATE_KEY env var passed via --key-from-stdin
- Single code path for both environments

Security considerations:
- Uses execFileSync (not execSync) to prevent shell injection
- Private key passed via stdin, never on command line or disk
- Secrets decrypted in-memory, never written to files
@kdaviduik kdaviduik force-pushed the kd-set-up-secrets-for-e2e branch from 4f0b3ea to 8f952fb Compare January 30, 2026 03:48
@kdaviduik kdaviduik merged commit c1703a8 into main Jan 30, 2026
13 of 14 checks passed
@kdaviduik kdaviduik deleted the kd-set-up-secrets-for-e2e branch January 30, 2026 06:11
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.

2 participants