Skip to content

fix: accept production enterprise keys in development environment#18611

Merged
FelixMalfait merged 3 commits intomainfrom
fix/enterprise-key-validation-in-development
Mar 13, 2026
Merged

fix: accept production enterprise keys in development environment#18611
FelixMalfait merged 3 commits intomainfrom
fix/enterprise-key-validation-in-development

Conversation

@FelixMalfait
Copy link
Copy Markdown
Member

Problem

When NODE_ENV is development, the server was only using the dev public key to verify enterprise JWTs. Production keys are signed with the production private key, so they failed verification with the dev public key, resulting in "Invalid enterprise key" errors.

Solution

Try both production and dev public keys when in development, so production keys work when testing locally. In production, only the production key is used (unchanged behavior).

Changes

  • enterprise-plan.service.ts: Replaced getPublicKey() with getPublicKeysToTry() that returns both keys in development; updated verifyJwt() to try each key until one succeeds
  • enterprise-plan.service.spec.ts: Added test for production key acceptance when NODE_ENV is development

Made with Cursor

When NODE_ENV is development, the server was only using the dev public
key to verify enterprise JWTs. Production keys are signed with the
production private key, so they failed verification.

Now try both production and dev public keys when in development, so
production keys work when testing locally.

Made-with: Cursor
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/twenty-server/src/engine/core-modules/enterprise/services/__tests__/enterprise-plan.service.spec.ts">

<violation number="1" location="packages/twenty-server/src/engine/core-modules/enterprise/services/__tests__/enterprise-plan.service.spec.ts:365">
P2: This mock makes the new test pass for any key, so it does not actually verify the development fallback behavior introduced by the PR.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@FelixMalfait
Copy link
Copy Markdown
Member Author

FelixMalfait commented Mar 13, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:45102

This environment will automatically shut down after 5 hours.

…ices/__tests__/enterprise-plan.service.spec.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/twenty-server/src/engine/core-modules/enterprise/services/__tests__/enterprise-plan.service.spec.ts">

<violation number="1" location="packages/twenty-server/src/engine/core-modules/enterprise/services/__tests__/enterprise-plan.service.spec.ts:366">
P2: This test now exercises fallback to the second public key, not acceptance of the production key, so it can miss the regression it is meant to cover.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

return undefined;
});
mockCryptoVerify
.mockReturnValueOnce(false)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

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

P2: This test now exercises fallback to the second public key, not acceptance of the production key, so it can miss the regression it is meant to cover.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-server/src/engine/core-modules/enterprise/services/__tests__/enterprise-plan.service.spec.ts, line 366:

<comment>This test now exercises fallback to the second public key, not acceptance of the production key, so it can miss the regression it is meant to cover.</comment>

<file context>
@@ -362,10 +362,13 @@ describe('EnterprisePlanService', () => {
       });
-      mockCryptoVerify.mockReturnValue(true);
+      mockCryptoVerify
+        .mockReturnValueOnce(false)
+        .mockReturnValueOnce(true);
       const productionKey = createFakeJwt(MOCK_KEY_PAYLOAD);
</file context>
Fix with Cubic

@FelixMalfait
Copy link
Copy Markdown
Member Author

@claude fix lint and push directly to this branch

❌ > nx run twenty-server:lint:ci

npx oxlint --type-aware -c .oxlintrc.json src/ && (prettier src/ --check --cache --cache-location ../../.cache/prettier/packages/twenty-server --cache-strategy metadata || (echo 'ERROR: Prettier formatting check failed! Fix with: npx nx lint twenty-server --configuration=fix' && false))

Checking formatting...
[warn] src/engine/core-modules/enterprise/services/tests/enterprise-plan.service.spec.ts
[warn] Code style issues found in the above file. Run Prettier with --write to fix.
ERROR: Prettier formatting check failed! Fix with: npx nx lint twenty-server --configuration=fix
Warning: command "npx oxlint --type-aware -c .oxlintrc.json src/ && (prettier src/ --check --cache --cache-location ../../.cache/prettier/packages/twenty-server --cache-strategy metadata || (echo 'ERROR: Prettier formatting check failed! Fix with: npx nx lint twenty-server --configuration=fix' && false))" exited with non-zero status code::endgroup::

NX Running targets lint, typecheck for project twenty-server and 4 tasks it depends on failed

Failed tasks:

  • twenty-server:lint:ci

@claude
Copy link
Copy Markdown

claude bot commented Mar 13, 2026

Claude finished @FelixMalfait's task in 1m 51s —— View job


Fixing lint issues

  • Fix Prettier formatting in test file
  • Commit and push

Fixed the Prettier formatting issue — the chained .mockReturnValueOnce(false).mockReturnValueOnce(true) was reformatted to a single line per Prettier's rules. Pushed to the branch in 0e4ef05.
·

Co-authored-by: Félix Malfait <FelixMalfait@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@FelixMalfait
Copy link
Copy Markdown
Member Author

@ijreilly fyi merging since you aren't there today

@FelixMalfait FelixMalfait merged commit 5f558e5 into main Mar 13, 2026
75 checks passed
@FelixMalfait FelixMalfait deleted the fix/enterprise-key-validation-in-development branch March 13, 2026 08:20
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