Skip to content
Snippets Groups Projects
Commit c05d958d authored by michael.minelli's avatar michael.minelli
Browse files

Sonar => Resolve issues

parent 17ed9531
Branches
Tags
1 merge request!3Return error when client headers are missing (issue #19)
Pipeline #29954 passed
......@@ -15,4 +15,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="2749ea0f-74a8-42c0-9fd6-d6a4b4cd75a4" />
</component>
</module>
\ No newline at end of file
......@@ -38,7 +38,7 @@ class API implements WorkerTask {
private initBaseMiddlewares() {
this.backend.use(multer({
limits: { fieldSize: 100 * 1024 * 1024 }
limits: { fieldSize: 15 * 1024 * 1024 }
}).none()); //Used for extract params from body with format "form-data", The none is for say that we do not wait a file in params
this.backend.use(morganMiddleware); //Log API accesses
this.backend.use(helmet()); //Help to secure express, https://helmetjs.github.io/
......
......@@ -201,8 +201,6 @@ class AssignmentRoutes implements RoutesManager {
logger.error(error);
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send();
}
return;
};
}
......
......@@ -119,11 +119,11 @@ class ExerciseRoutes implements RoutesManager {
suffix++;
} else {
req.session.sendResponse(res, StatusCodes.INTERNAL_SERVER_ERROR, {}, 'Unknown gitlab error while forking repository', DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR);
return;
return undefined;
}
} else {
req.session.sendResponse(res, StatusCodes.INTERNAL_SERVER_ERROR, {}, 'Unknown error while forking repository', DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR);
return;
return undefined;
}
}
} while ( suffix < Config.exercise.maxSameName );
......@@ -131,7 +131,7 @@ class ExerciseRoutes implements RoutesManager {
if ( suffix >= Config.exercise.maxSameName ) {
logger.error('Max exercise with same name reached');
req.session.sendResponse(res, StatusCodes.INSUFFICIENT_SPACE_ON_RESOURCE, undefined, 'Max exercise per assignment reached', DojoStatusCode.MAX_EXERCISE_PER_ASSIGNMENT_REACHED);
return;
return undefined;
}
return repository;
......@@ -139,13 +139,14 @@ class ExerciseRoutes implements RoutesManager {
private async createExercise(req: express.Request, res: express.Response) {
const params: { members: Array<GitlabUser> } = req.body;
params.members = [ await req.session.profile.gitlabProfile!.value, ...params.members ].removeObjectDuplicates(gitlabUser => gitlabUser.id);
params.members = [ await req.session.profile.gitlabProfile.value, ...params.members ].removeObjectDuplicates(gitlabUser => gitlabUser.id);
const assignment: Assignment = req.boundParams.assignment!;
const reachedLimitUsers: Array<GitlabUser> = await this.checkExerciseLimit(assignment, params.members);
if ( reachedLimitUsers.length > 0 ) {
return req.session.sendResponse(res, StatusCodes.INSUFFICIENT_SPACE_ON_RESOURCE, reachedLimitUsers, 'Max exercise per assignment reached', DojoStatusCode.MAX_EXERCISE_PER_ASSIGNMENT_REACHED);
req.session.sendResponse(res, StatusCodes.INSUFFICIENT_SPACE_ON_RESOURCE, reachedLimitUsers, 'Max exercise per assignment reached', DojoStatusCode.MAX_EXERCISE_PER_ASSIGNMENT_REACHED);
return;
}
......@@ -168,13 +169,15 @@ class ExerciseRoutes implements RoutesManager {
await GitlabManager.addRepositoryBadge(repository.id, Config.gitlab.badges.pipeline.link, Config.gitlab.badges.pipeline.imageUrl, 'Pipeline Status');
} catch ( error ) {
return GlobalHelper.repositoryCreationError('Repo params error', error, req, res, DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR, DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR, repository);
GlobalHelper.repositoryCreationError('Repo params error', error, req, res, DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR, DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR, repository);
return;
}
try {
await GitlabManager.updateFile(repository.id, '.gitlab-ci.yml', fs.readFileSync(path.join(__dirname, '../../assets/exercise_gitlab_ci.yml'), 'base64'), 'Add .gitlab-ci.yml (DO NOT MODIFY THIS FILE)');
} catch ( error ) {
return GlobalHelper.repositoryCreationError('CI file update error', error, req, res, DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR, DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR, repository);
GlobalHelper.repositoryCreationError('CI file update error', error, req, res, DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR, DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR, repository);
return;
}
try {
......@@ -215,9 +218,11 @@ class ExerciseRoutes implements RoutesManager {
}
}) as unknown as Exercise;
return req.session.sendResponse(res, StatusCodes.OK, exercise);
req.session.sendResponse(res, StatusCodes.OK, exercise);
return;
} catch ( error ) {
return GlobalHelper.repositoryCreationError('DB error', error, req, res, DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR, DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR, repository);
await GlobalHelper.repositoryCreationError('DB error', error, req, res, DojoStatusCode.EXERCISE_CREATION_GITLAB_ERROR, DojoStatusCode.EXERCISE_CREATION_INTERNAL_ERROR, repository);
return;
}
}
......@@ -235,7 +240,7 @@ class ExerciseRoutes implements RoutesManager {
return file;
}));
const dojoAssignmentFile: AssignmentFile = JSON5.parse(atob(assignmentHjsonFile.content)) as AssignmentFile;
const dojoAssignmentFile: AssignmentFile = JSON5.parse(atob(assignmentHjsonFile.content));
const immutablePaths = dojoAssignmentFile.immutable.map(fileDescriptor => fileDescriptor.path);
......
Subproject commit da76a3b35471ec1e9862ae3b57f5905a909058b5
Subproject commit 6214acbd799d9eed3f5b6840858f8d5ecda82c86
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment