Merge pull request #1773 from automatisch/rest-admin-get-app-auth-clients
feat: Implement new admin get auth clients API endpoint
This commit is contained in:
@@ -1,41 +0,0 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
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 getAdminAppAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/app-auth-clients/get-app-auth-clients.js';
|
|
||||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
|
||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/app-auth-clients', () => {
|
|
||||||
let currentUser, currentUserRole, token;
|
|
||||||
|
|
||||||
describe('with valid license key', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return app auth clients', async () => {
|
|
||||||
const appAuthClientOne = await createAppAuthClient();
|
|
||||||
const appAuthClientTwo = await createAppAuthClient();
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/admin/app-auth-clients')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getAdminAppAuthClientsMock([
|
|
||||||
appAuthClientTwo,
|
|
||||||
appAuthClientOne,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -2,10 +2,9 @@ import { renderObject } from '../../../../../helpers/renderer.js';
|
|||||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClients = await AppAuthClient.query().orderBy(
|
const appAuthClients = await AppAuthClient.query()
|
||||||
'created_at',
|
.where({ app_key: request.params.appKey })
|
||||||
'desc'
|
.orderBy('created_at', 'desc');
|
||||||
);
|
|
||||||
|
|
||||||
renderObject(response, appAuthClients);
|
renderObject(response, appAuthClients);
|
||||||
};
|
};
|
@@ -0,0 +1,44 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
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 { 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 * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||||
|
let currentUser, adminRole, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
adminRole = await createRole({ key: 'admin' });
|
||||||
|
currentUser = await createUser({ roleId: adminRole.id });
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified app auth client info', async () => {
|
||||||
|
const appAuthClientOne = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const appAuthClientTwo = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/v1/admin/apps/deepl/auth-clients')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getAuthClientsMock([
|
||||||
|
appAuthClientTwo,
|
||||||
|
appAuthClientOne,
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -7,7 +7,7 @@ import getAuthClientsMock from '../../../../../test/mocks/rest/api/v1/apps/get-a
|
|||||||
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/app/:appKey/auth-clients', () => {
|
describe('GET /api/v1/apps/:appKey/auth-clients', () => {
|
||||||
let currentUser, token;
|
let currentUser, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@@ -3,19 +3,10 @@ import asyncHandler from 'express-async-handler';
|
|||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
import { authenticateUser } from '../../../../helpers/authentication.js';
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
||||||
import getAdminAppAuthClientsAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-clients.ee.js';
|
|
||||||
import getAdminAppAuthClientAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-client.ee.js';
|
import getAdminAppAuthClientAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-client.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
authenticateUser,
|
|
||||||
authorizeAdmin,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAdminAppAuthClientsAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:appAuthClientId',
|
'/:appAuthClientId',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
|
27
packages/backend/src/routes/api/v1/admin/apps.ee.js
Normal file
27
packages/backend/src/routes/api/v1/admin/apps.ee.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import asyncHandler from 'express-async-handler';
|
||||||
|
import { authenticateUser } from '../../../../helpers/authentication.js';
|
||||||
|
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
||||||
|
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
||||||
|
import getAuthClientsAction from '../../../../controllers/api/v1/admin/apps/get-auth-clients.ee.js';
|
||||||
|
import getRoleAction from '../../../../controllers/api/v1/admin/roles/get-role.ee.js';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/auth-clients',
|
||||||
|
authenticateUser,
|
||||||
|
authorizeAdmin,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getAuthClientsAction)
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/auth-clients/:appAuthClientId',
|
||||||
|
authenticateUser,
|
||||||
|
authorizeAdmin,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getRoleAction)
|
||||||
|
);
|
||||||
|
|
||||||
|
export default router;
|
@@ -13,6 +13,7 @@ import appsRouter from './api/v1/apps.js';
|
|||||||
import connectionsRouter from './api/v1/connections.js';
|
import connectionsRouter from './api/v1/connections.js';
|
||||||
import executionsRouter from './api/v1/executions.js';
|
import executionsRouter from './api/v1/executions.js';
|
||||||
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
||||||
|
import adminAppsRouter from './api/v1/admin/apps.ee.js';
|
||||||
import adminSamlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
import adminSamlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
||||||
import rolesRouter from './api/v1/admin/roles.ee.js';
|
import rolesRouter from './api/v1/admin/roles.ee.js';
|
||||||
import permissionsRouter from './api/v1/admin/permissions.ee.js';
|
import permissionsRouter from './api/v1/admin/permissions.ee.js';
|
||||||
@@ -35,10 +36,11 @@ router.use('/api/v1/flows', flowsRouter);
|
|||||||
router.use('/api/v1/steps', stepsRouter);
|
router.use('/api/v1/steps', stepsRouter);
|
||||||
router.use('/api/v1/executions', executionsRouter);
|
router.use('/api/v1/executions', executionsRouter);
|
||||||
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
|
router.use('/api/v1/admin/apps', adminAppsRouter);
|
||||||
|
router.use('/api/v1/admin/users', adminUsersRouter);
|
||||||
router.use('/api/v1/admin/roles', rolesRouter);
|
router.use('/api/v1/admin/roles', rolesRouter);
|
||||||
router.use('/api/v1/admin/permissions', permissionsRouter);
|
router.use('/api/v1/admin/permissions', permissionsRouter);
|
||||||
router.use('/api/v1/admin/users', adminUsersRouter);
|
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/app-auth-clients', adminAppAuthClientsRouter);
|
router.use('/api/v1/admin/app-auth-clients', adminAppAuthClientsRouter);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
const getAdminAppAuthClientsMock = (appAuthClients) => {
|
const getAdminAppAuthClientsMock = (appAuthClients) => {
|
||||||
return {
|
return {
|
||||||
data: appAuthClients.map((appAuthClient) => ({
|
data: appAuthClients.map((appAuthClient) => ({
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
Reference in New Issue
Block a user