From 5ab0137f274b9c92f0511f7b13f2eb28b2f603b0 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 1 Jun 2021 10:31:59 +0300 Subject: [PATCH] Improved a mock endpoint for testing import configuration modal --- .../monkey_island/cc/resources/temp_configuration.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/resources/temp_configuration.py b/monkey/monkey_island/cc/resources/temp_configuration.py index 1c558e7f8..fe9ae09b6 100644 --- a/monkey/monkey_island/cc/resources/temp_configuration.py +++ b/monkey/monkey_island/cc/resources/temp_configuration.py @@ -1,6 +1,8 @@ +import json from dataclasses import dataclass import flask_restful +from flask import request from common.utils.exceptions import ( InvalidConfigurationError, @@ -26,9 +28,9 @@ class TempConfiguration(flask_restful.Resource): @jwt_required def post(self): - # request_contents = json.loads(request.data) + request_contents = json.loads(request.data) try: - self.decrypt() + self.decrypt(request_contents["password"]) self.import_config() return ResponseContents().form_response() except InvalidCredentialsError: @@ -50,7 +52,11 @@ class TempConfiguration(flask_restful.Resource): status_code=403, ).form_response() - def decrypt(self): + def decrypt(self, password=""): + if not password: + raise NoCredentialsError + if not password == "abc": + raise InvalidCredentialsError return False def import_config(self):