0
Fork 0
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:
Gao Sun 2022-10-09 22:23:50 +08:00
parent 7d7f5283ca
commit 7f761203b7
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
7 changed files with 30 additions and 35 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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();
})();

View file

@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export const checkAlterationState = async () => {};

View 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,
});

View file

@ -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));

View file

@ -5,6 +5,6 @@
],
"exclude": [
"src/**/*.test.ts",
"src/__mocks__/",
"src/**/__mocks__/",
]
}