Skip to content

Commit 6d327fb

Browse files
Merge pull request #487 from iriusrisk/feature/BLAZ-2438
[feature/BLAZ-2438] to dev
2 parents 256e8ff + d835b87 commit 6d327fb

6 files changed

Lines changed: 337 additions & 1 deletion

slp_mtmt/tests/integration/test_mtmt_processor.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
SAMPLE_UNMAPPED_TRUSTZONES = test_resource_paths.unmapped_trustzones_tm7
3232
SAMPLE_UNMAPPED_TRUSTZONES_OTM = test_resource_paths.unmapped_trustzones_otm
3333
SAMPLE_MODEL_NO_NAME_FIGURES = test_resource_paths.model_with_no_name_figures_tm7
34+
MTMT_AZURE_COMPONENTS = test_resource_paths.azure_components_tm7
35+
OTM_AZURE_COMPONENTS = test_resource_paths.azure_components_otm
36+
MTMT_SIMPLE_LINE_BOUNDARY = test_resource_paths.simple_line_boundary_tm7
37+
MTMT_MULTIPLE_TRUSTZONES_SAME_TYPE = test_resource_paths.multiple_trustzones_same_type_tm7
38+
MAPPING_MULTIPLE_TRUSTZONES_SAME_TYPE = test_resource_paths.multiple_trustzones_same_type_mapping
3439

3540
class TestMtmtProcessor:
3641
excluded_regex = [
@@ -172,3 +177,75 @@ def test_invalid_mapping_file_size(self, mappings: list[bytes]):
172177
assert 'Mapping files are not valid' == error.value.title
173178
assert 'Mapping files are not valid. Invalid size' == error.value.detail
174179
assert 'Mapping files are not valid. Invalid size' == error.value.message
180+
181+
def test_run_azure_components(self):
182+
# GIVEN a valid MTMT file with some resources
183+
source_file = get_byte_data(MTMT_AZURE_COMPONENTS)
184+
185+
# AND a valid MTMT mapping file
186+
mapping_file = get_byte_data(SAMPLE_VALID_MAPPING_FILE)
187+
188+
# WHEN the MTMT file is processed
189+
otm = MTMTProcessor(SAMPLE_ID, SAMPLE_NAME, source_file, [mapping_file]).process()
190+
191+
# THEN we check the result is as expected
192+
result, expected = validate_and_compare(otm.json(), OTM_AZURE_COMPONENTS, None)
193+
assert result == expected
194+
195+
def test_run_simple_line_boundary(self):
196+
# GIVEN a valid MTMT file with some resources
197+
source_file = get_byte_data(MTMT_SIMPLE_LINE_BOUNDARY)
198+
199+
# AND a valid MTMT mapping file
200+
mapping_file = get_byte_data(SAMPLE_VALID_MAPPING_FILE)
201+
202+
# WHEN the MTMT file is processed
203+
otm = MTMTProcessor(SAMPLE_ID, SAMPLE_NAME, source_file, [mapping_file]).process()
204+
205+
# THEN we check the result is as expected
206+
assert len(otm.trustzones) == 2
207+
assert otm.trustzones[0].id == 'ef4b8d94-ff80-419b-b590-b1a6aad88408'
208+
assert otm.trustzones[0].name == 'Generic Trust Line Boundary'
209+
assert otm.trustzones[0].type == 'b61d6911-338d-46a8-9f39-8dcd24abfe91'
210+
assert otm.trustzones[0].trustrating == 10
211+
assert otm.trustzones[1].id == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
212+
assert otm.trustzones[1].name == 'Default trustzone'
213+
assert otm.trustzones[1].type == 'b61d6911-338d-46a8-9f39-8dcd24abfe91'
214+
assert otm.trustzones[1].trustrating == 10
215+
assert otm.components[0].parent == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
216+
assert otm.components[1].parent == 'ef4b8d94-ff80-419b-b590-b1a6aad88408'
217+
assert otm.components[2].parent == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
218+
assert otm.components[3].parent == '185f1c6f-3879-464c-89c9-dc6f0b0c2b21'
219+
220+
def test_run_multiple_trustzones_same_type(self):
221+
# GIVEN a valid MTMT file with some resources
222+
source_file = get_byte_data(MTMT_MULTIPLE_TRUSTZONES_SAME_TYPE)
223+
224+
# AND a valid MTMT mapping file
225+
mapping_file = get_byte_data(MAPPING_MULTIPLE_TRUSTZONES_SAME_TYPE)
226+
227+
# WHEN the MTMT file is processed
228+
otm = MTMTProcessor(SAMPLE_ID, SAMPLE_NAME, source_file, [mapping_file]).process()
229+
230+
# THEN we check the result is as expected
231+
assert len(otm.trustzones) == 5
232+
assert otm.trustzones[0].id == '06de5005-eca7-41c8-8848-9d942dc7994d'
233+
assert otm.trustzones[0].name == 'Local User Zone'
234+
assert otm.trustzones[0].type == '2ab4effa-40b7-4cd2-ba81-8247d29a6f2d'
235+
assert otm.trustzones[0].trustrating == 10
236+
assert otm.trustzones[1].id == '1c5a9402-2016-4bc6-9861-9e7eaf725ae6'
237+
assert otm.trustzones[1].name == 'Azure Trust Boundary'
238+
assert otm.trustzones[1].type == '2ab4effa-40b7-4cd2-ba81-8247d29a6f2d'
239+
assert otm.trustzones[1].trustrating == 10
240+
assert otm.trustzones[2].id == '871dde5d-cd57-4436-a07d-a73f039511a2'
241+
assert otm.trustzones[2].name == 'Azure Trust Boundary'
242+
assert otm.trustzones[2].type == '2ab4effa-40b7-4cd2-ba81-8247d29a6f2d'
243+
assert otm.trustzones[2].trustrating == 10
244+
assert otm.trustzones[3].id == 'efb356d5-0b83-4b16-be28-0337c29a7d4a'
245+
assert otm.trustzones[3].name == 'Remote User Zone'
246+
assert otm.trustzones[3].type == 'f0ba7722-39b6-4c81-8290-a30a248bb8d9'
247+
assert otm.trustzones[3].trustrating == 10
248+
assert otm.trustzones[4].id == 'b39375e4-1903-4c20-bf8d-fbfdde6d2d77'
249+
assert otm.trustzones[4].name == 'Remote User Zone'
250+
assert otm.trustzones[4].type == 'f0ba7722-39b6-4c81-8290-a30a248bb8d9'
251+
assert otm.trustzones[4].trustrating == 10
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trustzones:
2+
3+
- label: Remote User Zone
4+
type: f0ba7722-39b6-4c81-8290-a30a248bb8d9
5+
6+
- label: Local User Zone
7+
type: 2ab4effa-40b7-4cd2-ba81-8247d29a6f2d
8+
9+
10+
- label: Azure Trust Boundary
11+
type: 2ab4effa-40b7-4cd2-ba81-8247d29a6f2d
12+
13+
14+
components: []
15+
16+
dataflows: []
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
{
2+
"otmVersion": "0.2.0",
3+
"project": {
4+
"id": "example-project",
5+
"name": "Example Project"
6+
},
7+
"representations": [
8+
{
9+
"id": "Microsoft Threat Modeling Tool",
10+
"name": "Microsoft Threat Modeling Tool",
11+
"type": "threat-model"
12+
},
13+
{
14+
"id": "example-project-diagram",
15+
"name": "example-project Diagram Representation",
16+
"size": {
17+
"height": 2000,
18+
"width": 2000
19+
},
20+
"type": "diagram"
21+
}
22+
],
23+
"trustZones": [
24+
{
25+
"attributes": {
26+
"Dataflow Order": "0",
27+
"Name": "The Public zone"
28+
},
29+
"id": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374",
30+
"name": "The Public zone",
31+
"representations": [
32+
{
33+
"id": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374-representation",
34+
"name": "The Public zone Representation",
35+
"position": {
36+
"x": 60,
37+
"y": 26
38+
},
39+
"representation": "example-project-diagram",
40+
"size": {
41+
"height": 430,
42+
"width": 1243
43+
}
44+
}
45+
],
46+
"risk": {
47+
"trustRating": 10
48+
},
49+
"type": "b61d6911-338d-46a8-9f39-8dcd24abfe91"
50+
}
51+
],
52+
"components": [
53+
{
54+
"attributes": {
55+
"Azure Postgres DB Firewall Settings": "Select",
56+
"Azure Postgres DB TLS Enforced": "Select",
57+
"Name": "Azure Database for PostgreSQL",
58+
"Out Of Scope": "false"
59+
},
60+
"id": "81b54eb4-e007-4682-ac6f-fa75d3b8a19d",
61+
"name": "Azure Database for PostgreSQL",
62+
"parent": {
63+
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
64+
},
65+
"representations": [
66+
{
67+
"id": "81b54eb4-e007-4682-ac6f-fa75d3b8a19d-representation",
68+
"name": "Azure Database for PostgreSQL Representation",
69+
"position": {
70+
"x": 934,
71+
"y": 45
72+
},
73+
"representation": "example-project-diagram",
74+
"size": {
75+
"height": 82,
76+
"width": 82
77+
}
78+
}
79+
],
80+
"type": "CD-MICROSOFT-AZURE-DB-POSTGRESQL"
81+
},
82+
{
83+
"attributes": {
84+
"CORS Enabled": "Select",
85+
"HTTPS Enforced": "Select",
86+
"Name": "Azure Storage",
87+
"Network Security": "Select",
88+
"Out Of Scope": "false",
89+
"Storage Type": "Select"
90+
},
91+
"id": "df895836-af23-4033-ab75-81352301e4ce",
92+
"name": "Azure Storage",
93+
"parent": {
94+
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
95+
},
96+
"representations": [
97+
{
98+
"id": "df895836-af23-4033-ab75-81352301e4ce-representation",
99+
"name": "Azure Storage Representation",
100+
"position": {
101+
"x": 301,
102+
"y": 162
103+
},
104+
"representation": "example-project-diagram",
105+
"size": {
106+
"height": 82,
107+
"width": 82
108+
}
109+
}
110+
],
111+
"type": "azure-storage"
112+
},
113+
{
114+
"attributes": {
115+
"Mobile Client Technologies": "Android",
116+
"Name": "Mobile Client - Android",
117+
"Out Of Scope": "false"
118+
},
119+
"id": "ab94757b-4722-403f-8e9d-425edd5343ee",
120+
"name": "Mobile Client - Android",
121+
"parent": {
122+
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
123+
},
124+
"representations": [
125+
{
126+
"id": "ab94757b-4722-403f-8e9d-425edd5343ee-representation",
127+
"name": "Mobile Client - Android Representation",
128+
"position": {
129+
"x": 45,
130+
"y": 281
131+
},
132+
"representation": "example-project-diagram",
133+
"size": {
134+
"height": 82,
135+
"width": 82
136+
}
137+
}
138+
],
139+
"type": "android-device-client"
140+
},
141+
{
142+
"attributes": {
143+
"Mobile Client Technologies": "iOS",
144+
"Name": "Mobile Client - iOS",
145+
"Out Of Scope": "false"
146+
},
147+
"id": "ff0709b7-7d68-4c6f-a2d3-6c2ad01cf448",
148+
"name": "Mobile Client - iOS",
149+
"parent": {
150+
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
151+
},
152+
"representations": [
153+
{
154+
"id": "ff0709b7-7d68-4c6f-a2d3-6c2ad01cf448-representation",
155+
"name": "Mobile Client - iOS Representation",
156+
"position": {
157+
"x": 177,
158+
"y": 284
159+
},
160+
"representation": "example-project-diagram",
161+
"size": {
162+
"height": 82,
163+
"width": 82
164+
}
165+
}
166+
],
167+
"type": "ios-device-client"
168+
},
169+
{
170+
"attributes": {
171+
"Hosting environment": "Select",
172+
"Identity Provider": "Select",
173+
"Name": "Web API - RESTful",
174+
"Out Of Scope": "false",
175+
"Web API Technologies": "Select"
176+
},
177+
"id": "977581d7-5176-4f6e-875d-be5ca87fe2e5",
178+
"name": "Web API - RESTful",
179+
"parent": {
180+
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
181+
},
182+
"representations": [
183+
{
184+
"id": "977581d7-5176-4f6e-875d-be5ca87fe2e5-representation",
185+
"name": "Web API - RESTful Representation",
186+
"position": {
187+
"x": 299,
188+
"y": 286
189+
},
190+
"representation": "example-project-diagram",
191+
"size": {
192+
"height": 82,
193+
"width": 82
194+
}
195+
}
196+
],
197+
"type": "web-service"
198+
},
199+
{
200+
"attributes": {
201+
"Hosting environment": "Select",
202+
"Identity Provider": "Select",
203+
"Name": "Web API - SOAP",
204+
"Out Of Scope": "false",
205+
"Web API Technologies": "Select"
206+
},
207+
"id": "fe3b51b9-cddc-4758-91f0-5fe05a1a1387",
208+
"name": "Web API - SOAP",
209+
"parent": {
210+
"trustZone": "ae3b78bb-48d0-4ee2-a465-9e0d17f4d374"
211+
},
212+
"representations": [
213+
{
214+
"id": "fe3b51b9-cddc-4758-91f0-5fe05a1a1387-representation",
215+
"name": "Web API - SOAP Representation",
216+
"position": {
217+
"x": 417,
218+
"y": 289
219+
},
220+
"representation": "example-project-diagram",
221+
"size": {
222+
"height": 82,
223+
"width": 82
224+
}
225+
}
226+
],
227+
"type": "web-service"
228+
}
229+
],
230+
"dataflows": []
231+
}

slp_mtmt/tests/resources/mtmt/mtmt-azure-tm-template-components-default-mapping.tm7

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

slp_mtmt/tests/resources/mtmt/multiple_trustzones_same_type.tm7

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

slp_mtmt/tests/resources/test_resource_paths.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
mtmt_mapping_invalid_no_dataflows = f'{path}/mapping/invalid-mapping-without-dataflows.yaml'
2121
name_mapping_overriden = f'{path}/mapping/name_mapping_overriden.yaml'
2222
type_mapping_overriden = f'{path}/mapping/type_mapping_overriden.yaml'
23+
multiple_trustzones_same_type_mapping = f'{path}/mapping/multiple-trustzones-same-type.yaml'
2324

2425

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

5054
# OTM
5155
example_position_otm = f'{path}/mtmt/MTMT_example_coordinates.otm'
@@ -57,4 +61,4 @@
5761
nested_trustzones_line_otm = f'{path}/otm/nested_tz_line.otm'
5862
model_mtmt_source_file_otm = f'{path}/otm/test_model_tm7.otm'
5963
unmapped_trustzones_otm = f'{path}/mtmt/mtmt-resources-SDL-knowledge-base-components.otm'
60-
64+
azure_components_otm = f'{path}/mtmt/mtmt-azure-tm-template-components-default-mapping.otm'

0 commit comments

Comments
 (0)