Skip to content

Commit

Permalink
Merge pull request #407 from iriusrisk/feature/BLAZ-710
Browse files Browse the repository at this point in the history
[feature/BLAZ-710] to dev
  • Loading branch information
jmgarcia-iriusrisk authored Oct 30, 2024
2 parents f5346b1 + f18c742 commit 6d864a6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'jmespath==1.0.1',
'python-hcl2==4.3.2',
'requests==2.32.3',
'fastapi==0.109.2',
'fastapi>=0.115.2,<0.116.0',
'python-multipart==0.0.7',
'click==8.1.7',
'uvicorn==0.23.2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
@check_mime_type('diag_file', 'diag_type', DiagramFileNotValidError)
def diagram(diag_file: UploadFile = File(...),
diag_type: DiagramType = Form(...),
id: str = Form(...),
name: str = Form(...),
id: str = Form(..., min_length=1, max_length=999),
name: str = Form(..., min_length=1, max_length=999),
default_mapping_file: UploadFile = File(...),
custom_mapping_file: UploadFile = File(None)):
logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
@check_mime_type('source_file', 'source_type')
def etm(source_file: UploadFile = File(...),
source_type: EtmType = Form(...),
id: str = Form(...),
name: str = Form(...),
id: str = Form(..., min_length=1, max_length=999),
name: str = Form(..., min_length=1, max_length=999),
default_mapping_file: UploadFile = File(...),
custom_mapping_file: UploadFile = File(None)):
logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
def iac(iac_file: List[UploadFile]
= File(...),
iac_type: IacType = Form(...),
id: str = Form(...),
name: str = Form(...),
id: str = Form(..., min_length=1, max_length=999),
name: str = Form(..., min_length=1, max_length=999),
mapping_file: UploadFile = File(None),
default_mapping_file: UploadFile = File(None),
custom_mapping_file: UploadFile = File(None)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from startleft.startleft.api.controllers.diagram import diag_create_otm_controller
from tests.resources import test_resource_paths

IRIUSRISK_URL = ''

webapp = fastapi_server.webapp

client = TestClient(webapp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json

import pytest
from fastapi.testclient import TestClient

from startleft.startleft.api import fastapi_server
from startleft.startleft.api.controllers.etm import etm_create_otm_controller

webapp = fastapi_server.webapp

client = TestClient(webapp)


def get_url():
return etm_create_otm_controller.PREFIX + etm_create_otm_controller.URL


octet_stream = 'application/octet-stream'


class TestOTMControllerEtm:

@pytest.mark.parametrize("project_id,project_name,source_file,errors_expected, error_type", [
(None, 'name', None, 4, 'RequestValidationError'),
('id', None, None, 4, 'RequestValidationError'),
('id', 'name', None, 3, 'RequestValidationError'),
(None, None, None, 5, 'RequestValidationError'),
('', None, None, 5, 'RequestValidationError')
])
def test_create_project_validation_error(self, project_id: str, project_name: str, source_file,
errors_expected: int,
error_type: str):
# Given a body
body = {'id': project_id, 'name': project_name}

# When I do post to the endpoint
files = {'source_file': source_file} if source_file else None
response = client.post(get_url(), files=files, data=body)

# Then
assert response.status_code == 400
res_body = json.loads(response.text)
assert res_body['status'] == '400'
assert res_body['error_type'] == error_type
assert len(res_body['errors']) == errors_expected
for e in res_body['errors']:
assert len(e['errorMessage']) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from startleft.startleft.api.controllers.iac import iac_create_otm_controller
from tests.resources.test_resource_paths import default_cloudformation_mapping, example_json, \
cloudformation_malformed_mapping_wrong_id, invalid_yaml, cloudformation_all_functions, \
cloudformation_mapping_all_functions, cloudformation_gz, visio_aws_shapes, cloudformation_multiple_files_networks, \
cloudformation_mapping_all_functions, cloudformation_gz, cloudformation_multiple_files_networks, \
cloudformation_multiple_files_resources, cloudformation_ref_full_syntax, cloudformation_ref_short_syntax

TESTING_IAC_TYPE = IacType.CLOUDFORMATION.value
Expand Down Expand Up @@ -98,6 +98,9 @@ def test_create_project_validation_error(self, project_id: str, project_name: st
res_body = json.loads(response.content.decode('utf-8'))
assert res_body['status'] == '400'
assert res_body['error_type'] == error_type
assert len(res_body['errors']) == 1
for e in res_body['errors']:
assert len(e['errorMessage']) > 0

@responses.activate
@patch('slp_cft.slp_cft.validate.cft_validator.CloudformationValidator.validate')
Expand Down

0 comments on commit 6d864a6

Please sign in to comment.