refactor(server): decrypt license with provided aes key (#12570)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added support for a new AES key for license management, improving license encryption and decryption processes.

- **Bug Fixes**
  - Improved error messages and handling when activating expired or invalid licenses.

- **Refactor**
  - Updated license decryption logic to use a fixed AES key instead of deriving one from the workspace ID.
  - Added validation for environment variable values to prevent invalid configurations.

- **Tests**
  - Enhanced license-related tests to cover new key usage and updated error messages.
  - Updated environment variable validation tests with clearer error messages.

- **Chores**
  - Updated environment variable handling for improved consistency.
  - Set production environment variable explicitly in build configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
forehalo
2025-05-27 11:54:28 +00:00
parent 7175019a0a
commit dc7cd0487b
13 changed files with 74 additions and 19 deletions
@@ -15,9 +15,10 @@ import {
const testWorkspaceId = 'd6f52bc7-d62a-4822-804a-335fa7dfe5a6';
const testPublicKey = `-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEkXqe9HR32rSgaNxaePXbwHxoanUq
1DcQTV1twn+G47/HiY+rj7oOw3cLNzOVe7+4Uxn8SMZ/XLImtqFQ6I4WVg==
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqrxlczPknUuj4q4xx1VGr063Cgu7
Hc3w7v4FGmoA5MNzzhrkho1ckDYw2wrX6zBnehFzcivURv80HherE2GQjg==
-----END PUBLIC KEY-----`;
const testTestLicenseAESKey = 'TEST_LICENSE_AES_KEY';
const fixturesDir = join(import.meta.dirname, '__fixtures__');
function getLicense(file: string) {
@@ -39,6 +40,7 @@ let owner: MockedUser;
e2e.before(async () => {
process.env.DEPLOYMENT_TYPE = 'selfhosted';
process.env.AFFiNE_PRO_PUBLIC_KEY = testPublicKey;
process.env.AFFiNE_PRO_LICENSE_AES_KEY = testTestLicenseAESKey;
refreshEnv();
app = await createApp();
@@ -123,7 +125,8 @@ e2e('should not install expired license', async t => {
},
}),
{
message: 'License has expired.',
message:
'Invalid license to activate. License file has expired. Please contact with Affine support to fetch a latest one.',
}
);
});
@@ -29,7 +29,7 @@ test('should read NODE_ENV', t => {
},
{
message:
'Invalid value "unknown" for environment variable NODE_ENV, expected one of ["development","test","production"]',
'Invalid NODE_ENV environment. `unknown` is not a valid NODE_ENV value.',
}
);
});