feat: Implement get saml auth providers API endpoint
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
import { renderObject } from '../../../../helpers/renderer.js';
|
||||||
|
import SamlAuthProvider from '../../../../models/saml-auth-provider.ee.js';
|
||||||
|
|
||||||
|
export default async (request, response) => {
|
||||||
|
const samlAuthProviders = await SamlAuthProvider.query().orderBy(
|
||||||
|
'created_at',
|
||||||
|
'desc'
|
||||||
|
);
|
||||||
|
|
||||||
|
renderObject(response, samlAuthProviders);
|
||||||
|
};
|
@@ -0,0 +1,46 @@
|
|||||||
|
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 { createPermission } from '../../../../../test/factories/permission.js';
|
||||||
|
import { createSamlAuthProvider } from '../../../../../test/factories/saml-auth-provider.ee.js';
|
||||||
|
import getSamlAuthProvidersMock from '../../../../../test/mocks/rest/api/v1/saml-auth-providers/get-saml-auth-providers.ee.js';
|
||||||
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/saml-auth-providers', () => {
|
||||||
|
let samlAuthProviderOne, samlAuthProviderTwo, currentUser, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
currentUser = await createUser();
|
||||||
|
const role = await currentUser.$relatedQuery('role');
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
roleId: role.id,
|
||||||
|
action: 'read',
|
||||||
|
subject: 'SamlAuthProvider',
|
||||||
|
conditions: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
samlAuthProviderOne = await createSamlAuthProvider();
|
||||||
|
samlAuthProviderTwo = await createSamlAuthProvider();
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return saml auth providers', async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/v1/saml-auth-providers')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = await getSamlAuthProvidersMock([
|
||||||
|
samlAuthProviderTwo,
|
||||||
|
samlAuthProviderOne,
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -7,6 +7,10 @@ const authorizationList = {
|
|||||||
action: 'read',
|
action: 'read',
|
||||||
subject: 'User',
|
subject: 'User',
|
||||||
},
|
},
|
||||||
|
'/api/v1/saml-auth-providers/': {
|
||||||
|
action: 'read',
|
||||||
|
subject: 'SamlAuthProvider',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const authorizeUser = async (request, response, next) => {
|
export const authorizeUser = async (request, response, next) => {
|
||||||
|
17
packages/backend/src/routes/api/v1/saml-auth-providers.ee.js
Normal file
17
packages/backend/src/routes/api/v1/saml-auth-providers.ee.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||||
|
import { authorizeUser } from '../../../helpers/authorization.js';
|
||||||
|
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
||||||
|
import getSamlAuthProvidersAction from '../../../controllers/api/v1/saml-auth-providers/get-saml-auth-providers.ee.js';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/',
|
||||||
|
authenticateUser,
|
||||||
|
authorizeUser,
|
||||||
|
checkIsEnterprise,
|
||||||
|
getSamlAuthProvidersAction
|
||||||
|
);
|
||||||
|
|
||||||
|
export default router;
|
@@ -5,6 +5,7 @@ import paddleRouter from './paddle.ee.js';
|
|||||||
import healthcheckRouter from './healthcheck.js';
|
import healthcheckRouter from './healthcheck.js';
|
||||||
import automatischRouter from './api/v1/automatisch.js';
|
import automatischRouter from './api/v1/automatisch.js';
|
||||||
import usersRouter from './api/v1/users.js';
|
import usersRouter from './api/v1/users.js';
|
||||||
|
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -14,5 +15,6 @@ router.use('/paddle', paddleRouter);
|
|||||||
router.use('/healthcheck', healthcheckRouter);
|
router.use('/healthcheck', healthcheckRouter);
|
||||||
router.use('/api/v1/automatisch', automatischRouter);
|
router.use('/api/v1/automatisch', automatischRouter);
|
||||||
router.use('/api/v1/users', usersRouter);
|
router.use('/api/v1/users', usersRouter);
|
||||||
|
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import userSerializer from './user.js';
|
import userSerializer from './user.js';
|
||||||
import roleSerializer from './role.js';
|
import roleSerializer from './role.js';
|
||||||
import permissionSerializer from './permission.js';
|
import permissionSerializer from './permission.js';
|
||||||
|
import samlAuthProviderSerializer from './saml-auth-provider.ee.js';
|
||||||
|
|
||||||
const serializers = {
|
const serializers = {
|
||||||
User: userSerializer,
|
User: userSerializer,
|
||||||
Role: roleSerializer,
|
Role: roleSerializer,
|
||||||
Permission: permissionSerializer,
|
Permission: permissionSerializer,
|
||||||
|
SamlAuthProvider: samlAuthProviderSerializer,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default serializers;
|
export default serializers;
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
const getSamlAuthProvidersMock = async (samlAuthProviders) => {
|
||||||
|
const data = samlAuthProviders.map((samlAuthProvider) => {
|
||||||
|
return {
|
||||||
|
active: samlAuthProvider.active,
|
||||||
|
certificate: samlAuthProvider.certificate,
|
||||||
|
defaultRoleId: samlAuthProvider.defaultRoleId,
|
||||||
|
emailAttributeName: samlAuthProvider.emailAttributeName,
|
||||||
|
entryPoint: samlAuthProvider.entryPoint,
|
||||||
|
firstnameAttributeName: samlAuthProvider.firstnameAttributeName,
|
||||||
|
id: samlAuthProvider.id,
|
||||||
|
issuer: samlAuthProvider.issuer,
|
||||||
|
name: samlAuthProvider.name,
|
||||||
|
roleAttributeName: samlAuthProvider.roleAttributeName,
|
||||||
|
signatureAlgorithm: samlAuthProvider.signatureAlgorithm,
|
||||||
|
surnameAttributeName: samlAuthProvider.surnameAttributeName,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: data,
|
||||||
|
meta: {
|
||||||
|
count: data.length,
|
||||||
|
currentPage: null,
|
||||||
|
isArray: true,
|
||||||
|
totalPages: null,
|
||||||
|
type: 'SamlAuthProvider',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getSamlAuthProvidersMock;
|
Reference in New Issue
Block a user