diff --git a/ExpressAPI/src/helpers/GlobalHelper.ts b/ExpressAPI/src/helpers/GlobalHelper.ts index f9e59ee7e25bfcaf125c1e5bc990921535012d58..18f0d57714f6febb5063fcbfe92cb5d9875e0a13 100644 --- a/ExpressAPI/src/helpers/GlobalHelper.ts +++ b/ExpressAPI/src/helpers/GlobalHelper.ts @@ -6,6 +6,7 @@ import axios, { AxiosError } from 'axios'; import { StatusCodes } from 'http-status-codes'; import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode'; import SharedConfig from '../shared/config/SharedConfig'; +import * as https from 'https'; class GlobalHelper { @@ -31,7 +32,13 @@ class GlobalHelper { async isSonarSupported(): Promise<boolean> { try { - const sonar = await axios.get(SharedConfig.sonar.url); + // Use custom instance to allow self-signed certificates + const instance = axios.create({ + httpsAgent: new https.Agent({ + rejectUnauthorized: false + }) + }); + const sonar = await instance.get(SharedConfig.sonar.url); return SharedConfig.sonar.enabled && sonar.status == 200; } catch ( error ) { return false; diff --git a/ExpressAPI/src/routes/AssignmentRoutes.ts b/ExpressAPI/src/routes/AssignmentRoutes.ts index 28bdb2b1dab2dea278d1a1a154dfe7d385e1fa93..7b192fcf855065660c8a6ef36f168996b9606a76 100644 --- a/ExpressAPI/src/routes/AssignmentRoutes.ts +++ b/ExpressAPI/src/routes/AssignmentRoutes.ts @@ -30,23 +30,25 @@ import DojoModelsHelper from '../helpers/DojoModelsHelper'; class AssignmentRoutes implements RoutesManager { private readonly assignmentValidator: ExpressValidator.Schema = { - name : { + name : { trim : true, notEmpty: true }, - members : { + members : { trim : true, notEmpty : true, customSanitizer: DojoValidators.jsonSanitizer }, - template: { + template : { trim : true, custom : DojoValidators.templateUrlValidator, customSanitizer: DojoValidators.templateUrlSanitizer }, - useSonar: { - notEmpty: true - } + useSonar : { + trim : true, + notEmpty : true, + isBoolean: true, + }, }; private readonly assignmentAddCorrigeValidator: ExpressValidator.Schema = { @@ -88,12 +90,14 @@ class AssignmentRoutes implements RoutesManager { private async createAssignment(req: express.Request, res: express.Response) { const params: { - name: string, members: Array<GitlabUser>, template: string, useSonar: boolean + name: string, members: Array<GitlabUser>, template: string, useSonar: string } = req.body; + const useSonar = params.useSonar === 'true'; + params.members = [ await req.session.profile.gitlabProfile.value, ...params.members ]; params.members = params.members.removeObjectDuplicates(gitlabUser => gitlabUser.id); - if (params.useSonar && !(await GlobalHelper.isSonarSupported())) { + if (useSonar && !(await GlobalHelper.isSonarSupported())) { return req.session.sendResponse(res, StatusCodes.UNPROCESSABLE_ENTITY, {}, `Sonar integration is not supported`, DojoStatusCode.ASSIGNMENT_CREATION_SONAR_ERROR); } @@ -154,7 +158,7 @@ class AssignmentRoutes implements RoutesManager { gitlabCreationInfo: repository as unknown as Prisma.JsonObject, gitlabLastInfo : repository as unknown as Prisma.JsonObject, gitlabLastInfoDate: new Date(), - useSonar : params.useSonar, + useSonar : useSonar, staff : { connectOrCreate: [ ...params.members.map(gitlabUser => { return { diff --git a/ExpressAPI/src/routes/BaseRoutes.ts b/ExpressAPI/src/routes/BaseRoutes.ts index 5d29ac0e1f8c117b6d5296f638b552b1919a0b73..6db7ef7d1aa585a9695472a32d7b67dcbdd9280c 100644 --- a/ExpressAPI/src/routes/BaseRoutes.ts +++ b/ExpressAPI/src/routes/BaseRoutes.ts @@ -2,7 +2,7 @@ import { Express } from 'express-serve-static-core'; import express from 'express'; import { StatusCodes } from 'http-status-codes'; import RoutesManager from '../express/RoutesManager'; -import SharedConfig from '../shared/config/SharedConfig'; +import GlobalHelper from '../helpers/GlobalHelper'; class BaseRoutes implements RoutesManager { @@ -22,7 +22,7 @@ class BaseRoutes implements RoutesManager { private async sonar(req: express.Request, res: express.Response) { const data = { - sonarEnabled: SharedConfig.useSonar + sonarEnabled: await GlobalHelper.isSonarSupported() }; return req.session.sendResponse(res, StatusCodes.OK, data); }