Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions slp_mtmt/tests/integration/test_mtmt_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
SAMPLE_UNMAPPED_TRUSTZONES = test_resource_paths.unmapped_trustzones_tm7
SAMPLE_UNMAPPED_TRUSTZONES_OTM = test_resource_paths.unmapped_trustzones_otm
SAMPLE_MODEL_NO_NAME_FIGURES = test_resource_paths.model_with_no_name_figures_tm7
MTMT_AZURE_COMPONENTS = test_resource_paths.azure_components_tm7
OTM_AZURE_COMPONENTS = test_resource_paths.azure_components_otm
MTMT_SIMPLE_LINE_BOUNDARY = test_resource_paths.simple_line_boundary_tm7
MTMT_MULTIPLE_TRUSTZONES_SAME_TYPE = test_resource_paths.multiple_trustzones_same_type_tm7
MAPPING_MULTIPLE_TRUSTZONES_SAME_TYPE = test_resource_paths.multiple_trustzones_same_type_mapping

class TestMtmtProcessor:
excluded_regex = [
Expand Down Expand Up @@ -172,3 +177,75 @@ def test_invalid_mapping_file_size(self, mappings: list[bytes]):
assert 'Mapping files are not valid' == error.value.title
assert 'Mapping files are not valid. Invalid size' == error.value.detail
assert 'Mapping files are not valid. Invalid size' == error.value.message

def test_run_azure_components(self):
# GIVEN a valid MTMT file with some resources
source_file = get_byte_data(MTMT_AZURE_COMPONENTS)

# AND a valid MTMT mapping file
mapping_file = get_byte_data(SAMPLE_VALID_MAPPING_FILE)

# WHEN the MTMT file is processed
otm = MTMTProcessor(SAMPLE_ID, SAMPLE_NAME, source_file, [mapping_file]).process()

# THEN we check the result is as expected
result, expected = validate_and_compare(otm.json(), OTM_AZURE_COMPONENTS, None)
assert result == expected

def test_run_simple_line_boundary(self):
# GIVEN a valid MTMT file with some resources
source_file = get_byte_data(MTMT_SIMPLE_LINE_BOUNDARY)

# AND a valid MTMT mapping file
mapping_file = get_byte_data(SAMPLE_VALID_MAPPING_FILE)

# WHEN the MTMT file is processed
otm = MTMTProcessor(SAMPLE_ID, SAMPLE_NAME, source_file, [mapping_file]).process()

# THEN we check the result is as expected
assert len(otm.trustzones) == 2
assert otm.trustzones[0].id == 'ef4b8d94-ff80-419b-b590-b1a6aad88408'
assert otm.trustzones[0].name == 'Generic Trust Line Boundary'
assert otm.trustzones[0].type == 'b61d6911-338d-46a8-9f39-8dcd24abfe91'
assert otm.trustzones[0].trustrating == 10
assert otm.trustzones[1].id == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
assert otm.trustzones[1].name == 'Default trustzone'
assert otm.trustzones[1].type == 'b61d6911-338d-46a8-9f39-8dcd24abfe91'
assert otm.trustzones[1].trustrating == 10
assert otm.components[0].parent == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
assert otm.components[1].parent == 'ef4b8d94-ff80-419b-b590-b1a6aad88408'
assert otm.components[2].parent == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
assert otm.components[3].parent == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'

def test_run_multiple_trustzones_same_type(self):
# GIVEN a valid MTMT file with some resources
source_file = get_byte_data(MTMT_MULTIPLE_TRUSTZONES_SAME_TYPE)

# AND a valid MTMT mapping file
mapping_file = get_byte_data(MAPPING_MULTIPLE_TRUSTZONES_SAME_TYPE)

# WHEN the MTMT file is processed
otm = MTMTProcessor(SAMPLE_ID, SAMPLE_NAME, source_file, [mapping_file]).process()

# THEN we check the result is as expected
assert len(otm.trustzones) == 5
assert otm.trustzones[0].id == '06de5005-eca7-41c8-8848-9d942dc7994d'
assert otm.trustzones[0].name == 'Local User Zone'
assert otm.trustzones[0].type == '2ab4effa-40b7-4cd2-ba81-8247d29a6f2d'
assert otm.trustzones[0].trustrating == 10
assert otm.trustzones[1].id == '1c5a9402-2016-4bc6-9861-9e7eaf725ae6'
assert otm.trustzones[1].name == 'Azure Trust Boundary'
assert otm.trustzones[1].type == '2ab4effa-40b7-4cd2-ba81-8247d29a6f2d'
assert otm.trustzones[1].trustrating == 10
assert otm.trustzones[2].id == '871dde5d-cd57-4436-a07d-a73f039511a2'
assert otm.trustzones[2].name == 'Azure Trust Boundary'
assert otm.trustzones[2].type == '2ab4effa-40b7-4cd2-ba81-8247d29a6f2d'
assert otm.trustzones[2].trustrating == 10
assert otm.trustzones[3].id == 'efb356d5-0b83-4b16-be28-0337c29a7d4a'
assert otm.trustzones[3].name == 'Remote User Zone'
assert otm.trustzones[3].type == 'f0ba7722-39b6-4c81-8290-a30a248bb8d9'
assert otm.trustzones[3].trustrating == 10
assert otm.trustzones[4].id == 'b39375e4-1903-4c20-bf8d-fbfdde6d2d77'
assert otm.trustzones[4].name == 'Remote User Zone'
assert otm.trustzones[4].type == 'f0ba7722-39b6-4c81-8290-a30a248bb8d9'
assert otm.trustzones[4].trustrating == 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trustzones:

- label: Remote User Zone
type: f0ba7722-39b6-4c81-8290-a30a248bb8d9

- label: Local User Zone
type: 2ab4effa-40b7-4cd2-ba81-8247d29a6f2d


- label: Azure Trust Boundary
type: 2ab4effa-40b7-4cd2-ba81-8247d29a6f2d


components: []

dataflows: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
{
"otmVersion": "0.2.0",
"project": {
"id": "example-project",
"name": "Example Project"
},
"representations": [
{
"id": "Microsoft Threat Modeling Tool",
"name": "Microsoft Threat Modeling Tool",
"type": "threat-model"
},
{
"id": "example-project-diagram",
"name": "example-project Diagram Representation",
"size": {
"height": 2000,
"width": 2000
},
"type": "diagram"
}
],
"trustZones": [
{
"attributes": {
"Dataflow Order": "0",
"Name": "The Public zone"
},
"id": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374",
"name": "The Public zone",
"representations": [
{
"id": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374-representation",
"name": "The Public zone Representation",
"position": {
"x": 60,
"y": 26
},
"representation": "example-project-diagram",
"size": {
"height": 430,
"width": 1243
}
}
],
"risk": {
"trustRating": 10
},
"type": "b61d6911-338d-46a8-9f39-8dcd24abfe91"
}
],
"components": [
{
"attributes": {
"Azure Postgres DB Firewall Settings": "Select",
"Azure Postgres DB TLS Enforced": "Select",
"Name": "Azure Database for PostgreSQL",
"Out Of Scope": "false"
},
"id": "81b54eb4-e007-4682-ac6f-fa75d3b8a19d",
"name": "Azure Database for PostgreSQL",
"parent": {
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
},
"representations": [
{
"id": "81b54eb4-e007-4682-ac6f-fa75d3b8a19d-representation",
"name": "Azure Database for PostgreSQL Representation",
"position": {
"x": 934,
"y": 45
},
"representation": "example-project-diagram",
"size": {
"height": 82,
"width": 82
}
}
],
"type": "CD-MICROSOFT-AZURE-DB-POSTGRESQL"
},
{
"attributes": {
"CORS Enabled": "Select",
"HTTPS Enforced": "Select",
"Name": "Azure Storage",
"Network Security": "Select",
"Out Of Scope": "false",
"Storage Type": "Select"
},
"id": "df895836-af23-4033-ab75-81352301e4ce",
"name": "Azure Storage",
"parent": {
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
},
"representations": [
{
"id": "df895836-af23-4033-ab75-81352301e4ce-representation",
"name": "Azure Storage Representation",
"position": {
"x": 301,
"y": 162
},
"representation": "example-project-diagram",
"size": {
"height": 82,
"width": 82
}
}
],
"type": "azure-storage"
},
{
"attributes": {
"Mobile Client Technologies": "Android",
"Name": "Mobile Client - Android",
"Out Of Scope": "false"
},
"id": "ab94757b-4722-403f-8e9d-425edd5343ee",
"name": "Mobile Client - Android",
"parent": {
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
},
"representations": [
{
"id": "ab94757b-4722-403f-8e9d-425edd5343ee-representation",
"name": "Mobile Client - Android Representation",
"position": {
"x": 45,
"y": 281
},
"representation": "example-project-diagram",
"size": {
"height": 82,
"width": 82
}
}
],
"type": "android-device-client"
},
{
"attributes": {
"Mobile Client Technologies": "iOS",
"Name": "Mobile Client - iOS",
"Out Of Scope": "false"
},
"id": "ff0709b7-7d68-4c6f-a2d3-6c2ad01cf448",
"name": "Mobile Client - iOS",
"parent": {
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
},
"representations": [
{
"id": "ff0709b7-7d68-4c6f-a2d3-6c2ad01cf448-representation",
"name": "Mobile Client - iOS Representation",
"position": {
"x": 177,
"y": 284
},
"representation": "example-project-diagram",
"size": {
"height": 82,
"width": 82
}
}
],
"type": "ios-device-client"
},
{
"attributes": {
"Hosting environment": "Select",
"Identity Provider": "Select",
"Name": "Web API - RESTful",
"Out Of Scope": "false",
"Web API Technologies": "Select"
},
"id": "977581d7-5176-4f6e-875d-be5ca87fe2e5",
"name": "Web API - RESTful",
"parent": {
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
},
"representations": [
{
"id": "977581d7-5176-4f6e-875d-be5ca87fe2e5-representation",
"name": "Web API - RESTful Representation",
"position": {
"x": 299,
"y": 286
},
"representation": "example-project-diagram",
"size": {
"height": 82,
"width": 82
}
}
],
"type": "web-service"
},
{
"attributes": {
"Hosting environment": "Select",
"Identity Provider": "Select",
"Name": "Web API - SOAP",
"Out Of Scope": "false",
"Web API Technologies": "Select"
},
"id": "fe3b51b9-cddc-4758-91f0-5fe05a1a1387",
"name": "Web API - SOAP",
"parent": {
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
},
"representations": [
{
"id": "fe3b51b9-cddc-4758-91f0-5fe05a1a1387-representation",
"name": "Web API - SOAP Representation",
"position": {
"x": 417,
"y": 289
},
"representation": "example-project-diagram",
"size": {
"height": 82,
"width": 82
}
}
],
"type": "web-service"
}
],
"dataflows": []
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion slp_mtmt/tests/resources/test_resource_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
mtmt_mapping_invalid_no_dataflows = f'{path}/mapping/invalid-mapping-without-dataflows.yaml'
name_mapping_overriden = f'{path}/mapping/name_mapping_overriden.yaml'
type_mapping_overriden = f'{path}/mapping/type_mapping_overriden.yaml'
multiple_trustzones_same_type_mapping = f'{path}/mapping/multiple-trustzones-same-type.yaml'


# legacy mapping
Expand All @@ -46,6 +47,9 @@
model_with_figures_without_name_file = f'{path}/mtmt/model_with_figures_without_name.tm7'
unmapped_trustzones_tm7 = f'{path}/mtmt/mtmt-resources-SDL-knowledge-base-components.tm7'
model_with_no_name_figures_tm7 = f'{path}/mtmt/mtmt-model-with-figures-without-name.tm7'
azure_components_tm7 = f'{path}/mtmt/mtmt-azure-tm-template-components-default-mapping.tm7'
simple_line_boundary_tm7 = f'{path}/mtmt/MTMT_simple_line_boundary.tm7'
multiple_trustzones_same_type_tm7 = f'{path}/mtmt/multiple_trustzones_same_type.tm7'

# OTM
example_position_otm = f'{path}/mtmt/MTMT_example_coordinates.otm'
Expand All @@ -57,4 +61,4 @@
nested_trustzones_line_otm = f'{path}/otm/nested_tz_line.otm'
model_mtmt_source_file_otm = f'{path}/otm/test_model_tm7.otm'
unmapped_trustzones_otm = f'{path}/mtmt/mtmt-resources-SDL-knowledge-base-components.otm'

azure_components_otm = f'{path}/mtmt/mtmt-azure-tm-template-components-default-mapping.otm'
Loading