diff --git a/packages/backend/src/controllers/api/v1/admin/apps/create-auth-client.ee.js b/packages/backend/src/controllers/api/v1/admin/apps/create-oauth-client.ee.js similarity index 66% rename from packages/backend/src/controllers/api/v1/admin/apps/create-auth-client.ee.js rename to packages/backend/src/controllers/api/v1/admin/apps/create-oauth-client.ee.js index 49cbfff2..ffba9257 100644 --- a/packages/backend/src/controllers/api/v1/admin/apps/create-auth-client.ee.js +++ b/packages/backend/src/controllers/api/v1/admin/apps/create-oauth-client.ee.js @@ -6,14 +6,14 @@ export default async (request, response) => { .findOne({ key: request.params.appKey }) .throwIfNotFound(); - const appAuthClient = await appConfig - .$relatedQuery('appAuthClients') - .insert(appAuthClientParams(request)); + const oauthClient = await appConfig + .$relatedQuery('oauthClients') + .insert(oauthClientParams(request)); - renderObject(response, appAuthClient, { status: 201 }); + renderObject(response, oauthClient, { status: 201 }); }; -const appAuthClientParams = (request) => { +const oauthClientParams = (request) => { const { active, appKey, name, formattedAuthDefaults } = request.body; return { diff --git a/packages/backend/src/controllers/api/v1/admin/apps/create-auth-client.ee.test.js b/packages/backend/src/controllers/api/v1/admin/apps/create-oauth-client.ee.test.js similarity index 81% rename from packages/backend/src/controllers/api/v1/admin/apps/create-auth-client.ee.test.js rename to packages/backend/src/controllers/api/v1/admin/apps/create-oauth-client.ee.test.js index ea658f88..4746a881 100644 --- a/packages/backend/src/controllers/api/v1/admin/apps/create-auth-client.ee.test.js +++ b/packages/backend/src/controllers/api/v1/admin/apps/create-oauth-client.ee.test.js @@ -5,11 +5,11 @@ import app from '../../../../../app.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import { createUser } from '../../../../../../test/factories/user.js'; import { createRole } from '../../../../../../test/factories/role.js'; -import createAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/create-auth-client.js'; +import createOAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/create-oauth-client.js'; import { createAppConfig } from '../../../../../../test/factories/app-config.js'; import * as license from '../../../../../helpers/license.ee.js'; -describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => { +describe('POST /api/v1/admin/apps/:appKey/oauth-clients', () => { let currentUser, adminRole, token; beforeEach(async () => { @@ -26,7 +26,7 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => { key: 'gitlab', }); - const appAuthClient = { + const oauthClient = { active: true, appKey: 'gitlab', name: 'First auth client', @@ -39,17 +39,17 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => { }; const response = await request(app) - .post('/api/v1/admin/apps/gitlab/auth-clients') + .post('/api/v1/admin/apps/gitlab/oauth-clients') .set('Authorization', token) - .send(appAuthClient) + .send(oauthClient) .expect(201); - const expectedPayload = createAppAuthClientMock(appAuthClient); + const expectedPayload = createOAuthClientMock(oauthClient); expect(response.body).toMatchObject(expectedPayload); }); it('should return not found response for not existing app config', async () => { - const appAuthClient = { + const oauthClient = { active: true, appKey: 'gitlab', name: 'First auth client', @@ -62,9 +62,9 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => { }; await request(app) - .post('/api/v1/admin/apps/gitlab/auth-clients') + .post('/api/v1/admin/apps/gitlab/oauth-clients') .set('Authorization', token) - .send(appAuthClient) + .send(oauthClient) .expect(404); }); @@ -73,14 +73,14 @@ describe('POST /api/v1/admin/apps/:appKey/auth-clients', () => { key: 'gitlab', }); - const appAuthClient = { + const oauthClient = { appKey: 'gitlab', }; const response = await request(app) - .post('/api/v1/admin/apps/gitlab/auth-clients') + .post('/api/v1/admin/apps/gitlab/oauth-clients') .set('Authorization', token) - .send(appAuthClient) + .send(oauthClient) .expect(422); expect(response.body.meta.type).toStrictEqual('ModelValidation'); diff --git a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-client.ee.js b/packages/backend/src/controllers/api/v1/admin/apps/get-auth-client.ee.js deleted file mode 100644 index c43ac23e..00000000 --- a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-client.ee.js +++ /dev/null @@ -1,11 +0,0 @@ -import { renderObject } from '../../../../../helpers/renderer.js'; -import AppAuthClient from '../../../../../models/app-auth-client.js'; - -export default async (request, response) => { - const appAuthClient = await AppAuthClient.query() - .findById(request.params.appAuthClientId) - .where({ app_key: request.params.appKey }) - .throwIfNotFound(); - - renderObject(response, appAuthClient); -}; diff --git a/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-client.ee.js b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-client.ee.js new file mode 100644 index 00000000..577461f2 --- /dev/null +++ b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-client.ee.js @@ -0,0 +1,11 @@ +import { renderObject } from '../../../../../helpers/renderer.js'; +import OAuthClient from '../../../../../models/oauth-client.js'; + +export default async (request, response) => { + const oauthClient = await OAuthClient.query() + .findById(request.params.oauthClientId) + .where({ app_key: request.params.appKey }) + .throwIfNotFound(); + + renderObject(response, oauthClient); +}; diff --git a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-client.ee.test.js b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-client.ee.test.js similarity index 56% rename from packages/backend/src/controllers/api/v1/admin/apps/get-auth-client.ee.test.js rename to packages/backend/src/controllers/api/v1/admin/apps/get-oauth-client.ee.test.js index 2edb0ffe..5b30c289 100644 --- a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-client.ee.test.js +++ b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-client.ee.test.js @@ -5,12 +5,12 @@ import app from '../../../../../app.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import { createUser } from '../../../../../../test/factories/user.js'; import { createRole } from '../../../../../../test/factories/role.js'; -import getAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-client.js'; -import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js'; +import getOAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-oauth-client.js'; +import { createOAuthClient } from '../../../../../../test/factories/oauth-client.js'; import * as license from '../../../../../helpers/license.ee.js'; -describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => { - let currentUser, adminRole, currentAppAuthClient, token; +describe('GET /api/v1/admin/apps/:appKey/oauth-clients/:oauthClientId', () => { + let currentUser, adminRole, currentOAuthClient, token; beforeEach(async () => { vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true); @@ -18,29 +18,29 @@ describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => { adminRole = await createRole({ name: 'Admin' }); currentUser = await createUser({ roleId: adminRole.id }); - currentAppAuthClient = await createAppAuthClient({ + currentOAuthClient = await createOAuthClient({ appKey: 'deepl', }); token = await createAuthTokenByUserId(currentUser.id); }); - it('should return specified app auth client', async () => { + it('should return specified oauth client', async () => { const response = await request(app) - .get(`/api/v1/admin/apps/deepl/auth-clients/${currentAppAuthClient.id}`) + .get(`/api/v1/admin/apps/deepl/oauth-clients/${currentOAuthClient.id}`) .set('Authorization', token) .expect(200); - const expectedPayload = getAppAuthClientMock(currentAppAuthClient); + const expectedPayload = getOAuthClientMock(currentOAuthClient); expect(response.body).toStrictEqual(expectedPayload); }); - it('should return not found response for not existing app auth client ID', async () => { - const notExistingAppAuthClientUUID = Crypto.randomUUID(); + it('should return not found response for not existing oauth client ID', async () => { + const notExistingOAuthClientUUID = Crypto.randomUUID(); await request(app) .get( - `/api/v1/admin/apps/deepl/auth-clients/${notExistingAppAuthClientUUID}` + `/api/v1/admin/apps/deepl/oauth-clients/${notExistingOAuthClientUUID}` ) .set('Authorization', token) .expect(404); @@ -48,7 +48,7 @@ describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => { it('should return bad request response for invalid UUID', async () => { await request(app) - .get('/api/v1/admin/apps/deepl/auth-clients/invalidAppAuthClientUUID') + .get('/api/v1/admin/apps/deepl/oauth-clients/invalidOAuthClientUUID') .set('Authorization', token) .expect(400); }); diff --git a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-clients.ee.js b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-clients.ee.js similarity index 54% rename from packages/backend/src/controllers/api/v1/admin/apps/get-auth-clients.ee.js rename to packages/backend/src/controllers/api/v1/admin/apps/get-oauth-clients.ee.js index 257e0dd7..230104a4 100644 --- a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-clients.ee.js +++ b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-clients.ee.js @@ -1,10 +1,10 @@ import { renderObject } from '../../../../../helpers/renderer.js'; -import AppAuthClient from '../../../../../models/app-auth-client.js'; +import OAuthClient from '../../../../../models/oauth-client.js'; export default async (request, response) => { - const appAuthClients = await AppAuthClient.query() + const oauthClients = await OAuthClient.query() .where({ app_key: request.params.appKey }) .orderBy('created_at', 'desc'); - renderObject(response, appAuthClients); + renderObject(response, oauthClients); }; diff --git a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-clients.ee.test.js b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-clients.ee.test.js similarity index 62% rename from packages/backend/src/controllers/api/v1/admin/apps/get-auth-clients.ee.test.js rename to packages/backend/src/controllers/api/v1/admin/apps/get-oauth-clients.ee.test.js index 7fbba6e0..69be2bbf 100644 --- a/packages/backend/src/controllers/api/v1/admin/apps/get-auth-clients.ee.test.js +++ b/packages/backend/src/controllers/api/v1/admin/apps/get-oauth-clients.ee.test.js @@ -4,11 +4,11 @@ import app from '../../../../../app.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import { createUser } from '../../../../../../test/factories/user.js'; import { createRole } from '../../../../../../test/factories/role.js'; -import getAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-clients.js'; -import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js'; +import getAdminOAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-oauth-clients.js'; +import { createOAuthClient } from '../../../../../../test/factories/oauth-client.js'; import * as license from '../../../../../helpers/license.ee.js'; -describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => { +describe('GET /api/v1/admin/apps/:appKey/oauth-clients', () => { let currentUser, adminRole, token; beforeEach(async () => { @@ -20,23 +20,23 @@ describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => { token = await createAuthTokenByUserId(currentUser.id); }); - it('should return specified app auth client info', async () => { - const appAuthClientOne = await createAppAuthClient({ + it('should return specified oauth client info', async () => { + const oauthClientOne = await createOAuthClient({ appKey: 'deepl', }); - const appAuthClientTwo = await createAppAuthClient({ + const oauthClientTwo = await createOAuthClient({ appKey: 'deepl', }); const response = await request(app) - .get('/api/v1/admin/apps/deepl/auth-clients') + .get('/api/v1/admin/apps/deepl/oauth-clients') .set('Authorization', token) .expect(200); - const expectedPayload = getAuthClientsMock([ - appAuthClientTwo, - appAuthClientOne, + const expectedPayload = getAdminOAuthClientsMock([ + oauthClientTwo, + oauthClientOne, ]); expect(response.body).toStrictEqual(expectedPayload); diff --git a/packages/backend/src/controllers/api/v1/admin/apps/update-auth-client.ee.js b/packages/backend/src/controllers/api/v1/admin/apps/update-auth-client.ee.js deleted file mode 100644 index a34e9a67..00000000 --- a/packages/backend/src/controllers/api/v1/admin/apps/update-auth-client.ee.js +++ /dev/null @@ -1,22 +0,0 @@ -import { renderObject } from '../../../../../helpers/renderer.js'; -import AppAuthClient from '../../../../../models/app-auth-client.js'; - -export default async (request, response) => { - const appAuthClient = await AppAuthClient.query() - .findById(request.params.appAuthClientId) - .throwIfNotFound(); - - await appAuthClient.$query().patchAndFetch(appAuthClientParams(request)); - - renderObject(response, appAuthClient); -}; - -const appAuthClientParams = (request) => { - const { active, name, formattedAuthDefaults } = request.body; - - return { - active, - name, - formattedAuthDefaults, - }; -}; diff --git a/packages/backend/src/controllers/api/v1/admin/apps/update-oauth-client.ee.js b/packages/backend/src/controllers/api/v1/admin/apps/update-oauth-client.ee.js new file mode 100644 index 00000000..7e9c3f7a --- /dev/null +++ b/packages/backend/src/controllers/api/v1/admin/apps/update-oauth-client.ee.js @@ -0,0 +1,22 @@ +import { renderObject } from '../../../../../helpers/renderer.js'; +import OAuthClient from '../../../../../models/oauth-client.js'; + +export default async (request, response) => { + const oauthClient = await OAuthClient.query() + .findById(request.params.oauthClientId) + .throwIfNotFound(); + + await oauthClient.$query().patchAndFetch(oauthClientParams(request)); + + renderObject(response, oauthClient); +}; + +const oauthClientParams = (request) => { + const { active, name, formattedAuthDefaults } = request.body; + + return { + active, + name, + formattedAuthDefaults, + }; +}; diff --git a/packages/backend/src/controllers/api/v1/admin/apps/update-auth-client.ee.test.js b/packages/backend/src/controllers/api/v1/admin/apps/update-oauth-client.ee.test.js similarity index 65% rename from packages/backend/src/controllers/api/v1/admin/apps/update-auth-client.ee.test.js rename to packages/backend/src/controllers/api/v1/admin/apps/update-oauth-client.ee.test.js index f1a7bccd..9d28bb34 100644 --- a/packages/backend/src/controllers/api/v1/admin/apps/update-auth-client.ee.test.js +++ b/packages/backend/src/controllers/api/v1/admin/apps/update-oauth-client.ee.test.js @@ -6,12 +6,12 @@ import app from '../../../../../app.js'; import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js'; import { createUser } from '../../../../../../test/factories/user.js'; import { createRole } from '../../../../../../test/factories/role.js'; -import updateAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/update-auth-client.js'; +import updateOAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/update-oauth-client.js'; import { createAppConfig } from '../../../../../../test/factories/app-config.js'; -import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js'; +import { createOAuthClient } from '../../../../../../test/factories/oauth-client.js'; import * as license from '../../../../../helpers/license.ee.js'; -describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => { +describe('PATCH /api/v1/admin/apps/:appKey/oauth-clients', () => { let currentUser, adminRole, token; beforeEach(async () => { @@ -27,8 +27,8 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => { }); }); - it('should return updated entity for valid app auth client', async () => { - const appAuthClient = { + it('should return updated entity for valid oauth client', async () => { + const oauthClient = { active: true, appKey: 'gitlab', formattedAuthDefaults: { @@ -39,33 +39,33 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => { }, }; - const existingAppAuthClient = await createAppAuthClient({ + const existingOAuthClient = await createOAuthClient({ appKey: 'gitlab', name: 'First auth client', }); const response = await request(app) .patch( - `/api/v1/admin/apps/gitlab/auth-clients/${existingAppAuthClient.id}` + `/api/v1/admin/apps/gitlab/oauth-clients/${existingOAuthClient.id}` ) .set('Authorization', token) - .send(appAuthClient) + .send(oauthClient) .expect(200); - const expectedPayload = updateAppAuthClientMock({ - ...existingAppAuthClient, - ...appAuthClient, + const expectedPayload = updateOAuthClientMock({ + ...existingOAuthClient, + ...oauthClient, }); expect(response.body).toMatchObject(expectedPayload); }); - it('should return not found response for not existing app auth client', async () => { - const notExistingAppAuthClientId = Crypto.randomUUID(); + it('should return not found response for not existing oauth client', async () => { + const notExistingOAuthClientId = Crypto.randomUUID(); await request(app) .patch( - `/api/v1/admin/apps/gitlab/auth-clients/${notExistingAppAuthClientId}` + `/api/v1/admin/apps/gitlab/oauth-clients/${notExistingOAuthClientId}` ) .set('Authorization', token) .expect(404); @@ -73,27 +73,27 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => { it('should return bad request response for invalid UUID', async () => { await request(app) - .patch('/api/v1/admin/apps/gitlab/auth-clients/invalidAuthClientUUID') + .patch('/api/v1/admin/apps/gitlab/oauth-clients/invalidAuthClientUUID') .set('Authorization', token) .expect(400); }); it('should return HTTP 422 for invalid payload', async () => { - const appAuthClient = { + const oauthClient = { formattedAuthDefaults: 'invalid input', }; - const existingAppAuthClient = await createAppAuthClient({ + const existingOAuthClient = await createOAuthClient({ appKey: 'gitlab', name: 'First auth client', }); const response = await request(app) .patch( - `/api/v1/admin/apps/gitlab/auth-clients/${existingAppAuthClient.id}` + `/api/v1/admin/apps/gitlab/oauth-clients/${existingOAuthClient.id}` ) .set('Authorization', token) - .send(appAuthClient) + .send(oauthClient) .expect(422); expect(response.body.meta.type).toBe('ModelValidation'); diff --git a/packages/backend/src/controllers/api/v1/apps/create-connection.js b/packages/backend/src/controllers/api/v1/apps/create-connection.js index 40a081b9..35e3a34b 100644 --- a/packages/backend/src/controllers/api/v1/apps/create-connection.js +++ b/packages/backend/src/controllers/api/v1/apps/create-connection.js @@ -9,18 +9,18 @@ export default async (request, response) => { .$query() .withGraphFetched({ appConfig: true, - appAuthClient: true, + oauthClient: true, }); renderObject(response, connectionWithAppConfigAndAuthClient, { status: 201 }); }; const connectionParams = (request) => { - const { appAuthClientId, formattedData } = request.body; + const { oauthClientId, formattedData } = request.body; return { key: request.params.appKey, - appAuthClientId, + oauthClientId, formattedData, verified: false, }; diff --git a/packages/backend/src/controllers/api/v1/apps/create-connection.test.js b/packages/backend/src/controllers/api/v1/apps/create-connection.test.js index c73df6b6..0465458f 100644 --- a/packages/backend/src/controllers/api/v1/apps/create-connection.test.js +++ b/packages/backend/src/controllers/api/v1/apps/create-connection.test.js @@ -3,7 +3,7 @@ import request from 'supertest'; import app from '../../../../app.js'; import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js'; import { createAppConfig } from '../../../../../test/factories/app-config.js'; -import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js'; +import { createOAuthClient } from '../../../../../test/factories/oauth-client.js'; import { createUser } from '../../../../../test/factories/user.js'; import { createPermission } from '../../../../../test/factories/permission.js'; import { createRole } from '../../../../../test/factories/role.js'; @@ -267,7 +267,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => { }); describe('with auth client enabled', async () => { - let appAuthClient; + let oauthClient; beforeEach(async () => { await createAppConfig({ @@ -276,7 +276,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => { useOnlyPredefinedAuthClients: false, }); - appAuthClient = await createAppAuthClient({ + oauthClient = await createOAuthClient({ appKey: 'gitlab', active: true, formattedAuthDefaults: { @@ -290,7 +290,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => { it('should return created connection', async () => { const connectionData = { - appAuthClientId: appAuthClient.id, + oauthClientId: oauthClient.id, }; const response = await request(app) @@ -338,7 +338,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => { }); describe('with auth client disabled', async () => { - let appAuthClient; + let oauthClient; beforeEach(async () => { await createAppConfig({ @@ -347,7 +347,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => { useOnlyPredefinedAuthClients: false, }); - appAuthClient = await createAppAuthClient({ + oauthClient = await createOAuthClient({ appKey: 'gitlab', active: false, }); @@ -355,7 +355,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => { it('should return with not authorized response', async () => { const connectionData = { - appAuthClientId: appAuthClient.id, + oauthClientId: oauthClient.id, }; await request(app) diff --git a/packages/backend/src/controllers/api/v1/apps/get-action-substeps.test.js b/packages/backend/src/controllers/api/v1/apps/get-action-substeps.test.js index bc28ae33..e3b6db03 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-action-substeps.test.js +++ b/packages/backend/src/controllers/api/v1/apps/get-action-substeps.test.js @@ -15,7 +15,7 @@ describe('GET /api/v1/apps/:appKey/actions/:actionKey/substeps', () => { exampleApp = await App.findOneByKey('github'); }); - it('should return the app auth info', async () => { + it('should return the action substeps info', async () => { const actions = await App.findActionsByKey('github'); const exampleAction = actions.find( (action) => action.key === 'createIssue' diff --git a/packages/backend/src/controllers/api/v1/apps/get-auth-client.ee.js b/packages/backend/src/controllers/api/v1/apps/get-auth-client.ee.js deleted file mode 100644 index 5aceb529..00000000 --- a/packages/backend/src/controllers/api/v1/apps/get-auth-client.ee.js +++ /dev/null @@ -1,11 +0,0 @@ -import { renderObject } from '../../../../helpers/renderer.js'; -import AppAuthClient from '../../../../models/app-auth-client.js'; - -export default async (request, response) => { - const appAuthClient = await AppAuthClient.query() - .findById(request.params.appAuthClientId) - .where({ app_key: request.params.appKey, active: true }) - .throwIfNotFound(); - - renderObject(response, appAuthClient); -}; diff --git a/packages/backend/src/controllers/api/v1/apps/get-config.ee.js b/packages/backend/src/controllers/api/v1/apps/get-config.ee.js index d0837e35..229c20d1 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-config.ee.js +++ b/packages/backend/src/controllers/api/v1/apps/get-config.ee.js @@ -4,7 +4,7 @@ import AppConfig from '../../../../models/app-config.js'; export default async (request, response) => { const appConfig = await AppConfig.query() .withGraphFetched({ - appAuthClients: true, + oauthClients: true, }) .findOne({ key: request.params.appKey, diff --git a/packages/backend/src/controllers/api/v1/apps/get-connections.js b/packages/backend/src/controllers/api/v1/apps/get-connections.js index 1f5a91ad..0f2fdfcb 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-connections.js +++ b/packages/backend/src/controllers/api/v1/apps/get-connections.js @@ -9,7 +9,7 @@ export default async (request, response) => { .select('connections.*') .withGraphFetched({ appConfig: true, - appAuthClient: true, + oauthClient: true, }) .fullOuterJoinRelated('steps') .where({ diff --git a/packages/backend/src/controllers/api/v1/apps/get-oauth-client.ee.js b/packages/backend/src/controllers/api/v1/apps/get-oauth-client.ee.js new file mode 100644 index 00000000..2577f27d --- /dev/null +++ b/packages/backend/src/controllers/api/v1/apps/get-oauth-client.ee.js @@ -0,0 +1,11 @@ +import { renderObject } from '../../../../helpers/renderer.js'; +import OAuthClient from '../../../../models/oauth-client.js'; + +export default async (request, response) => { + const oauthClient = await OAuthClient.query() + .findById(request.params.oauthClientId) + .where({ app_key: request.params.appKey, active: true }) + .throwIfNotFound(); + + renderObject(response, oauthClient); +}; diff --git a/packages/backend/src/controllers/api/v1/apps/get-auth-client.ee.test.js b/packages/backend/src/controllers/api/v1/apps/get-oauth-client.ee.test.js similarity index 54% rename from packages/backend/src/controllers/api/v1/apps/get-auth-client.ee.test.js rename to packages/backend/src/controllers/api/v1/apps/get-oauth-client.ee.test.js index d5bea452..b39367f8 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-auth-client.ee.test.js +++ b/packages/backend/src/controllers/api/v1/apps/get-oauth-client.ee.test.js @@ -4,46 +4,46 @@ import Crypto from 'crypto'; import app from '../../../../app.js'; import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js'; import { createUser } from '../../../../../test/factories/user.js'; -import getAppAuthClientMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth-client.js'; -import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js'; +import getOAuthClientMock from '../../../../../test/mocks/rest/api/v1/apps/get-oauth-client.js'; +import { createOAuthClient } from '../../../../../test/factories/oauth-client.js'; import * as license from '../../../../helpers/license.ee.js'; -describe('GET /api/v1/apps/:appKey/auth-clients/:appAuthClientId', () => { - let currentUser, currentAppAuthClient, token; +describe('GET /api/v1/apps/:appKey/oauth-clients/:oauthClientId', () => { + let currentUser, currentOAuthClient, token; beforeEach(async () => { vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true); currentUser = await createUser(); - currentAppAuthClient = await createAppAuthClient({ + currentOAuthClient = await createOAuthClient({ appKey: 'deepl', }); token = await createAuthTokenByUserId(currentUser.id); }); - it('should return specified app auth client', async () => { + it('should return specified oauth client', async () => { const response = await request(app) - .get(`/api/v1/apps/deepl/auth-clients/${currentAppAuthClient.id}`) + .get(`/api/v1/apps/deepl/oauth-clients/${currentOAuthClient.id}`) .set('Authorization', token) .expect(200); - const expectedPayload = getAppAuthClientMock(currentAppAuthClient); + const expectedPayload = getOAuthClientMock(currentOAuthClient); expect(response.body).toStrictEqual(expectedPayload); }); - it('should return not found response for not existing app auth client ID', async () => { - const notExistingAppAuthClientUUID = Crypto.randomUUID(); + it('should return not found response for not existing oauth client ID', async () => { + const notExistingOAuthClientUUID = Crypto.randomUUID(); await request(app) - .get(`/api/v1/apps/deepl/auth-clients/${notExistingAppAuthClientUUID}`) + .get(`/api/v1/apps/deepl/oauth-clients/${notExistingOAuthClientUUID}`) .set('Authorization', token) .expect(404); }); it('should return bad request response for invalid UUID', async () => { await request(app) - .get('/api/v1/apps/deepl/auth-clients/invalidAppAuthClientUUID') + .get('/api/v1/apps/deepl/oauth-clients/invalidOAuthClientUUID') .set('Authorization', token) .expect(400); }); diff --git a/packages/backend/src/controllers/api/v1/apps/get-auth-clients.ee.js b/packages/backend/src/controllers/api/v1/apps/get-oauth-clients.ee.js similarity index 56% rename from packages/backend/src/controllers/api/v1/apps/get-auth-clients.ee.js rename to packages/backend/src/controllers/api/v1/apps/get-oauth-clients.ee.js index 06eceec1..2a68737b 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-auth-clients.ee.js +++ b/packages/backend/src/controllers/api/v1/apps/get-oauth-clients.ee.js @@ -1,10 +1,10 @@ import { renderObject } from '../../../../helpers/renderer.js'; -import AppAuthClient from '../../../../models/app-auth-client.js'; +import OAuthClient from '../../../../models/oauth-client.js'; export default async (request, response) => { - const appAuthClients = await AppAuthClient.query() + const oauthClients = await OAuthClient.query() .where({ app_key: request.params.appKey, active: true }) .orderBy('created_at', 'desc'); - renderObject(response, appAuthClients); + renderObject(response, oauthClients); }; diff --git a/packages/backend/src/controllers/api/v1/apps/get-auth-clients.ee.test.js b/packages/backend/src/controllers/api/v1/apps/get-oauth-clients.ee.test.js similarity index 59% rename from packages/backend/src/controllers/api/v1/apps/get-auth-clients.ee.test.js rename to packages/backend/src/controllers/api/v1/apps/get-oauth-clients.ee.test.js index d84bf167..4e4b8508 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-auth-clients.ee.test.js +++ b/packages/backend/src/controllers/api/v1/apps/get-oauth-clients.ee.test.js @@ -3,11 +3,11 @@ import request from 'supertest'; import app from '../../../../app.js'; import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js'; import { createUser } from '../../../../../test/factories/user.js'; -import getAuthClientsMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth-clients.js'; -import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js'; +import getOAuthClientsMock from '../../../../../test/mocks/rest/api/v1/apps/get-oauth-clients.js'; +import { createOAuthClient } from '../../../../../test/factories/oauth-client.js'; import * as license from '../../../../helpers/license.ee.js'; -describe('GET /api/v1/apps/:appKey/auth-clients', () => { +describe('GET /api/v1/apps/:appKey/oauth-clients', () => { let currentUser, token; beforeEach(async () => { @@ -18,23 +18,23 @@ describe('GET /api/v1/apps/:appKey/auth-clients', () => { token = await createAuthTokenByUserId(currentUser.id); }); - it('should return specified app auth client info', async () => { - const appAuthClientOne = await createAppAuthClient({ + it('should return specified oauth client info', async () => { + const oauthClientOne = await createOAuthClient({ appKey: 'deepl', }); - const appAuthClientTwo = await createAppAuthClient({ + const oauthClientTwo = await createOAuthClient({ appKey: 'deepl', }); const response = await request(app) - .get('/api/v1/apps/deepl/auth-clients') + .get('/api/v1/apps/deepl/oauth-clients') .set('Authorization', token) .expect(200); - const expectedPayload = getAuthClientsMock([ - appAuthClientTwo, - appAuthClientOne, + const expectedPayload = getOAuthClientsMock([ + oauthClientTwo, + oauthClientOne, ]); expect(response.body).toStrictEqual(expectedPayload); diff --git a/packages/backend/src/controllers/api/v1/apps/get-trigger-substeps.test.js b/packages/backend/src/controllers/api/v1/apps/get-trigger-substeps.test.js index 0748ee5a..e54b6de2 100644 --- a/packages/backend/src/controllers/api/v1/apps/get-trigger-substeps.test.js +++ b/packages/backend/src/controllers/api/v1/apps/get-trigger-substeps.test.js @@ -15,7 +15,7 @@ describe('GET /api/v1/apps/:appKey/triggers/:triggerKey/substeps', () => { exampleApp = await App.findOneByKey('github'); }); - it('should return the app auth info', async () => { + it('should return the trigger substeps info', async () => { const triggers = await App.findTriggersByKey('github'); const exampleTrigger = triggers.find( (trigger) => trigger.key === 'newIssues' diff --git a/packages/backend/src/controllers/api/v1/connections/update-connection.js b/packages/backend/src/controllers/api/v1/connections/update-connection.js index 5d84e797..979aa733 100644 --- a/packages/backend/src/controllers/api/v1/connections/update-connection.js +++ b/packages/backend/src/controllers/api/v1/connections/update-connection.js @@ -14,6 +14,6 @@ export default async (request, response) => { }; const connectionParams = (request) => { - const { formattedData, appAuthClientId } = request.body; - return { formattedData, appAuthClientId }; + const { formattedData, oauthClientId } = request.body; + return { formattedData, oauthClientId }; }; diff --git a/packages/backend/src/db/migrations/20241217170447_change_app_auth_clients_as_oauth_clients.js b/packages/backend/src/db/migrations/20241217170447_change_app_auth_clients_as_oauth_clients.js new file mode 100644 index 00000000..a26ad1f4 --- /dev/null +++ b/packages/backend/src/db/migrations/20241217170447_change_app_auth_clients_as_oauth_clients.js @@ -0,0 +1,31 @@ +export async function up(knex) { + await knex.schema.renameTable('app_auth_clients', 'oauth_clients'); + + await knex.schema.raw( + 'ALTER INDEX app_auth_clients_pkey RENAME TO oauth_clients_pkey' + ); + + await knex.schema.raw( + 'ALTER INDEX app_auth_clients_name_unique RENAME TO oauth_clients_name_unique' + ); + + return await knex.schema.alterTable('connections', (table) => { + table.renameColumn('app_auth_client_id', 'oauth_client_id'); + }); +} + +export async function down(knex) { + await knex.schema.renameTable('oauth_clients', 'app_auth_clients'); + + await knex.schema.raw( + 'ALTER INDEX oauth_clients_pkey RENAME TO app_auth_clients_pkey' + ); + + await knex.schema.raw( + 'ALTER INDEX oauth_clients_name_unique RENAME TO app_auth_clients_name_unique' + ); + + return await knex.schema.alterTable('connections', (table) => { + table.renameColumn('oauth_client_id', 'app_auth_client_id'); + }); +} diff --git a/packages/backend/src/helpers/add-authentication-steps.js b/packages/backend/src/helpers/add-authentication-steps.js index 5e7a462a..ee1bc85b 100644 --- a/packages/backend/src/helpers/add-authentication-steps.js +++ b/packages/backend/src/helpers/add-authentication-steps.js @@ -88,8 +88,8 @@ const sharedAuthenticationStepsWithAuthUrl = [ value: '{key}', }, { - name: 'appAuthClientId', - value: '{appAuthClientId}', + name: 'oauthClientId', + value: '{oauthClientId}', }, ], }, diff --git a/packages/backend/src/models/__snapshots__/connection.test.js.snap b/packages/backend/src/models/__snapshots__/connection.test.js.snap index 9fc77caf..405133b0 100644 --- a/packages/backend/src/models/__snapshots__/connection.test.js.snap +++ b/packages/backend/src/models/__snapshots__/connection.test.js.snap @@ -3,10 +3,6 @@ exports[`Connection model > jsonSchema should have correct validations 1`] = ` { "properties": { - "appAuthClientId": { - "format": "uuid", - "type": "string", - }, "createdAt": { "type": "string", }, @@ -31,6 +27,10 @@ exports[`Connection model > jsonSchema should have correct validations 1`] = ` "minLength": 1, "type": "string", }, + "oauthClientId": { + "format": "uuid", + "type": "string", + }, "updatedAt": { "type": "string", }, diff --git a/packages/backend/src/models/__snapshots__/app-auth-client.test.js.snap b/packages/backend/src/models/__snapshots__/oauth-client.test.js.snap similarity index 87% rename from packages/backend/src/models/__snapshots__/app-auth-client.test.js.snap rename to packages/backend/src/models/__snapshots__/oauth-client.test.js.snap index 87b5cc8c..04b38119 100644 --- a/packages/backend/src/models/__snapshots__/app-auth-client.test.js.snap +++ b/packages/backend/src/models/__snapshots__/oauth-client.test.js.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`AppAuthClient model > jsonSchema should have correct validations 1`] = ` +exports[`OAuthClient model > jsonSchema should have correct validations 1`] = ` { "properties": { "active": { diff --git a/packages/backend/src/models/app-auth-client.test.js b/packages/backend/src/models/app-auth-client.test.js deleted file mode 100644 index bc4be9fc..00000000 --- a/packages/backend/src/models/app-auth-client.test.js +++ /dev/null @@ -1,202 +0,0 @@ -import { describe, it, expect, vi } from 'vitest'; -import AES from 'crypto-js/aes.js'; -import enc from 'crypto-js/enc-utf8.js'; - -import AppConfig from './app-config.js'; -import AppAuthClient from './app-auth-client.js'; -import Base from './base.js'; -import appConfig from '../config/app.js'; -import { createAppAuthClient } from '../../test/factories/app-auth-client.js'; - -describe('AppAuthClient model', () => { - it('tableName should return correct name', () => { - expect(AppAuthClient.tableName).toBe('app_auth_clients'); - }); - - it('jsonSchema should have correct validations', () => { - expect(AppAuthClient.jsonSchema).toMatchSnapshot(); - }); - - it('relationMappings should return correct associations', () => { - const relationMappings = AppAuthClient.relationMappings(); - - const expectedRelations = { - appConfig: { - relation: Base.BelongsToOneRelation, - modelClass: AppConfig, - join: { - from: 'app_auth_clients.app_key', - to: 'app_configs.key', - }, - }, - }; - - expect(relationMappings).toStrictEqual(expectedRelations); - }); - - describe('encryptData', () => { - it('should return undefined if eligibleForEncryption is not true', async () => { - vi.spyOn( - AppAuthClient.prototype, - 'eligibleForEncryption' - ).mockReturnValue(false); - - const appAuthClient = new AppAuthClient(); - - expect(appAuthClient.encryptData()).toBeUndefined(); - }); - - it('should encrypt formattedAuthDefaults and set it to authDefaults', async () => { - vi.spyOn( - AppAuthClient.prototype, - 'eligibleForEncryption' - ).mockReturnValue(true); - - const formattedAuthDefaults = { - key: 'value', - }; - - const appAuthClient = new AppAuthClient(); - appAuthClient.formattedAuthDefaults = formattedAuthDefaults; - appAuthClient.encryptData(); - - const expectedDecryptedValue = JSON.parse( - AES.decrypt( - appAuthClient.authDefaults, - appConfig.encryptionKey - ).toString(enc) - ); - - expect(formattedAuthDefaults).toStrictEqual(expectedDecryptedValue); - expect(appAuthClient.authDefaults).not.toStrictEqual( - formattedAuthDefaults - ); - }); - - it('should encrypt formattedAuthDefaults and remove formattedAuthDefaults', async () => { - vi.spyOn( - AppAuthClient.prototype, - 'eligibleForEncryption' - ).mockReturnValue(true); - - const formattedAuthDefaults = { - key: 'value', - }; - - const appAuthClient = new AppAuthClient(); - appAuthClient.formattedAuthDefaults = formattedAuthDefaults; - appAuthClient.encryptData(); - - expect(appAuthClient.formattedAuthDefaults).not.toBeDefined(); - }); - }); - - describe('decryptData', () => { - it('should return undefined if eligibleForDecryption is not true', () => { - vi.spyOn( - AppAuthClient.prototype, - 'eligibleForDecryption' - ).mockReturnValue(false); - - const appAuthClient = new AppAuthClient(); - - expect(appAuthClient.decryptData()).toBeUndefined(); - }); - - it('should decrypt authDefaults and set it to formattedAuthDefaults', async () => { - vi.spyOn( - AppAuthClient.prototype, - 'eligibleForDecryption' - ).mockReturnValue(true); - - const formattedAuthDefaults = { - key: 'value', - }; - - const authDefaults = AES.encrypt( - JSON.stringify(formattedAuthDefaults), - appConfig.encryptionKey - ).toString(); - - const appAuthClient = new AppAuthClient(); - appAuthClient.authDefaults = authDefaults; - appAuthClient.decryptData(); - - expect(appAuthClient.formattedAuthDefaults).toStrictEqual( - formattedAuthDefaults - ); - expect(appAuthClient.authDefaults).not.toStrictEqual( - formattedAuthDefaults - ); - }); - }); - - describe('eligibleForEncryption', () => { - it('should return true when formattedAuthDefaults property exists', async () => { - const appAuthClient = await createAppAuthClient(); - - expect(appAuthClient.eligibleForEncryption()).toBe(true); - }); - - it("should return false when formattedAuthDefaults property doesn't exist", async () => { - const appAuthClient = await createAppAuthClient(); - - delete appAuthClient.formattedAuthDefaults; - - expect(appAuthClient.eligibleForEncryption()).toBe(false); - }); - }); - - describe('eligibleForDecryption', () => { - it('should return true when authDefaults property exists', async () => { - const appAuthClient = await createAppAuthClient(); - - expect(appAuthClient.eligibleForDecryption()).toBe(true); - }); - - it("should return false when authDefaults property doesn't exist", async () => { - const appAuthClient = await createAppAuthClient(); - - delete appAuthClient.authDefaults; - - expect(appAuthClient.eligibleForDecryption()).toBe(false); - }); - }); - - it('$beforeInsert should call AppAuthClient.encryptData', async () => { - const appAuthClientBeforeInsertSpy = vi.spyOn( - AppAuthClient.prototype, - 'encryptData' - ); - - await createAppAuthClient(); - - expect(appAuthClientBeforeInsertSpy).toHaveBeenCalledOnce(); - }); - - it('$beforeUpdate should call AppAuthClient.encryptData', async () => { - const appAuthClient = await createAppAuthClient(); - - const appAuthClientBeforeUpdateSpy = vi.spyOn( - AppAuthClient.prototype, - 'encryptData' - ); - - await appAuthClient.$query().patchAndFetch({ name: 'sample' }); - - expect(appAuthClientBeforeUpdateSpy).toHaveBeenCalledOnce(); - }); - - it('$afterFind should call AppAuthClient.decryptData', async () => { - const appAuthClient = await createAppAuthClient(); - - const appAuthClientAfterFindSpy = vi.spyOn( - AppAuthClient.prototype, - 'decryptData' - ); - - await appAuthClient.$query(); - - expect(appAuthClientAfterFindSpy).toHaveBeenCalledOnce(); - }); -}); diff --git a/packages/backend/src/models/app-config.js b/packages/backend/src/models/app-config.js index 6763e9f8..fe7e2d44 100644 --- a/packages/backend/src/models/app-config.js +++ b/packages/backend/src/models/app-config.js @@ -1,5 +1,5 @@ import App from './app.js'; -import AppAuthClient from './app-auth-client.js'; +import OAuthClient from './oauth-client.js'; import Base from './base.js'; class AppConfig extends Base { @@ -24,12 +24,12 @@ class AppConfig extends Base { }; static relationMappings = () => ({ - appAuthClients: { + oauthClients: { relation: Base.HasManyRelation, - modelClass: AppAuthClient, + modelClass: OAuthClient, join: { from: 'app_configs.key', - to: 'app_auth_clients.app_key', + to: 'oauth_clients.app_key', }, }, }); diff --git a/packages/backend/src/models/app-config.test.js b/packages/backend/src/models/app-config.test.js index 2e6f05be..a68b393f 100644 --- a/packages/backend/src/models/app-config.test.js +++ b/packages/backend/src/models/app-config.test.js @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest'; import Base from './base.js'; import AppConfig from './app-config.js'; import App from './app.js'; -import AppAuthClient from './app-auth-client.js'; +import OAuthClient from './oauth-client.js'; describe('AppConfig model', () => { it('tableName should return correct name', () => { @@ -22,12 +22,12 @@ describe('AppConfig model', () => { const relationMappings = AppConfig.relationMappings(); const expectedRelations = { - appAuthClients: { + oauthClients: { relation: Base.HasManyRelation, - modelClass: AppAuthClient, + modelClass: OAuthClient, join: { from: 'app_configs.key', - to: 'app_auth_clients.app_key', + to: 'oauth_clients.app_key', }, }, }; diff --git a/packages/backend/src/models/connection.js b/packages/backend/src/models/connection.js index 4a8d5351..5b4c7c66 100644 --- a/packages/backend/src/models/connection.js +++ b/packages/backend/src/models/connection.js @@ -2,7 +2,7 @@ import AES from 'crypto-js/aes.js'; import enc from 'crypto-js/enc-utf8.js'; import App from './app.js'; import AppConfig from './app-config.js'; -import AppAuthClient from './app-auth-client.js'; +import OAuthClient from './oauth-client.js'; import Base from './base.js'; import User from './user.js'; import Step from './step.js'; @@ -24,7 +24,7 @@ class Connection extends Base { data: { type: 'string' }, formattedData: { type: 'object' }, userId: { type: 'string', format: 'uuid' }, - appAuthClientId: { type: 'string', format: 'uuid' }, + oauthClientId: { type: 'string', format: 'uuid' }, verified: { type: 'boolean', default: false }, draft: { type: 'boolean' }, deletedAt: { type: 'string' }, @@ -69,12 +69,12 @@ class Connection extends Base { to: 'app_configs.key', }, }, - appAuthClient: { + oauthClient: { relation: Base.BelongsToOneRelation, - modelClass: AppAuthClient, + modelClass: OAuthClient, join: { - from: 'connections.app_auth_client_id', - to: 'app_auth_clients.id', + from: 'connections.oauth_client_id', + to: 'oauth_clients.id', }, }, }); @@ -136,8 +136,8 @@ class Connection extends Base { if (!this.formattedData) { const authClient = await appConfig - .$relatedQuery('appAuthClients') - .findById(this.appAuthClientId) + .$relatedQuery('oauthClients') + .findById(this.oauthClientId) .where({ active: true }) .throwIfNotFound(); @@ -215,13 +215,13 @@ class Connection extends Base { return updatedConnection; } - async updateFormattedData({ formattedData, appAuthClientId }) { - if (appAuthClientId) { - const appAuthClient = await AppAuthClient.query() - .findById(appAuthClientId) + async updateFormattedData({ formattedData, oauthClientId }) { + if (oauthClientId) { + const oauthClient = await OAuthClient.query() + .findById(oauthClientId) .throwIfNotFound(); - formattedData = appAuthClient.formattedAuthDefaults; + formattedData = oauthClient.formattedAuthDefaults; } return await this.$query().patchAndFetch({ diff --git a/packages/backend/src/models/connection.test.js b/packages/backend/src/models/connection.test.js index 329fdfe6..58410eef 100644 --- a/packages/backend/src/models/connection.test.js +++ b/packages/backend/src/models/connection.test.js @@ -2,7 +2,7 @@ import { describe, it, expect, vi } from 'vitest'; import AES from 'crypto-js/aes.js'; import enc from 'crypto-js/enc-utf8.js'; import appConfig from '../config/app.js'; -import AppAuthClient from './app-auth-client.js'; +import OAuthClient from './oauth-client.js'; import App from './app.js'; import AppConfig from './app-config.js'; import Base from './base.js'; @@ -12,7 +12,7 @@ import User from './user.js'; import Telemetry from '../helpers/telemetry/index.js'; import { createConnection } from '../../test/factories/connection.js'; import { createAppConfig } from '../../test/factories/app-config.js'; -import { createAppAuthClient } from '../../test/factories/app-auth-client.js'; +import { createOAuthClient } from '../../test/factories/oauth-client.js'; describe('Connection model', () => { it('tableName should return correct name', () => { @@ -61,12 +61,12 @@ describe('Connection model', () => { to: 'app_configs.key', }, }, - appAuthClient: { + oauthClient: { relation: Base.BelongsToOneRelation, - modelClass: AppAuthClient, + modelClass: OAuthClient, join: { - from: 'connections.app_auth_client_id', - to: 'app_auth_clients.id', + from: 'connections.oauth_client_id', + to: 'oauth_clients.id', }, }, }; @@ -307,13 +307,13 @@ describe('Connection model', () => { ); }); - it('should apply app auth client auth defaults when creating with shared app auth client', async () => { + it('should apply oauth client auth defaults when creating with shared oauth client', async () => { await createAppConfig({ key: 'gitlab', disabled: false, }); - const appAuthClient = await createAppAuthClient({ + const oauthClient = await createOAuthClient({ appKey: 'gitlab', active: true, formattedAuthDefaults: { @@ -323,7 +323,7 @@ describe('Connection model', () => { const connection = await createConnection({ key: 'gitlab', - appAuthClientId: appAuthClient.id, + oauthClientId: oauthClient.id, formattedData: null, }); @@ -559,22 +559,22 @@ describe('Connection model', () => { }); describe('updateFormattedData', () => { - it('should extend connection data with app auth client auth defaults', async () => { - const appAuthClient = await createAppAuthClient({ + it('should extend connection data with oauth client auth defaults', async () => { + const oauthClient = await createOAuthClient({ formattedAuthDefaults: { clientId: 'sample-id', }, }); const connection = await createConnection({ - appAuthClientId: appAuthClient.id, + oauthClientId: oauthClient.id, formattedData: { token: 'sample-token', }, }); const updatedConnection = await connection.updateFormattedData({ - appAuthClientId: appAuthClient.id, + oauthClientId: oauthClient.id, }); expect(updatedConnection.formattedData).toStrictEqual({ diff --git a/packages/backend/src/models/app-auth-client.js b/packages/backend/src/models/oauth-client.js similarity index 93% rename from packages/backend/src/models/app-auth-client.js rename to packages/backend/src/models/oauth-client.js index 48800841..d4c253a4 100644 --- a/packages/backend/src/models/app-auth-client.js +++ b/packages/backend/src/models/oauth-client.js @@ -4,8 +4,8 @@ import appConfig from '../config/app.js'; import Base from './base.js'; import AppConfig from './app-config.js'; -class AppAuthClient extends Base { - static tableName = 'app_auth_clients'; +class OAuthClient extends Base { + static tableName = 'oauth_clients'; static jsonSchema = { type: 'object', @@ -27,7 +27,7 @@ class AppAuthClient extends Base { relation: Base.BelongsToOneRelation, modelClass: AppConfig, join: { - from: 'app_auth_clients.app_key', + from: 'oauth_clients.app_key', to: 'app_configs.key', }, }, @@ -87,4 +87,4 @@ class AppAuthClient extends Base { } } -export default AppAuthClient; +export default OAuthClient; diff --git a/packages/backend/src/models/oauth-client.test.js b/packages/backend/src/models/oauth-client.test.js new file mode 100644 index 00000000..e1d17154 --- /dev/null +++ b/packages/backend/src/models/oauth-client.test.js @@ -0,0 +1,192 @@ +import { describe, it, expect, vi } from 'vitest'; +import AES from 'crypto-js/aes.js'; +import enc from 'crypto-js/enc-utf8.js'; + +import AppConfig from './app-config.js'; +import OAuthClient from './oauth-client.js'; +import Base from './base.js'; +import appConfig from '../config/app.js'; +import { createOAuthClient } from '../../test/factories/oauth-client.js'; + +describe('OAuthClient model', () => { + it('tableName should return correct name', () => { + expect(OAuthClient.tableName).toBe('oauth_clients'); + }); + + it('jsonSchema should have correct validations', () => { + expect(OAuthClient.jsonSchema).toMatchSnapshot(); + }); + + it('relationMappings should return correct associations', () => { + const relationMappings = OAuthClient.relationMappings(); + + const expectedRelations = { + appConfig: { + relation: Base.BelongsToOneRelation, + modelClass: AppConfig, + join: { + from: 'oauth_clients.app_key', + to: 'app_configs.key', + }, + }, + }; + + expect(relationMappings).toStrictEqual(expectedRelations); + }); + + describe('encryptData', () => { + it('should return undefined if eligibleForEncryption is not true', async () => { + vi.spyOn(OAuthClient.prototype, 'eligibleForEncryption').mockReturnValue( + false + ); + + const oauthClient = new OAuthClient(); + + expect(oauthClient.encryptData()).toBeUndefined(); + }); + + it('should encrypt formattedAuthDefaults and set it to authDefaults', async () => { + vi.spyOn(OAuthClient.prototype, 'eligibleForEncryption').mockReturnValue( + true + ); + + const formattedAuthDefaults = { + key: 'value', + }; + + const oauthClient = new OAuthClient(); + oauthClient.formattedAuthDefaults = formattedAuthDefaults; + oauthClient.encryptData(); + + const expectedDecryptedValue = JSON.parse( + AES.decrypt(oauthClient.authDefaults, appConfig.encryptionKey).toString( + enc + ) + ); + + expect(formattedAuthDefaults).toStrictEqual(expectedDecryptedValue); + expect(oauthClient.authDefaults).not.toStrictEqual(formattedAuthDefaults); + }); + + it('should encrypt formattedAuthDefaults and remove formattedAuthDefaults', async () => { + vi.spyOn(OAuthClient.prototype, 'eligibleForEncryption').mockReturnValue( + true + ); + + const formattedAuthDefaults = { + key: 'value', + }; + + const oauthClient = new OAuthClient(); + oauthClient.formattedAuthDefaults = formattedAuthDefaults; + oauthClient.encryptData(); + + expect(oauthClient.formattedAuthDefaults).not.toBeDefined(); + }); + }); + + describe('decryptData', () => { + it('should return undefined if eligibleForDecryption is not true', () => { + vi.spyOn(OAuthClient.prototype, 'eligibleForDecryption').mockReturnValue( + false + ); + + const oauthClient = new OAuthClient(); + + expect(oauthClient.decryptData()).toBeUndefined(); + }); + + it('should decrypt authDefaults and set it to formattedAuthDefaults', async () => { + vi.spyOn(OAuthClient.prototype, 'eligibleForDecryption').mockReturnValue( + true + ); + + const formattedAuthDefaults = { + key: 'value', + }; + + const authDefaults = AES.encrypt( + JSON.stringify(formattedAuthDefaults), + appConfig.encryptionKey + ).toString(); + + const oauthClient = new OAuthClient(); + oauthClient.authDefaults = authDefaults; + oauthClient.decryptData(); + + expect(oauthClient.formattedAuthDefaults).toStrictEqual( + formattedAuthDefaults + ); + expect(oauthClient.authDefaults).not.toStrictEqual(formattedAuthDefaults); + }); + }); + + describe('eligibleForEncryption', () => { + it('should return true when formattedAuthDefaults property exists', async () => { + const oauthClient = await createOAuthClient(); + + expect(oauthClient.eligibleForEncryption()).toBe(true); + }); + + it("should return false when formattedAuthDefaults property doesn't exist", async () => { + const oauthClient = await createOAuthClient(); + + delete oauthClient.formattedAuthDefaults; + + expect(oauthClient.eligibleForEncryption()).toBe(false); + }); + }); + + describe('eligibleForDecryption', () => { + it('should return true when authDefaults property exists', async () => { + const oauthClient = await createOAuthClient(); + + expect(oauthClient.eligibleForDecryption()).toBe(true); + }); + + it("should return false when authDefaults property doesn't exist", async () => { + const oauthClient = await createOAuthClient(); + + delete oauthClient.authDefaults; + + expect(oauthClient.eligibleForDecryption()).toBe(false); + }); + }); + + it('$beforeInsert should call OAuthClient.encryptData', async () => { + const oauthClientBeforeInsertSpy = vi.spyOn( + OAuthClient.prototype, + 'encryptData' + ); + + await createOAuthClient(); + + expect(oauthClientBeforeInsertSpy).toHaveBeenCalledOnce(); + }); + + it('$beforeUpdate should call OAuthClient.encryptData', async () => { + const oauthClient = await createOAuthClient(); + + const oauthClientBeforeUpdateSpy = vi.spyOn( + OAuthClient.prototype, + 'encryptData' + ); + + await oauthClient.$query().patchAndFetch({ name: 'sample' }); + + expect(oauthClientBeforeUpdateSpy).toHaveBeenCalledOnce(); + }); + + it('$afterFind should call OAuthClient.decryptData', async () => { + const oauthClient = await createOAuthClient(); + + const oauthClientAfterFindSpy = vi.spyOn( + OAuthClient.prototype, + 'decryptData' + ); + + await oauthClient.$query(); + + expect(oauthClientAfterFindSpy).toHaveBeenCalledOnce(); + }); +}); diff --git a/packages/backend/src/routes/api/v1/admin/apps.ee.js b/packages/backend/src/routes/api/v1/admin/apps.ee.js index c476d2ff..6a0eb9a6 100644 --- a/packages/backend/src/routes/api/v1/admin/apps.ee.js +++ b/packages/backend/src/routes/api/v1/admin/apps.ee.js @@ -4,10 +4,10 @@ import { authorizeAdmin } from '../../../../helpers/authorization.js'; import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js'; import createConfigAction from '../../../../controllers/api/v1/admin/apps/create-config.ee.js'; import updateConfigAction from '../../../../controllers/api/v1/admin/apps/update-config.ee.js'; -import getAuthClientsAction from '../../../../controllers/api/v1/admin/apps/get-auth-clients.ee.js'; -import getAuthClientAction from '../../../../controllers/api/v1/admin/apps/get-auth-client.ee.js'; -import createAuthClientAction from '../../../../controllers/api/v1/admin/apps/create-auth-client.ee.js'; -import updateAuthClientAction from '../../../../controllers/api/v1/admin/apps/update-auth-client.ee.js'; +import getOAuthClientsAction from '../../../../controllers/api/v1/admin/apps/get-oauth-clients.ee.js'; +import getOAuthClientAction from '../../../../controllers/api/v1/admin/apps/get-oauth-client.ee.js'; +import createOAuthClientAction from '../../../../controllers/api/v1/admin/apps/create-oauth-client.ee.js'; +import updateOAuthClientAction from '../../../../controllers/api/v1/admin/apps/update-oauth-client.ee.js'; const router = Router(); @@ -28,35 +28,35 @@ router.patch( ); router.get( - '/:appKey/auth-clients', + '/:appKey/oauth-clients', authenticateUser, authorizeAdmin, checkIsEnterprise, - getAuthClientsAction + getOAuthClientsAction ); router.post( - '/:appKey/auth-clients', + '/:appKey/oauth-clients', authenticateUser, authorizeAdmin, checkIsEnterprise, - createAuthClientAction + createOAuthClientAction ); router.get( - '/:appKey/auth-clients/:appAuthClientId', + '/:appKey/oauth-clients/:oauthClientId', authenticateUser, authorizeAdmin, checkIsEnterprise, - getAuthClientAction + getOAuthClientAction ); router.patch( - '/:appKey/auth-clients/:appAuthClientId', + '/:appKey/oauth-clients/:oauthClientId', authenticateUser, authorizeAdmin, checkIsEnterprise, - updateAuthClientAction + updateOAuthClientAction ); export default router; diff --git a/packages/backend/src/routes/api/v1/apps.js b/packages/backend/src/routes/api/v1/apps.js index 5bdc27f1..c92fc552 100644 --- a/packages/backend/src/routes/api/v1/apps.js +++ b/packages/backend/src/routes/api/v1/apps.js @@ -7,8 +7,8 @@ import getAppsAction from '../../../controllers/api/v1/apps/get-apps.js'; import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js'; import getConnectionsAction from '../../../controllers/api/v1/apps/get-connections.js'; import getConfigAction from '../../../controllers/api/v1/apps/get-config.ee.js'; -import getAuthClientsAction from '../../../controllers/api/v1/apps/get-auth-clients.ee.js'; -import getAuthClientAction from '../../../controllers/api/v1/apps/get-auth-client.ee.js'; +import getOAuthClientsAction from '../../../controllers/api/v1/apps/get-oauth-clients.ee.js'; +import getOAuthClientAction from '../../../controllers/api/v1/apps/get-oauth-client.ee.js'; import getTriggersAction from '../../../controllers/api/v1/apps/get-triggers.js'; import getTriggerSubstepsAction from '../../../controllers/api/v1/apps/get-trigger-substeps.js'; import getActionsAction from '../../../controllers/api/v1/apps/get-actions.js'; @@ -44,17 +44,17 @@ router.get( ); router.get( - '/:appKey/auth-clients', + '/:appKey/oauth-clients', authenticateUser, checkIsEnterprise, - getAuthClientsAction + getOAuthClientsAction ); router.get( - '/:appKey/auth-clients/:appAuthClientId', + '/:appKey/oauth-clients/:oauthClientId', authenticateUser, checkIsEnterprise, - getAuthClientAction + getOAuthClientAction ); router.get('/:appKey/triggers', authenticateUser, getTriggersAction); diff --git a/packages/backend/src/serializers/app-auth-client.js b/packages/backend/src/serializers/app-auth-client.js deleted file mode 100644 index 88af3dab..00000000 --- a/packages/backend/src/serializers/app-auth-client.js +++ /dev/null @@ -1,10 +0,0 @@ -const appAuthClientSerializer = (appAuthClient) => { - return { - id: appAuthClient.id, - appConfigId: appAuthClient.appConfigId, - name: appAuthClient.name, - active: appAuthClient.active, - }; -}; - -export default appAuthClientSerializer; diff --git a/packages/backend/src/serializers/app-auth-client.test.js b/packages/backend/src/serializers/app-auth-client.test.js deleted file mode 100644 index d4ed178e..00000000 --- a/packages/backend/src/serializers/app-auth-client.test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { describe, it, expect, beforeEach } from 'vitest'; -import { createAppAuthClient } from '../../test/factories/app-auth-client'; -import appAuthClientSerializer from './app-auth-client'; - -describe('appAuthClient serializer', () => { - let appAuthClient; - - beforeEach(async () => { - appAuthClient = await createAppAuthClient(); - }); - - it('should return app auth client data', async () => { - const expectedPayload = { - id: appAuthClient.id, - appConfigId: appAuthClient.appConfigId, - name: appAuthClient.name, - active: appAuthClient.active, - }; - - expect(appAuthClientSerializer(appAuthClient)).toStrictEqual( - expectedPayload - ); - }); -}); diff --git a/packages/backend/src/serializers/connection.js b/packages/backend/src/serializers/connection.js index 388a6b87..70224476 100644 --- a/packages/backend/src/serializers/connection.js +++ b/packages/backend/src/serializers/connection.js @@ -2,7 +2,7 @@ const connectionSerializer = (connection) => { return { id: connection.id, key: connection.key, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: { screenName: connection.formattedData.screenName, }, diff --git a/packages/backend/src/serializers/connection.test.js b/packages/backend/src/serializers/connection.test.js index 3ea7b324..bb9db58a 100644 --- a/packages/backend/src/serializers/connection.test.js +++ b/packages/backend/src/serializers/connection.test.js @@ -13,7 +13,7 @@ describe('connectionSerializer', () => { const expectedPayload = { id: connection.id, key: connection.key, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: { screenName: connection.formattedData.screenName, }, diff --git a/packages/backend/src/serializers/index.js b/packages/backend/src/serializers/index.js index 3111b2df..4525b5ae 100644 --- a/packages/backend/src/serializers/index.js +++ b/packages/backend/src/serializers/index.js @@ -4,7 +4,7 @@ import permissionSerializer from './permission.js'; import adminSamlAuthProviderSerializer from './admin-saml-auth-provider.ee.js'; import samlAuthProviderSerializer from './saml-auth-provider.ee.js'; import samlAuthProviderRoleMappingSerializer from './role-mapping.ee.js'; -import appAuthClientSerializer from './app-auth-client.js'; +import oauthClientSerializer from './oauth-client.js'; import appConfigSerializer from './app-config.js'; import flowSerializer from './flow.js'; import stepSerializer from './step.js'; @@ -28,7 +28,7 @@ const serializers = { AdminSamlAuthProvider: adminSamlAuthProviderSerializer, SamlAuthProvider: samlAuthProviderSerializer, RoleMapping: samlAuthProviderRoleMappingSerializer, - AppAuthClient: appAuthClientSerializer, + OAuthClient: oauthClientSerializer, AppConfig: appConfigSerializer, Flow: flowSerializer, Step: stepSerializer, diff --git a/packages/backend/src/serializers/oauth-client.js b/packages/backend/src/serializers/oauth-client.js new file mode 100644 index 00000000..bacebafc --- /dev/null +++ b/packages/backend/src/serializers/oauth-client.js @@ -0,0 +1,10 @@ +const oauthClientSerializer = (oauthClient) => { + return { + id: oauthClient.id, + appConfigId: oauthClient.appConfigId, + name: oauthClient.name, + active: oauthClient.active, + }; +}; + +export default oauthClientSerializer; diff --git a/packages/backend/src/serializers/oauth-client.test.js b/packages/backend/src/serializers/oauth-client.test.js new file mode 100644 index 00000000..d5ab8d70 --- /dev/null +++ b/packages/backend/src/serializers/oauth-client.test.js @@ -0,0 +1,22 @@ +import { describe, it, expect, beforeEach } from 'vitest'; +import { createOAuthClient } from '../../test/factories/oauth-client'; +import oauthClientSerializer from './oauth-client'; + +describe('oauthClient serializer', () => { + let oauthClient; + + beforeEach(async () => { + oauthClient = await createOAuthClient(); + }); + + it('should return oauth client data', async () => { + const expectedPayload = { + id: oauthClient.id, + appConfigId: oauthClient.appConfigId, + name: oauthClient.name, + active: oauthClient.active, + }; + + expect(oauthClientSerializer(oauthClient)).toStrictEqual(expectedPayload); + }); +}); diff --git a/packages/backend/test/factories/app-auth-client.js b/packages/backend/test/factories/oauth-client.js similarity index 67% rename from packages/backend/test/factories/app-auth-client.js rename to packages/backend/test/factories/oauth-client.js index 831d4c14..0b0f6b9b 100644 --- a/packages/backend/test/factories/app-auth-client.js +++ b/packages/backend/test/factories/oauth-client.js @@ -1,5 +1,5 @@ import { faker } from '@faker-js/faker'; -import AppAuthClient from '../../src/models/app-auth-client'; +import OAuthClient from '../../src/models/oauth-client'; const formattedAuthDefaults = { oAuthRedirectUrl: faker.internet.url(), @@ -8,14 +8,14 @@ const formattedAuthDefaults = { clientSecret: faker.string.uuid(), }; -export const createAppAuthClient = async (params = {}) => { +export const createOAuthClient = async (params = {}) => { params.name = params?.name || faker.person.fullName(); params.appKey = params?.appKey || 'deepl'; params.active = params?.active ?? true; params.formattedAuthDefaults = params?.formattedAuthDefaults || formattedAuthDefaults; - const appAuthClient = await AppAuthClient.query().insertAndFetch(params); + const oauthClient = await OAuthClient.query().insertAndFetch(params); - return appAuthClient; + return oauthClient; }; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/create-auth-client.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/create-auth-client.js deleted file mode 100644 index f91c8500..00000000 --- a/packages/backend/test/mocks/rest/api/v1/admin/apps/create-auth-client.js +++ /dev/null @@ -1,17 +0,0 @@ -const createAppAuthClientMock = (appAuthClient) => { - return { - data: { - name: appAuthClient.name, - active: appAuthClient.active, - }, - meta: { - count: 1, - currentPage: null, - isArray: false, - totalPages: null, - type: 'AppAuthClient', - }, - }; -}; - -export default createAppAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/create-oauth-client.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/create-oauth-client.js new file mode 100644 index 00000000..10e4e9b7 --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/admin/apps/create-oauth-client.js @@ -0,0 +1,17 @@ +const createOAuthClientMock = (oauthClient) => { + return { + data: { + name: oauthClient.name, + active: oauthClient.active, + }, + meta: { + count: 1, + currentPage: null, + isArray: false, + totalPages: null, + type: 'OAuthClient', + }, + }; +}; + +export default createOAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/get-auth-client.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/get-auth-client.js deleted file mode 100644 index 4d437eca..00000000 --- a/packages/backend/test/mocks/rest/api/v1/admin/apps/get-auth-client.js +++ /dev/null @@ -1,18 +0,0 @@ -const getAppAuthClientMock = (appAuthClient) => { - return { - data: { - name: appAuthClient.name, - id: appAuthClient.id, - active: appAuthClient.active, - }, - meta: { - count: 1, - currentPage: null, - isArray: false, - totalPages: null, - type: 'AppAuthClient', - }, - }; -}; - -export default getAppAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/get-auth-clients.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/get-auth-clients.js deleted file mode 100644 index dd0cc5ee..00000000 --- a/packages/backend/test/mocks/rest/api/v1/admin/apps/get-auth-clients.js +++ /dev/null @@ -1,18 +0,0 @@ -const getAdminAppAuthClientsMock = (appAuthClients) => { - return { - data: appAuthClients.map((appAuthClient) => ({ - name: appAuthClient.name, - id: appAuthClient.id, - active: appAuthClient.active, - })), - meta: { - count: appAuthClients.length, - currentPage: null, - isArray: true, - totalPages: null, - type: 'AppAuthClient', - }, - }; -}; - -export default getAdminAppAuthClientsMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/get-oauth-client.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/get-oauth-client.js new file mode 100644 index 00000000..1431b968 --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/admin/apps/get-oauth-client.js @@ -0,0 +1,18 @@ +const getOAuthClientMock = (oauthClient) => { + return { + data: { + name: oauthClient.name, + id: oauthClient.id, + active: oauthClient.active, + }, + meta: { + count: 1, + currentPage: null, + isArray: false, + totalPages: null, + type: 'OAuthClient', + }, + }; +}; + +export default getOAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/get-oauth-clients.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/get-oauth-clients.js new file mode 100644 index 00000000..c0bd5d54 --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/admin/apps/get-oauth-clients.js @@ -0,0 +1,18 @@ +const getAdminOAuthClientsMock = (oauthClients) => { + return { + data: oauthClients.map((oauthClient) => ({ + name: oauthClient.name, + id: oauthClient.id, + active: oauthClient.active, + })), + meta: { + count: oauthClients.length, + currentPage: null, + isArray: true, + totalPages: null, + type: 'OAuthClient', + }, + }; +}; + +export default getAdminOAuthClientsMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/update-auth-client.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/update-auth-client.js deleted file mode 100644 index 9d4dea24..00000000 --- a/packages/backend/test/mocks/rest/api/v1/admin/apps/update-auth-client.js +++ /dev/null @@ -1,18 +0,0 @@ -const updateAppAuthClientMock = (appAuthClient) => { - return { - data: { - id: appAuthClient.id, - name: appAuthClient.name, - active: appAuthClient.active, - }, - meta: { - count: 1, - currentPage: null, - isArray: false, - totalPages: null, - type: 'AppAuthClient', - }, - }; -}; - -export default updateAppAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/admin/apps/update-oauth-client.js b/packages/backend/test/mocks/rest/api/v1/admin/apps/update-oauth-client.js new file mode 100644 index 00000000..bdb5294d --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/admin/apps/update-oauth-client.js @@ -0,0 +1,18 @@ +const updateOAuthClientMock = (oauthClient) => { + return { + data: { + id: oauthClient.id, + name: oauthClient.name, + active: oauthClient.active, + }, + meta: { + count: 1, + currentPage: null, + isArray: false, + totalPages: null, + type: 'OAuthClient', + }, + }; +}; + +export default updateOAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/apps/create-connection.js b/packages/backend/test/mocks/rest/api/v1/apps/create-connection.js index 2eb1fd7f..ccbeba23 100644 --- a/packages/backend/test/mocks/rest/api/v1/apps/create-connection.js +++ b/packages/backend/test/mocks/rest/api/v1/apps/create-connection.js @@ -2,7 +2,7 @@ const createConnection = (connection) => { const connectionData = { id: connection.id, key: connection.key, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: connection.formattedData, verified: connection.verified || false, createdAt: connection.createdAt.getTime(), diff --git a/packages/backend/test/mocks/rest/api/v1/apps/get-auth-client.js b/packages/backend/test/mocks/rest/api/v1/apps/get-auth-client.js deleted file mode 100644 index 4d437eca..00000000 --- a/packages/backend/test/mocks/rest/api/v1/apps/get-auth-client.js +++ /dev/null @@ -1,18 +0,0 @@ -const getAppAuthClientMock = (appAuthClient) => { - return { - data: { - name: appAuthClient.name, - id: appAuthClient.id, - active: appAuthClient.active, - }, - meta: { - count: 1, - currentPage: null, - isArray: false, - totalPages: null, - type: 'AppAuthClient', - }, - }; -}; - -export default getAppAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/apps/get-auth-clients.js b/packages/backend/test/mocks/rest/api/v1/apps/get-auth-clients.js deleted file mode 100644 index 0a697dec..00000000 --- a/packages/backend/test/mocks/rest/api/v1/apps/get-auth-clients.js +++ /dev/null @@ -1,18 +0,0 @@ -const getAppAuthClientsMock = (appAuthClients) => { - return { - data: appAuthClients.map((appAuthClient) => ({ - name: appAuthClient.name, - id: appAuthClient.id, - active: appAuthClient.active, - })), - meta: { - count: appAuthClients.length, - currentPage: null, - isArray: true, - totalPages: null, - type: 'AppAuthClient', - }, - }; -}; - -export default getAppAuthClientsMock; diff --git a/packages/backend/test/mocks/rest/api/v1/apps/get-connections.js b/packages/backend/test/mocks/rest/api/v1/apps/get-connections.js index bd3bfa4c..d7b9f0e9 100644 --- a/packages/backend/test/mocks/rest/api/v1/apps/get-connections.js +++ b/packages/backend/test/mocks/rest/api/v1/apps/get-connections.js @@ -4,7 +4,7 @@ const getConnectionsMock = (connections) => { id: connection.id, key: connection.key, verified: connection.verified, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: { screenName: connection.formattedData.screenName, }, diff --git a/packages/backend/test/mocks/rest/api/v1/apps/get-oauth-client.js b/packages/backend/test/mocks/rest/api/v1/apps/get-oauth-client.js new file mode 100644 index 00000000..1431b968 --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/apps/get-oauth-client.js @@ -0,0 +1,18 @@ +const getOAuthClientMock = (oauthClient) => { + return { + data: { + name: oauthClient.name, + id: oauthClient.id, + active: oauthClient.active, + }, + meta: { + count: 1, + currentPage: null, + isArray: false, + totalPages: null, + type: 'OAuthClient', + }, + }; +}; + +export default getOAuthClientMock; diff --git a/packages/backend/test/mocks/rest/api/v1/apps/get-oauth-clients.js b/packages/backend/test/mocks/rest/api/v1/apps/get-oauth-clients.js new file mode 100644 index 00000000..549544b0 --- /dev/null +++ b/packages/backend/test/mocks/rest/api/v1/apps/get-oauth-clients.js @@ -0,0 +1,18 @@ +const getOAuthClientsMock = (oauthClients) => { + return { + data: oauthClients.map((oauthClient) => ({ + name: oauthClient.name, + id: oauthClient.id, + active: oauthClient.active, + })), + meta: { + count: oauthClients.length, + currentPage: null, + isArray: true, + totalPages: null, + type: 'OAuthClient', + }, + }; +}; + +export default getOAuthClientsMock; diff --git a/packages/backend/test/mocks/rest/api/v1/connections/reset-connection.js b/packages/backend/test/mocks/rest/api/v1/connections/reset-connection.js index 0d8131c8..f618a641 100644 --- a/packages/backend/test/mocks/rest/api/v1/connections/reset-connection.js +++ b/packages/backend/test/mocks/rest/api/v1/connections/reset-connection.js @@ -3,7 +3,7 @@ const resetConnectionMock = (connection) => { id: connection.id, key: connection.key, verified: connection.verified, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: { screenName: connection.formattedData.screenName, }, diff --git a/packages/backend/test/mocks/rest/api/v1/connections/update-connection.js b/packages/backend/test/mocks/rest/api/v1/connections/update-connection.js index d46b9a0c..306f7726 100644 --- a/packages/backend/test/mocks/rest/api/v1/connections/update-connection.js +++ b/packages/backend/test/mocks/rest/api/v1/connections/update-connection.js @@ -3,7 +3,7 @@ const updateConnectionMock = (connection) => { id: connection.id, key: connection.key, verified: connection.verified, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: { screenName: connection.formattedData.screenName, }, diff --git a/packages/backend/test/mocks/rest/api/v1/steps/get-connection.js b/packages/backend/test/mocks/rest/api/v1/steps/get-connection.js index 831a148a..18731302 100644 --- a/packages/backend/test/mocks/rest/api/v1/steps/get-connection.js +++ b/packages/backend/test/mocks/rest/api/v1/steps/get-connection.js @@ -3,7 +3,7 @@ const getConnectionMock = async (connection) => { id: connection.id, key: connection.key, verified: connection.verified, - appAuthClientId: connection.appAuthClientId, + oauthClientId: connection.oauthClientId, formattedData: { screenName: connection.formattedData.screenName, }, diff --git a/packages/e2e-tests/tests/admin/applications.spec.js b/packages/e2e-tests/tests/admin/applications.spec.js index 847adc41..d5bfb4ba 100644 --- a/packages/e2e-tests/tests/admin/applications.spec.js +++ b/packages/e2e-tests/tests/admin/applications.spec.js @@ -4,8 +4,8 @@ const { insertAppConnection } = require('../../helpers/db-helpers'); test.describe('Admin Applications', () => { test.beforeAll(async () => { - const deleteAppAuthClients = { - text: 'DELETE FROM app_auth_clients WHERE app_key in ($1, $2, $3, $4, $5, $6)', + const deleteOAuthClients = { + text: 'DELETE FROM oauth_clients WHERE app_key in ($1, $2, $3, $4, $5, $6)', values: [ 'carbone', 'spotify', @@ -29,10 +29,8 @@ test.describe('Admin Applications', () => { }; try { - const deleteAppAuthClientsResult = await pgPool.query( - deleteAppAuthClients - ); - expect(deleteAppAuthClientsResult.command).toBe('DELETE'); + const deleteOAuthClientsResult = await pgPool.query(deleteOAuthClients); + expect(deleteOAuthClientsResult.command).toBe('DELETE'); const deleteAppConfigsResult = await pgPool.query(deleteAppConfigs); expect(deleteAppConfigsResult.command).toBe('DELETE'); } catch (err) {