mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
refactor(core): fix tests
This commit is contained in:
parent
7d7f5283ca
commit
7f761203b7
7 changed files with 30 additions and 35 deletions
|
@ -3,7 +3,6 @@ import { merge, Config } from '@silverhand/jest-config';
|
|||
const config: Config.InitialOptions = merge({
|
||||
testPathIgnorePatterns: ['/core/connectors/'],
|
||||
setupFilesAfterEnv: ['jest-matcher-specific-error', './jest.setup.ts'],
|
||||
globalSetup: './jest.global-setup.ts',
|
||||
});
|
||||
|
||||
export default config;
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* Generate private key for tests
|
||||
*/
|
||||
import { generateKeyPairSync } from 'crypto';
|
||||
import { writeFileSync } from 'fs';
|
||||
|
||||
export const privateKeyPath = 'oidc-private-key.test.pem';
|
||||
|
||||
const globalSetup = () => {
|
||||
const { privateKey } = generateKeyPairSync('rsa', {
|
||||
modulusLength: 4096,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem',
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem',
|
||||
},
|
||||
});
|
||||
|
||||
writeFileSync(privateKeyPath, privateKey);
|
||||
};
|
||||
|
||||
export default globalSetup;
|
|
@ -4,14 +4,10 @@
|
|||
|
||||
import envSet from '@/env-set';
|
||||
|
||||
import { privateKeyPath } from './jest.global-setup';
|
||||
jest.mock('@/lib/logto-config');
|
||||
jest.mock('@/env-set/check-alteration-state');
|
||||
|
||||
// eslint-disable-next-line unicorn/prefer-top-level-await
|
||||
(async () => {
|
||||
process.env = {
|
||||
...process.env,
|
||||
OIDC_PRIVATE_KEY_PATHS: privateKeyPath,
|
||||
OIDC_COOKIE_KEYS: '["LOGTOSEKRIT1"]',
|
||||
};
|
||||
await envSet.load();
|
||||
})();
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
export const checkAlterationState = async () => {};
|
21
packages/core/src/lib/__mocks__/logto-config.ts
Normal file
21
packages/core/src/lib/__mocks__/logto-config.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { generateKeyPairSync } from 'crypto';
|
||||
|
||||
import { LogtoOidcConfigKey, LogtoOidcConfigType } from '@logto/schemas';
|
||||
|
||||
const { privateKey } = generateKeyPairSync('rsa', {
|
||||
modulusLength: 4096,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem',
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem',
|
||||
},
|
||||
});
|
||||
|
||||
export const getOidcConfigs = async (): Promise<LogtoOidcConfigType> => ({
|
||||
[LogtoOidcConfigKey.PrivateKeys]: [privateKey],
|
||||
[LogtoOidcConfigKey.CookieKeys]: ['LOGTOSEKRIT1'],
|
||||
[LogtoOidcConfigKey.RefreshTokenReuseInterval]: 3,
|
||||
});
|
|
@ -1,10 +1,12 @@
|
|||
import { getRowsByKeys } from '@logto/cli/lib/queries/logto-config';
|
||||
import { logtoOidcConfigGuard, LogtoOidcConfigKey } from '@logto/schemas';
|
||||
import { logtoOidcConfigGuard, LogtoOidcConfigKey, LogtoOidcConfigType } from '@logto/schemas';
|
||||
import chalk from 'chalk';
|
||||
import { DatabasePool, DatabaseTransactionConnection } from 'slonik';
|
||||
import { z, ZodError } from 'zod';
|
||||
|
||||
export const getOidcConfigs = async (pool: DatabasePool | DatabaseTransactionConnection) => {
|
||||
export const getOidcConfigs = async (
|
||||
pool: DatabasePool | DatabaseTransactionConnection
|
||||
): Promise<LogtoOidcConfigType> => {
|
||||
try {
|
||||
const { rows } = await getRowsByKeys(pool, Object.values(LogtoOidcConfigKey));
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
],
|
||||
"exclude": [
|
||||
"src/**/*.test.ts",
|
||||
"src/__mocks__/",
|
||||
"src/**/__mocks__/",
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue