fix: Do not create oauth clients for non-supported apps

This commit is contained in:
Faruk AYDIN
2025-01-22 17:37:59 +01:00
parent e686d3b067
commit ede745495d
3 changed files with 53 additions and 3 deletions

View File

@@ -6,9 +6,9 @@ export default async (request, response) => {
.findOne({ key: request.params.appKey })
.throwIfNotFound();
const oauthClient = await appConfig
.$relatedQuery('oauthClients')
.insert(oauthClientParams(request));
const oauthClient = await appConfig.createOAuthClient(
oauthClientParams(request)
);
renderObject(response, oauthClient, { status: 201 });
};

View File

@@ -48,6 +48,34 @@ describe('POST /api/v1/admin/apps/:appKey/oauth-clients', () => {
expect(response.body).toMatchObject(expectedPayload);
});
it('should throw validation error for app that does not support oauth connections', async () => {
await createAppConfig({
key: 'deepl',
});
const oauthClient = {
active: true,
appKey: 'deepl',
name: 'First auth client',
formattedAuthDefaults: {
clientid: 'sample client ID',
clientSecret: 'sample client secret',
instanceUrl: 'https://deepl.com',
oAuthRedirectUrl: 'http://localhost:3001/app/deepl/connection/add',
},
};
const response = await request(app)
.post('/api/v1/admin/apps/deepl/oauth-clients')
.set('Authorization', token)
.send(oauthClient)
.expect(422);
expect(response.body.errors).toMatchObject({
app: ['This app does not support OAuth clients!'],
});
});
it('should return not found response for not existing app config', async () => {
const oauthClient = {
active: true,