mirror of
https://github.com/logto-io/logto.git
synced 2025-02-03 21:48:55 -05:00
fix(core): fix rebase
This commit is contained in:
parent
29d7642c6b
commit
57a9cfa6d3
6 changed files with 44 additions and 131 deletions
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
jwtCustomizerConfigGuard,
|
||||
type jwtCustomizerConfigGuard,
|
||||
LogtoTenantConfigKey,
|
||||
LogtoConfigs,
|
||||
type AdminConsoleData,
|
||||
|
@ -12,9 +12,7 @@ import {
|
|||
import { convertToIdentifiers } from '@logto/shared';
|
||||
import type { CommonQueryMethods } from 'slonik';
|
||||
import { sql } from 'slonik';
|
||||
import { z } from 'zod';
|
||||
|
||||
import RequestError from '#src/errors/RequestError/index.js';
|
||||
import { type z } from 'zod';
|
||||
|
||||
import { DeletionError } from '#src/errors/SlonikError/index.js';
|
||||
|
||||
|
@ -47,6 +45,17 @@ export const createLogtoConfigQueries = (pool: CommonQueryMethods) => {
|
|||
where ${fields.key} in (${sql.join(keys, sql`,`)})
|
||||
`);
|
||||
|
||||
const deleteRowByKey = async (key: LogtoConfigKey) => {
|
||||
const { rowCount } = await pool.query(sql`
|
||||
delete from ${table}
|
||||
where ${fields.key}=${key}
|
||||
`);
|
||||
|
||||
if (rowCount < 1) {
|
||||
throw new DeletionError(LogtoConfigs.table, key);
|
||||
}
|
||||
};
|
||||
|
||||
const updateOidcConfigsByKey = async (key: LogtoOidcConfigKey, value: OidcConfigKey[]) =>
|
||||
pool.query(sql`
|
||||
update ${table}
|
||||
|
@ -71,34 +80,7 @@ export const createLogtoConfigQueries = (pool: CommonQueryMethods) => {
|
|||
`
|
||||
);
|
||||
|
||||
const getJwtCustomizer = async <T extends LogtoJwtTokenKey>(key: T) => {
|
||||
const { rows } = await getRowsByKeys([key]);
|
||||
|
||||
// If the record does not exist (`rows` is empty)
|
||||
if (rows.length === 0) {
|
||||
throw new RequestError({
|
||||
code: 'entity.not_exists',
|
||||
name: table,
|
||||
id: key,
|
||||
status: 404,
|
||||
});
|
||||
}
|
||||
|
||||
return z.object({ value: jwtCustomizerConfigGuard[key] }).parse(rows[0]);
|
||||
};
|
||||
|
||||
const deleteJwtCustomizer = async <T extends LogtoJwtTokenKey>(key: T) => {
|
||||
const { rowCount } = await pool.query(
|
||||
sql`
|
||||
delete from ${table}
|
||||
where ${fields.key} = ${key}
|
||||
`
|
||||
);
|
||||
|
||||
if (rowCount < 1) {
|
||||
throw new DeletionError(LogtoConfigs.table, key);
|
||||
}
|
||||
};
|
||||
const deleteJwtCustomizer = async <T extends LogtoJwtTokenKey>(key: T) => deleteRowByKey(key);
|
||||
|
||||
return {
|
||||
getAdminConsoleConfig,
|
||||
|
@ -107,7 +89,6 @@ export const createLogtoConfigQueries = (pool: CommonQueryMethods) => {
|
|||
getRowsByKeys,
|
||||
updateOidcConfigsByKey,
|
||||
upsertJwtCustomizer,
|
||||
getJwtCustomizer,
|
||||
deleteJwtCustomizer,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -169,33 +169,14 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"get": {
|
||||
"summary": "Get JWT customizer",
|
||||
"description": "Get the JWT customizer for the given token type.",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "tokenType",
|
||||
"description": "The token type to get the JWT customizer for."
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "The JWT customizer."
|
||||
},
|
||||
"404": {
|
||||
"description": "The JWT customizer does not exist."
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Delete JWT customizer",
|
||||
"description": "Delete the JWT customizer for the given token type.",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "tokenType",
|
||||
"description": "The token type to delete the JWT customizer for."
|
||||
"name": "tokenTypePath",
|
||||
"description": "The token type path to delete the JWT customizer for."
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
|
|
@ -277,15 +277,6 @@ describe('configs routes', () => {
|
|||
expect(response.body).toEqual(mockJwtCustomizerConfigForAccessToken.value);
|
||||
});
|
||||
|
||||
it('GET /configs/jwt-customizer/:tokenType should return the record', async () => {
|
||||
logtoConfigLibraries.getJwtCustomizer.mockResolvedValueOnce(
|
||||
mockJwtCustomizerConfigForAccessToken
|
||||
);
|
||||
const response = await routeRequester.get('/configs/jwt-customizer/access-token');
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(mockJwtCustomizerConfigForAccessToken.value);
|
||||
});
|
||||
|
||||
it('DELETE /configs/jwt-customizer/:tokenType should delete the record', async () => {
|
||||
const response = await routeRequester.delete('/configs/jwt-customizer/client-credentials');
|
||||
expect(logtoConfigQueries.deleteJwtCustomizer).toHaveBeenCalledWith(
|
||||
|
|
|
@ -81,22 +81,14 @@ const getRedactedOidcKeyResponse = async (
|
|||
export default function logtoConfigRoutes<T extends AuthedRouter>(
|
||||
...[router, { queries, logtoConfigs, invalidateCache }]: RouterInitArgs<T>
|
||||
) {
|
||||
<<<<<<< HEAD
|
||||
const { getAdminConsoleConfig, getRowsByKeys, updateAdminConsoleConfig, updateOidcConfigsByKey } =
|
||||
queries.logtoConfigs;
|
||||
const { getOidcConfigs, upsertJwtCustomizer, getJwtCustomizer } = logtoConfigs;
|
||||
=======
|
||||
const {
|
||||
getAdminConsoleConfig,
|
||||
getRowsByKeys,
|
||||
insertJwtCustomizer,
|
||||
updateAdminConsoleConfig,
|
||||
updateOidcConfigsByKey,
|
||||
getJwtCustomizer,
|
||||
deleteJwtCustomizer,
|
||||
} = queries.logtoConfigs;
|
||||
const { getOidcConfigs } = logtoConfigs;
|
||||
>>>>>>> 8086c9bc6 (feat(core): add GET /configs/jwt-customizer API)
|
||||
const { getOidcConfigs, upsertJwtCustomizer, getJwtCustomizer } = logtoConfigs;
|
||||
|
||||
router.get(
|
||||
'/configs/admin-console',
|
||||
|
@ -278,19 +270,23 @@ export default function logtoConfigRoutes<T extends AuthedRouter>(
|
|||
);
|
||||
|
||||
router.delete(
|
||||
'/configs/jwt-customizer/:tokenType',
|
||||
'/configs/jwt-customizer/:tokenTypePath',
|
||||
koaGuard({
|
||||
params: z.object({
|
||||
tokenType: z.nativeEnum(LogtoJwtTokenKeyType),
|
||||
tokenTypePath: z.nativeEnum(LogtoJwtTokenPath),
|
||||
}),
|
||||
status: [204, 404],
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const {
|
||||
params: { tokenType },
|
||||
params: { tokenTypePath },
|
||||
} = ctx.guard;
|
||||
|
||||
await deleteJwtCustomizer(getLogtoJwtTokenKey(tokenType));
|
||||
await deleteJwtCustomizer(
|
||||
tokenTypePath === LogtoJwtTokenPath.AccessToken
|
||||
? LogtoJwtTokenKey.AccessToken
|
||||
: LogtoJwtTokenKey.ClientCredentials
|
||||
);
|
||||
ctx.status = 204;
|
||||
return next();
|
||||
}
|
||||
|
|
|
@ -46,10 +46,5 @@ export const getJwtCustomizer = async (keyTypePath: 'access-token' | 'client-cre
|
|||
.get(`configs/jwt-customizer/${keyTypePath}`)
|
||||
.json<JwtCustomizerAccessToken | JwtCustomizerClientCredentials>();
|
||||
|
||||
export const getJwtCustomizer = async (keyType: LogtoJwtTokenKeyType) =>
|
||||
authedAdminApi
|
||||
.get(`configs/jwt-customizer/${keyType}`)
|
||||
.json<JwtCustomizerAccessToken | JwtCustomizerClientCredentials>();
|
||||
|
||||
export const deleteJwtCustomizer = async (keyType: LogtoJwtTokenKeyType) =>
|
||||
authedAdminApi.delete(`configs/jwt-customizer/${keyType}`);
|
||||
export const deleteJwtCustomizer = async (keyTypePath: 'access-token' | 'client-credentials') =>
|
||||
authedAdminApi.delete(`configs/jwt-customizer/${keyTypePath}`);
|
||||
|
|
|
@ -3,7 +3,6 @@ import {
|
|||
type AdminConsoleData,
|
||||
LogtoOidcConfigKeyType,
|
||||
} from '@logto/schemas';
|
||||
import { HTTPError } from 'got';
|
||||
|
||||
import {
|
||||
deleteOidcKey,
|
||||
|
@ -128,7 +127,7 @@ describe('admin console sign-in experience', () => {
|
|||
expect(privateKeys2[1]?.id).toBe(privateKeys[0]?.id);
|
||||
});
|
||||
|
||||
it('should successfully POST/GET/DELETE a JWT customizer (access token)', async () => {
|
||||
it('should successfully PUT/GET/DELETE a JWT customizer (access token)', async () => {
|
||||
const accessTokenJwtCustomizerPayload = {
|
||||
script: '',
|
||||
envVars: {},
|
||||
|
@ -140,25 +139,15 @@ describe('admin console sign-in experience', () => {
|
|||
},
|
||||
};
|
||||
|
||||
const accessToken = await upsertJwtCustomizer('access-token', accessTokenJwtCustomizerPayload);
|
||||
/**
|
||||
* The 'access-token' JWT customizer has not been created, as a result:
|
||||
* - GET request should fail with a 404 error
|
||||
* - DELETE request should fail with a 404 error
|
||||
*/
|
||||
await expectRejects(getJwtCustomizer('access-token'), {
|
||||
code: 'entity.not_exists',
|
||||
statusCode: 404,
|
||||
});
|
||||
const response = await deleteJwtCustomizer('access-token').catch(
|
||||
(error: unknown) => error
|
||||
);
|
||||
expect(response instanceof HTTPError && response.response.statusCode === 404).toBe(true);
|
||||
|
||||
const accessToken = await insertJwtCustomizer(
|
||||
'access-token',
|
||||
accessTokenJwtCustomizerPayload
|
||||
);
|
||||
await expectRejects(deleteJwtCustomizer('access-token'), {
|
||||
code: 'entity.not_found',
|
||||
statusCode: 404,
|
||||
});
|
||||
const accessToken = await upsertJwtCustomizer('access-token', accessTokenJwtCustomizerPayload);
|
||||
expect(accessToken).toMatchObject(accessTokenJwtCustomizerPayload);
|
||||
const newAccessTokenJwtCustomizerPayload = {
|
||||
...accessTokenJwtCustomizerPayload,
|
||||
|
@ -172,44 +161,30 @@ describe('admin console sign-in experience', () => {
|
|||
await expect(getJwtCustomizer('access-token')).resolves.toMatchObject(
|
||||
newAccessTokenJwtCustomizerPayload
|
||||
);
|
||||
|
||||
/**
|
||||
* The 'access-token' JWT customizer has been created, as a result:
|
||||
* - DELETE request should succeed
|
||||
* - GET request should fail with a 404 error after the successful DELETE request
|
||||
*/
|
||||
await expect(deleteJwtCustomizer('access-token')).resolves.not.toThrow();
|
||||
await expectRejects(getJwtCustomizer('access-token'), {
|
||||
code: 'entity.not_found',
|
||||
code: 'entity.not_exists',
|
||||
statusCode: 404,
|
||||
});
|
||||
});
|
||||
|
||||
it('should successfully POST/GET/DELETE a JWT customizer (client credentials)', async () => {
|
||||
it('should successfully PUT/GET/DELETE a JWT customizer (client credentials)', async () => {
|
||||
const clientCredentialsJwtCustomizerPayload = {
|
||||
script: '',
|
||||
envVars: {},
|
||||
contextSample: {},
|
||||
};
|
||||
|
||||
const clientCredentials = await upsertJwtCustomizer(
|
||||
'client-credentials',
|
||||
/**
|
||||
* The 'client-credentials' JWT customizer has not been created, as a result:
|
||||
* - GET request should fail with a 404 error
|
||||
* - DELETE request should fail with a 404 error
|
||||
*/
|
||||
await expectRejects(getJwtCustomizer('client-credentials'), {
|
||||
code: 'entity.not_exists',
|
||||
statusCode: 404,
|
||||
});
|
||||
const response = await deleteJwtCustomizer(LogtoJwtTokenKeyType.ClientCredentials).catch(
|
||||
(error: unknown) => error
|
||||
);
|
||||
expect(response instanceof HTTPError && response.response.statusCode === 404).toBe(true);
|
||||
|
||||
const clientCredentials = await insertJwtCustomizer(
|
||||
LogtoJwtTokenKeyType.ClientCredentials,
|
||||
await expectRejects(deleteJwtCustomizer('client-credentials'), {
|
||||
code: 'entity.not_found',
|
||||
statusCode: 404,
|
||||
});
|
||||
const clientCredentials = await upsertJwtCustomizer(
|
||||
'client-credentials',
|
||||
clientCredentialsJwtCustomizerPayload
|
||||
);
|
||||
expect(clientCredentials).toMatchObject(clientCredentialsJwtCustomizerPayload);
|
||||
|
@ -225,15 +200,9 @@ describe('admin console sign-in experience', () => {
|
|||
await expect(getJwtCustomizer('client-credentials')).resolves.toMatchObject(
|
||||
newClientCredentialsJwtCustomizerPayload
|
||||
);
|
||||
|
||||
/**
|
||||
* The 'client-credentials' JWT customizer has been created, as a result:
|
||||
* - DELETE request should succeed
|
||||
* - GET request should fail with a 404 error after the successful DELETE request
|
||||
*/
|
||||
await deleteJwtCustomizer(LogtoJwtTokenKeyType.ClientCredentials);
|
||||
await expectRejects(getJwtCustomizer(LogtoJwtTokenKeyType.ClientCredentials), {
|
||||
code: 'entity.not_found',
|
||||
await expect(deleteJwtCustomizer('client-credentials')).resolves.not.toThrow();
|
||||
await expectRejects(getJwtCustomizer('client-credentials'), {
|
||||
code: 'entity.not_exists',
|
||||
statusCode: 404,
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue