Skip to content
Snippets Groups Projects
Commit 7be4ac29 authored by joel.vonderwe's avatar joel.vonderwe Committed by michael.minelli
Browse files

Correct boolean validator bug

parent d0874a5b
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import { GitbeakerRequestError } from '@gitbeaker/requester-utils';
import * as Gitlab from '@gitbeaker/rest';
import axios, { AxiosError } from 'axios';
import SharedConfig from '../shared/config/SharedConfig';
import * as https from 'https';
class GlobalHelper {
......@@ -60,7 +61,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;
......
......@@ -27,23 +27,25 @@ import SharedConfig from '../shared/config/SharedConfig.js';
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 = {
......@@ -131,12 +133,14 @@ class AssignmentRoutes implements RoutesManager {
private async createAssignment(req: express.Request, res: express.Response) {
const params: {
name: string, members: Array<Gitlab.UserSchema>, template: string, useSonar: boolean
name: string, members: Array<Gitlab.UserSchema>, 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);
}
......@@ -185,7 +189,7 @@ class AssignmentRoutes implements RoutesManager {
gitlabCreationDate: new Date(),
gitlabLastInfo : repository as unknown as Prisma.JsonObject,
gitlabLastInfoDate: new Date(),
useSonar : params.useSonar,
useSonar : useSonar,
staff : {
connectOrCreate: [ ...params.members.map(gitlabUser => {
return {
......
......@@ -4,6 +4,7 @@ import { StatusCodes } from 'http-status-codes';
import RoutesManager from '../express/RoutesManager.js';
import Config from '../config/Config';
import SharedConfig from '../shared/config/SharedConfig';
import GlobalHelper from '../helpers/GlobalHelper';
class BaseRoutes implements RoutesManager {
......@@ -36,7 +37,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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment