matlab-proxy 0.26.0__py3-none-any.whl → 0.27.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of matlab-proxy might be problematic. Click here for more details.
- matlab_proxy/app.py +50 -39
- matlab_proxy/app_state.py +9 -3
- matlab_proxy/default_configuration.py +2 -2
- matlab_proxy/gui/index.html +2 -2
- matlab_proxy/gui/static/css/{index.BSVLACuY.css → index.BLxKpbak.css} +2 -2
- matlab_proxy/gui/static/js/{index.CZgGkMCD.js → index.CKi3IRxe.js} +16 -16
- matlab_proxy/settings.py +5 -5
- matlab_proxy/util/__init__.py +2 -2
- matlab_proxy/util/list_servers.py +2 -2
- matlab_proxy/util/mwi/environment_variables.py +5 -0
- matlab_proxy/util/mwi/logger.py +1 -2
- matlab_proxy/util/mwi/session_name.py +28 -0
- matlab_proxy/util/mwi/token_auth.py +2 -2
- matlab_proxy/util/mwi/validators.py +3 -5
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/METADATA +37 -25
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/RECORD +23 -53
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/WHEEL +1 -2
- matlab_proxy_manager/README.md +85 -0
- matlab_proxy_manager/lib/README.md +53 -0
- matlab_proxy_manager/storage/README.md +54 -0
- matlab_proxy_manager/web/README.md +37 -0
- matlab_proxy-0.26.0.dist-info/top_level.txt +0 -3
- tests/integration/__init__.py +0 -1
- tests/integration/integration_tests_with_license/__init__.py +0 -1
- tests/integration/integration_tests_with_license/conftest.py +0 -47
- tests/integration/integration_tests_with_license/test_http_end_points.py +0 -397
- tests/integration/integration_tests_without_license/__init__.py +0 -1
- tests/integration/integration_tests_without_license/conftest.py +0 -116
- tests/integration/integration_tests_without_license/test_matlab_is_down_if_unlicensed.py +0 -49
- tests/integration/utils/__init__.py +0 -1
- tests/integration/utils/integration_tests_utils.py +0 -352
- tests/integration/utils/licensing.py +0 -152
- tests/unit/__init__.py +0 -1
- tests/unit/conftest.py +0 -66
- tests/unit/test_app.py +0 -1299
- tests/unit/test_app_state.py +0 -1094
- tests/unit/test_constants.py +0 -7
- tests/unit/test_ddux.py +0 -22
- tests/unit/test_devel.py +0 -246
- tests/unit/test_non_dev_mode.py +0 -169
- tests/unit/test_settings.py +0 -679
- tests/unit/util/__init__.py +0 -3
- tests/unit/util/mwi/__init__.py +0 -1
- tests/unit/util/mwi/embedded_connector/__init__.py +0 -1
- tests/unit/util/mwi/embedded_connector/test_helpers.py +0 -29
- tests/unit/util/mwi/embedded_connector/test_request.py +0 -64
- tests/unit/util/mwi/test_custom_http_headers.py +0 -281
- tests/unit/util/mwi/test_download.py +0 -152
- tests/unit/util/mwi/test_logger.py +0 -82
- tests/unit/util/mwi/test_token_auth.py +0 -303
- tests/unit/util/mwi/test_validators.py +0 -364
- tests/unit/util/test_cookie_jar.py +0 -252
- tests/unit/util/test_mw.py +0 -550
- tests/unit/util/test_util.py +0 -221
- tests/utils/__init__.py +0 -1
- tests/utils/logging_util.py +0 -81
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/entry_points.txt +0 -0
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info/licenses}/LICENSE.md +0 -0
tests/unit/test_settings.py
DELETED
|
@@ -1,679 +0,0 @@
|
|
|
1
|
-
# Copyright 2020-2025 The MathWorks, Inc.
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import tempfile
|
|
5
|
-
import time
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
|
|
8
|
-
import pytest
|
|
9
|
-
|
|
10
|
-
import matlab_proxy
|
|
11
|
-
import matlab_proxy.settings as settings
|
|
12
|
-
from matlab_proxy.constants import DEFAULT_PROCESS_START_TIMEOUT, VERSION_INFO_FILE_NAME
|
|
13
|
-
from matlab_proxy.util.cookie_jar import HttpOnlyCookieJar
|
|
14
|
-
from matlab_proxy.util.mwi import environment_variables as mwi_env
|
|
15
|
-
from matlab_proxy.util.mwi.exceptions import MatlabInstallError
|
|
16
|
-
|
|
17
|
-
"""This file tests methods defined in settings.py file
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def version_info_file_content(matlab_version):
|
|
22
|
-
"""Returns contents of VersionInfo.xml file for a specific matlab_version
|
|
23
|
-
|
|
24
|
-
Args:
|
|
25
|
-
matlab_version (str): MATLAB Version
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
str: Contents of VersionInfo.xml file for a specific matlab version
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
"""
|
|
32
|
-
Returns the contents of a valid VersionInfo.xml file
|
|
33
|
-
"""
|
|
34
|
-
return f"""<!-- Version information for MathWorks R2020b Release -->
|
|
35
|
-
<MathWorks_version_info>
|
|
36
|
-
<version>9.9.0.1524771</version>
|
|
37
|
-
<release>{matlab_version}</release>
|
|
38
|
-
<description>Update 2</description>
|
|
39
|
-
<date>Nov 03 2020</date>
|
|
40
|
-
<checksum>2207788044</checksum>
|
|
41
|
-
</MathWorks_version_info>
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@pytest.fixture(name="fake_matlab_empty_root_path")
|
|
46
|
-
def fake_matlab_empty_root_path_fixture(tmp_path):
|
|
47
|
-
empty_matlab_root = tmp_path / "R2020b"
|
|
48
|
-
os.makedirs(empty_matlab_root, exist_ok=True)
|
|
49
|
-
return empty_matlab_root
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@pytest.fixture(name="fake_matlab_executable_path")
|
|
53
|
-
def fake_matlab_executable_path_fixture(fake_matlab_empty_root_path):
|
|
54
|
-
matlab_executable_path = fake_matlab_empty_root_path / "bin" / "matlab"
|
|
55
|
-
os.makedirs(matlab_executable_path, exist_ok=True)
|
|
56
|
-
|
|
57
|
-
return matlab_executable_path
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def create_file(file_path, file_content):
|
|
61
|
-
with open(file_path, "w") as f:
|
|
62
|
-
f.write(file_content)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@pytest.fixture(name="fake_matlab_valid_version_info_file_path")
|
|
66
|
-
def fake_matlab_valid_version_info_file_path_fixture(fake_matlab_empty_root_path):
|
|
67
|
-
version_info_file_path = fake_matlab_empty_root_path / VERSION_INFO_FILE_NAME
|
|
68
|
-
create_file(version_info_file_path, version_info_file_content("R2020b"))
|
|
69
|
-
|
|
70
|
-
return version_info_file_path
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
@pytest.fixture(name="fake_matlab_root_path")
|
|
74
|
-
def fake_matlab_root_path_fixture(
|
|
75
|
-
fake_matlab_executable_path, fake_matlab_valid_version_info_file_path
|
|
76
|
-
):
|
|
77
|
-
"""Pytest fixture to create a fake matlab installation path.
|
|
78
|
-
|
|
79
|
-
Args:
|
|
80
|
-
fake_matlab_executable_path (Pytest fixture): Pytest fixture which returns path to a fake matlab executable
|
|
81
|
-
fake_matlab_valid_version_info_file_path (Pytest fixture): Pytest fixture which returns path of a VersionInfo.xml file for a fake matlab
|
|
82
|
-
|
|
83
|
-
Returns:
|
|
84
|
-
pathlib.Path: Path to a fake matlab root
|
|
85
|
-
"""
|
|
86
|
-
|
|
87
|
-
return fake_matlab_executable_path.parent.parent
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
@pytest.fixture(name="mock_shutil_which_none")
|
|
91
|
-
def mock_shutil_which_none_fixture(mocker):
|
|
92
|
-
"""Pytest fixture to mock shutil.which() method to return None
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
mocker : Built in pytest fixture
|
|
96
|
-
"""
|
|
97
|
-
mocker.patch("shutil.which", return_value=None)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def test_get_matlab_root_path_none(mock_shutil_which_none):
|
|
101
|
-
"""Test to check if settings.get_matlab_path() returns none when no matlab installation is present.
|
|
102
|
-
|
|
103
|
-
mock_shutil_which_none fixture mocks shutil.which() to return None
|
|
104
|
-
|
|
105
|
-
Args:
|
|
106
|
-
mock_shutil_which_none : Pytest fixture to mock shutil.which() method to return None.
|
|
107
|
-
"""
|
|
108
|
-
with pytest.raises(MatlabInstallError) as e:
|
|
109
|
-
_ = settings.get_matlab_executable_and_root_path()
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
@pytest.fixture(name="mock_shutil_which")
|
|
113
|
-
def mock_shutil_which_fixture(mocker, fake_matlab_executable_path):
|
|
114
|
-
"""Pytest fixture to mock shutil.which() method to return a temporary fake matlab path
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
mocker : Built in pytest fixture
|
|
118
|
-
fake_matlab_executable_path : Pytest fixture which returns path to fake matlab executable file
|
|
119
|
-
"""
|
|
120
|
-
mocker.patch("shutil.which", return_value=fake_matlab_executable_path)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
@pytest.fixture(name="non_existent_path")
|
|
124
|
-
def non_existent_path_fixture(tmp_path):
|
|
125
|
-
# Build path to a non existent folder
|
|
126
|
-
random_folder = tmp_path / f"{str(time.time()).replace('.', '')}"
|
|
127
|
-
non_existent_path = Path(tmp_path) / random_folder
|
|
128
|
-
|
|
129
|
-
return non_existent_path
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def test_get_matlab_root_path(fake_matlab_root_path, mock_shutil_which):
|
|
133
|
-
"""Test to check if a valid matlab path is returned
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
mock_shutil_which fixture mocks shutil.which() method to return a temporary path.
|
|
137
|
-
|
|
138
|
-
Args:
|
|
139
|
-
fake_matlab_executable_path : Pytest fixture which returns a path to fake matlab executable
|
|
140
|
-
mock_shutil_which : Pytest fixture to mock shutil.which() method to return a fake matlab path
|
|
141
|
-
"""
|
|
142
|
-
assert settings.get_matlab_executable_and_root_path()[1] == fake_matlab_root_path
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def test_get_matlab_root_path_invalid_custom_matlab_root(
|
|
146
|
-
monkeypatch, non_existent_path
|
|
147
|
-
):
|
|
148
|
-
# Monkeypatch the env var
|
|
149
|
-
monkeypatch.setenv(
|
|
150
|
-
mwi_env.get_env_name_custom_matlab_root(), str(non_existent_path)
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
# Test for appropriate error
|
|
154
|
-
with pytest.raises(MatlabInstallError) as e:
|
|
155
|
-
_ = settings.get_matlab_executable_and_root_path()
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def test_get_matlab_version_none():
|
|
159
|
-
"""Test to check settings.get_matlab_version() returns None when no valid matlab path is provided."""
|
|
160
|
-
assert settings.get_matlab_version(None) is None
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def test_get_matlab_version(fake_matlab_root_path, mock_shutil_which):
|
|
164
|
-
"""Test if a matlab version is returned when from a Version.xml file.
|
|
165
|
-
|
|
166
|
-
mock_shutil_which fixture will mock the settings.get_matlab_path() to return a fake matlab path
|
|
167
|
-
which containing a valid VersionInfo.xml file. settings.get_matlab_version() will extract the matlab version
|
|
168
|
-
from this file
|
|
169
|
-
|
|
170
|
-
Args:
|
|
171
|
-
mock_shutil_which : Pytest fixture to mock shutil.which() method.
|
|
172
|
-
"""
|
|
173
|
-
(
|
|
174
|
-
matlab_executable_path,
|
|
175
|
-
matlab_root_path,
|
|
176
|
-
) = settings.get_matlab_executable_and_root_path()
|
|
177
|
-
settings.get_matlab_version(matlab_root_path) is not None
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
def test_get_matlab_version_invalid_custom_matlab_root(monkeypatch, non_existent_path):
|
|
181
|
-
# Monkeypatch the env var
|
|
182
|
-
monkeypatch.setenv(
|
|
183
|
-
mwi_env.get_env_name_custom_matlab_root(), str(non_existent_path)
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
assert settings.get_matlab_version(None) is None
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def test_get_matlab_version_valid_custom_matlab_root(non_existent_path, monkeypatch):
|
|
190
|
-
"""Test matlab version when a custom matlab root path is supplied
|
|
191
|
-
|
|
192
|
-
Args:
|
|
193
|
-
tmp_path : Built-in pytest fixture
|
|
194
|
-
monkeypatch : Built-in pytest fixture m
|
|
195
|
-
"""
|
|
196
|
-
custom_matlab_root_path = non_existent_path
|
|
197
|
-
os.makedirs(custom_matlab_root_path, exist_ok=True)
|
|
198
|
-
matlab_version = "R2020b"
|
|
199
|
-
|
|
200
|
-
# Create a valid VersionInfo.xml file at custom matlab root
|
|
201
|
-
version_info_file_path = custom_matlab_root_path / VERSION_INFO_FILE_NAME
|
|
202
|
-
create_file(version_info_file_path, version_info_file_content(matlab_version))
|
|
203
|
-
|
|
204
|
-
# Monkeypatch the env var
|
|
205
|
-
monkeypatch.setenv(
|
|
206
|
-
mwi_env.get_env_name_custom_matlab_root(), str(custom_matlab_root_path)
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
actual_matlab_version = settings.get_matlab_version(custom_matlab_root_path)
|
|
210
|
-
|
|
211
|
-
assert actual_matlab_version == matlab_version
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
@pytest.mark.parametrize(
|
|
215
|
-
"matlab_version", ["R2020b", "R2021a"], ids=["R2020b", "R2021a"]
|
|
216
|
-
)
|
|
217
|
-
def test_settings_get_matlab_cmd_for_different_matlab_versions(
|
|
218
|
-
matlab_version, non_existent_path, monkeypatch
|
|
219
|
-
):
|
|
220
|
-
"""Test to check settings.get returns the correct matlab_cmd when MWI_CUSTOM_MATLAB_ROOT is set.
|
|
221
|
-
|
|
222
|
-
Args:
|
|
223
|
-
matlab_version (str): Matlab version
|
|
224
|
-
non_existent_path (Pytest fixture): Pytest fixture which returns a temporary non-existent path
|
|
225
|
-
monkeypatch (Builtin pytest fixture): Pytest fixture to monkeypatch environment variables.
|
|
226
|
-
"""
|
|
227
|
-
|
|
228
|
-
# Create custom matlab root for specific matlab_version
|
|
229
|
-
custom_matlab_root_path = non_existent_path / matlab_version
|
|
230
|
-
os.makedirs(custom_matlab_root_path, exist_ok=True)
|
|
231
|
-
|
|
232
|
-
# Create a valid VersionInfo.xml file at custom matlab root
|
|
233
|
-
version_info_file_path = custom_matlab_root_path / VERSION_INFO_FILE_NAME
|
|
234
|
-
create_file(version_info_file_path, version_info_file_content(matlab_version))
|
|
235
|
-
|
|
236
|
-
monkeypatch.setenv(
|
|
237
|
-
mwi_env.get_env_name_custom_matlab_root(), str(custom_matlab_root_path)
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
# Assert matlab_version is in path to matlab_cmd
|
|
241
|
-
sett = settings.get(dev=False)
|
|
242
|
-
assert matlab_version in str(sett["matlab_cmd"][0])
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
def test_get_dev_true():
|
|
246
|
-
"""Test to check settings returned by settings.get() method in dev mode."""
|
|
247
|
-
dev_mode_settings = settings.get(dev=True)
|
|
248
|
-
|
|
249
|
-
assert dev_mode_settings["matlab_cmd"][0] != "matlab"
|
|
250
|
-
assert dev_mode_settings["matlab_protocol"] == "http"
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
@pytest.fixture(name="patch_env_variables")
|
|
254
|
-
def patch_env_variables_fixture(monkeypatch):
|
|
255
|
-
"""Pytest fixture to Monkeypatch MWI_APP_PORT, BASE_URL, APP_HOST AND MLM_LICENSE_FILE env variables
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
Args:
|
|
259
|
-
monkeypatch : Built-in pytest fixture
|
|
260
|
-
"""
|
|
261
|
-
monkeypatch.setenv(mwi_env.get_env_name_base_url(), "/matlab")
|
|
262
|
-
monkeypatch.setenv(mwi_env.get_env_name_app_port(), "8900")
|
|
263
|
-
monkeypatch.setenv(mwi_env.get_env_name_app_host(), "localhost")
|
|
264
|
-
monkeypatch.setenv(mwi_env.get_env_name_network_license_manager(), "123@nlm")
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
def test_get_dev_false(patch_env_variables, mock_shutil_which, fake_matlab_root_path):
|
|
268
|
-
"""Test settings.get() method in Non Dev mode.
|
|
269
|
-
|
|
270
|
-
In Non dev mode, settings.get() expects MWI_APP_PORT, MWI_BASE_URL, APP_HOST AND MLM_LICENSE_FILE env variables
|
|
271
|
-
to be present. patch_env_variables monkeypatches them.
|
|
272
|
-
|
|
273
|
-
Args:
|
|
274
|
-
patch_env_variables : Pytest fixture which monkeypatches some env variables.
|
|
275
|
-
"""
|
|
276
|
-
_settings = settings.get(dev=False)
|
|
277
|
-
assert "matlab" in str(_settings["matlab_cmd"][0])
|
|
278
|
-
assert os.path.isdir(_settings["matlab_path"])
|
|
279
|
-
assert _settings["matlab_protocol"] == "https"
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
def test_get_mw_context_tags(monkeypatch):
|
|
283
|
-
"""Tests get_mw_context_tags() function to return appropriate MW_CONTEXT_TAGS"""
|
|
284
|
-
|
|
285
|
-
# Monkeypatch env var MW_CONTEXT_TAGS to check for if condition
|
|
286
|
-
dockerhub_mw_context_tags = "MATLAB:DOCKERHUB:V1"
|
|
287
|
-
monkeypatch.setenv("MW_CONTEXT_TAGS", dockerhub_mw_context_tags)
|
|
288
|
-
|
|
289
|
-
extension_name = matlab_proxy.get_default_config_name()
|
|
290
|
-
|
|
291
|
-
matlab_proxy_base_context_tags = matlab_proxy.get_mwi_ddux_value(extension_name)
|
|
292
|
-
expected_result = f"{dockerhub_mw_context_tags},{matlab_proxy_base_context_tags}"
|
|
293
|
-
|
|
294
|
-
actual_result = settings.get_mw_context_tags(extension_name)
|
|
295
|
-
|
|
296
|
-
assert expected_result == actual_result
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
@pytest.mark.parametrize(
|
|
300
|
-
"timeout_value",
|
|
301
|
-
[
|
|
302
|
-
(130, 130),
|
|
303
|
-
("asdf", DEFAULT_PROCESS_START_TIMEOUT),
|
|
304
|
-
(120.5, DEFAULT_PROCESS_START_TIMEOUT),
|
|
305
|
-
(None, DEFAULT_PROCESS_START_TIMEOUT),
|
|
306
|
-
],
|
|
307
|
-
ids=["Valid number", "Invalid number", "Valid decimal number", "No value supplied"],
|
|
308
|
-
)
|
|
309
|
-
def test_get_process_timeout(timeout_value, monkeypatch):
|
|
310
|
-
"""Parameterized test to check settings.test_get_process_timeout returns the correct timeout value when MWI_PROCESS_STARTUP_TIMEOUT is set.
|
|
311
|
-
|
|
312
|
-
Args:
|
|
313
|
-
timeout (str): Timeout for processes launched by matlab-proxy
|
|
314
|
-
monkeypatch (Builtin pytest fixture): Pytest fixture to monkeypatch environment variables.
|
|
315
|
-
"""
|
|
316
|
-
# Arrange
|
|
317
|
-
supplied_timeout, expected_timeout = timeout_value[0], timeout_value[1]
|
|
318
|
-
|
|
319
|
-
# pytest would throw warnings if None is supplied to monkeypatch
|
|
320
|
-
if supplied_timeout:
|
|
321
|
-
monkeypatch.setenv(
|
|
322
|
-
mwi_env.get_env_name_process_startup_timeout(), str(supplied_timeout)
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
# Act
|
|
326
|
-
actual_timeout = settings.get_process_startup_timeout()
|
|
327
|
-
|
|
328
|
-
# Assert
|
|
329
|
-
assert expected_timeout == actual_timeout
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
def test_get_mwi_config_folder_dev():
|
|
333
|
-
## Arrange
|
|
334
|
-
expected_config_dir = Path(tempfile.gettempdir()) / "MWI" / "tests"
|
|
335
|
-
|
|
336
|
-
# Act
|
|
337
|
-
actual_config_dir = settings.get_mwi_config_folder(dev=True)
|
|
338
|
-
|
|
339
|
-
# Assert
|
|
340
|
-
assert expected_config_dir == actual_config_dir
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
@pytest.mark.parametrize(
|
|
344
|
-
"hostname, home, expected_mwi_config_dir",
|
|
345
|
-
[
|
|
346
|
-
(
|
|
347
|
-
"bob",
|
|
348
|
-
Path("/home/bob"),
|
|
349
|
-
Path("/home/bob") / ".matlab" / "MWI" / "hosts" / "bob",
|
|
350
|
-
),
|
|
351
|
-
(
|
|
352
|
-
"bob",
|
|
353
|
-
Path("/home/CommonProject"),
|
|
354
|
-
Path("/home/CommonProject") / ".matlab" / "MWI" / "hosts" / "bob",
|
|
355
|
-
),
|
|
356
|
-
(
|
|
357
|
-
None,
|
|
358
|
-
Path("/home/CommonProject"),
|
|
359
|
-
Path("/home/CommonProject") / ".matlab" / "MWI",
|
|
360
|
-
),
|
|
361
|
-
],
|
|
362
|
-
ids=[
|
|
363
|
-
"Single host machine with unique $HOME per host",
|
|
364
|
-
"Multi-host machine with common $HOME for multiple hosts",
|
|
365
|
-
"default directory when hostname is missing",
|
|
366
|
-
],
|
|
367
|
-
)
|
|
368
|
-
def test_get_mwi_config_folder(mocker, hostname, home, expected_mwi_config_dir):
|
|
369
|
-
# Arrange
|
|
370
|
-
mocker.patch("matlab_proxy.settings.Path.home", return_value=home)
|
|
371
|
-
mocker.patch("matlab_proxy.settings.socket.gethostname", return_value=hostname)
|
|
372
|
-
|
|
373
|
-
# Act
|
|
374
|
-
actual_config_dir = settings.get_mwi_config_folder()
|
|
375
|
-
|
|
376
|
-
# Assert
|
|
377
|
-
assert expected_mwi_config_dir == actual_config_dir
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
def test_get_ssl_context_with_SSL_disabled(monkeypatch, tmpdir):
|
|
381
|
-
monkeypatch.setenv(mwi_env.get_env_name_enable_ssl(), "False")
|
|
382
|
-
mwi_certs_dir = Path(tmpdir)
|
|
383
|
-
ssl_context = settings._validate_ssl_files_and_get_ssl_context(mwi_certs_dir)
|
|
384
|
-
assert ssl_context is None
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
def test_get_ssl_context_with_SSL_enabled_auto_generated_certs(
|
|
388
|
-
monkeypatch, mocker, tmpdir
|
|
389
|
-
):
|
|
390
|
-
monkeypatch.setenv(mwi_env.get_env_name_enable_ssl(), "True")
|
|
391
|
-
mocker.patch(
|
|
392
|
-
"matlab_proxy.settings.generate_new_self_signed_certs",
|
|
393
|
-
return_value=("cert_path", "key_path"),
|
|
394
|
-
)
|
|
395
|
-
mock_ssl_context = mocker.patch("ssl.create_default_context")
|
|
396
|
-
mock_context = mocker.Mock()
|
|
397
|
-
mock_ssl_context.return_value = mock_context
|
|
398
|
-
mock_context.load_cert_chain.side_effect = None
|
|
399
|
-
mwi_certs_dir = Path(tmpdir)
|
|
400
|
-
|
|
401
|
-
ssl_context = settings._validate_ssl_files_and_get_ssl_context(mwi_certs_dir)
|
|
402
|
-
assert ssl_context is not None
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
def test_get_ssl_context_with_invalid_self_signed_certs_returns_none(mocker, tmpdir):
|
|
406
|
-
mocker.patch(
|
|
407
|
-
"matlab_proxy.settings.generate_new_self_signed_certs",
|
|
408
|
-
return_value=("cert_path", "key_path"),
|
|
409
|
-
)
|
|
410
|
-
mock_ssl_context = mocker.patch("ssl.create_default_context")
|
|
411
|
-
mock_context = mocker.Mock()
|
|
412
|
-
mock_ssl_context.return_value = mock_context
|
|
413
|
-
exception_msg = "Invalid certificate!"
|
|
414
|
-
mock_context.load_cert_chain.side_effect = Exception(exception_msg)
|
|
415
|
-
mwi_certs_dir = Path(tmpdir)
|
|
416
|
-
|
|
417
|
-
assert settings._validate_ssl_files_and_get_ssl_context(mwi_certs_dir) is None
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
def test_get_ssl_context_with_valid_custom_ssl_files(monkeypatch, mocker, tmpdir):
|
|
421
|
-
# Sets up the SUT
|
|
422
|
-
monkeypatch.setenv(mwi_env.get_env_name_enable_ssl(), "True")
|
|
423
|
-
monkeypatch.setenv(mwi_env.get_env_name_ssl_cert_file(), "test/cert.pem")
|
|
424
|
-
monkeypatch.setenv(mwi_env.get_env_name_ssl_key_file(), "test/key.pem")
|
|
425
|
-
mocker.patch(
|
|
426
|
-
"matlab_proxy.settings.mwi.validators.validate_ssl_key_and_cert_file",
|
|
427
|
-
return_value=("test/cert.pem", "test/key.pem"),
|
|
428
|
-
)
|
|
429
|
-
new_cert_fx = mocker.patch("matlab_proxy.settings.generate_new_self_signed_certs")
|
|
430
|
-
mock_ssl_context = mocker.patch("ssl.create_default_context")
|
|
431
|
-
mock_context = mocker.Mock()
|
|
432
|
-
mock_ssl_context.return_value = mock_context
|
|
433
|
-
mock_context.load_cert_chain.side_effect = None
|
|
434
|
-
mwi_certs_dir = Path(tmpdir)
|
|
435
|
-
|
|
436
|
-
ssl_context = settings._validate_ssl_files_and_get_ssl_context(mwi_certs_dir)
|
|
437
|
-
# Checks that self-signed certificate generation is not happening when user supplies valid ssl files
|
|
438
|
-
new_cert_fx.assert_not_called()
|
|
439
|
-
assert ssl_context is not None
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
def test_get_ssl_context_with_invalid_custom_ssl_files_raises_exception(
|
|
443
|
-
monkeypatch, mocker, tmpdir
|
|
444
|
-
):
|
|
445
|
-
# Sets up the SUT
|
|
446
|
-
monkeypatch.setenv(mwi_env.get_env_name_enable_ssl(), "True")
|
|
447
|
-
monkeypatch.setenv(mwi_env.get_env_name_ssl_cert_file(), "test/cert.pem")
|
|
448
|
-
monkeypatch.setenv(mwi_env.get_env_name_ssl_key_file(), "test/key.pem")
|
|
449
|
-
mocker.patch(
|
|
450
|
-
"matlab_proxy.settings.mwi.validators.validate_ssl_key_and_cert_file",
|
|
451
|
-
return_value=("test/cert.pem", "test/key.pem"),
|
|
452
|
-
)
|
|
453
|
-
mock_ssl_context = mocker.patch("ssl.create_default_context")
|
|
454
|
-
mock_context = mocker.Mock()
|
|
455
|
-
mock_ssl_context.return_value = mock_context
|
|
456
|
-
exception_msg = "Invalid certificate!"
|
|
457
|
-
mock_context.load_cert_chain.side_effect = Exception(exception_msg)
|
|
458
|
-
mwi_certs_dir = Path(tmpdir)
|
|
459
|
-
|
|
460
|
-
with pytest.raises(Exception, match=exception_msg):
|
|
461
|
-
settings._validate_ssl_files_and_get_ssl_context(mwi_certs_dir)
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
@pytest.mark.parametrize(
|
|
465
|
-
"expected_value_for_has_custom_code, custom_code, has_custom_code_exception_matlab_cmd",
|
|
466
|
-
[(False, "", False), (True, "run(disp('MATLAB'))", True)],
|
|
467
|
-
ids=["No custom code to execute", "Has custom code to execute"],
|
|
468
|
-
)
|
|
469
|
-
def test_get_matlab_settings_custom_code(
|
|
470
|
-
monkeypatch,
|
|
471
|
-
expected_value_for_has_custom_code,
|
|
472
|
-
custom_code,
|
|
473
|
-
has_custom_code_exception_matlab_cmd,
|
|
474
|
-
):
|
|
475
|
-
# Arrange
|
|
476
|
-
monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_code(), custom_code)
|
|
477
|
-
|
|
478
|
-
# Act
|
|
479
|
-
has_custom_code, code_to_execute = settings._get_matlab_code_to_execute()
|
|
480
|
-
exception_present_in_matlab_cmd = "MATLABCustomStartupCodeError" in code_to_execute
|
|
481
|
-
|
|
482
|
-
# Assert
|
|
483
|
-
assert has_custom_code == expected_value_for_has_custom_code
|
|
484
|
-
assert exception_present_in_matlab_cmd == has_custom_code_exception_matlab_cmd
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
def test_get_nlm_conn_str(monkeypatch):
|
|
488
|
-
# Arrange
|
|
489
|
-
test_nlm_str = "123@license_server_address"
|
|
490
|
-
monkeypatch.setenv(mwi_env.get_env_name_network_license_manager(), test_nlm_str)
|
|
491
|
-
|
|
492
|
-
# Act
|
|
493
|
-
nlm_conn_str = settings._get_nlm_conn_str()
|
|
494
|
-
|
|
495
|
-
# Assert
|
|
496
|
-
assert nlm_conn_str == test_nlm_str
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
@pytest.mark.parametrize("ws_env_suffix", ["", "-dev", "-test"])
|
|
500
|
-
def test_get_mw_licensing_urls(ws_env_suffix):
|
|
501
|
-
# Act
|
|
502
|
-
urls = settings._get_mw_licensing_urls(ws_env_suffix)
|
|
503
|
-
|
|
504
|
-
# Assert
|
|
505
|
-
assert all(ws_env_suffix in url for url in urls.values())
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
@pytest.mark.parametrize("nlm_conn_str", [None, "1234@testserver"])
|
|
509
|
-
def test_get_matlab_cmd_posix(nlm_conn_str, mocker):
|
|
510
|
-
# Arrange
|
|
511
|
-
matlab_executable_path = "/path/to/matlab"
|
|
512
|
-
code_to_execute = "disp('Test')"
|
|
513
|
-
mocker.patch("matlab_proxy.settings.system.is_windows", return_value=False)
|
|
514
|
-
|
|
515
|
-
# Act
|
|
516
|
-
cmd = settings._get_matlab_cmd(
|
|
517
|
-
matlab_executable_path, code_to_execute, nlm_conn_str
|
|
518
|
-
)
|
|
519
|
-
|
|
520
|
-
# Assert
|
|
521
|
-
assert cmd[0] == matlab_executable_path
|
|
522
|
-
assert "-noDisplayDesktop" not in cmd
|
|
523
|
-
|
|
524
|
-
if nlm_conn_str:
|
|
525
|
-
assert "-licmode" in cmd
|
|
526
|
-
assert "file" in cmd
|
|
527
|
-
else:
|
|
528
|
-
assert "-licmode" not in cmd
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
def test_get_matlab_cmd_windows(mocker):
|
|
532
|
-
# Arrange
|
|
533
|
-
matlab_executable_path = "C:\\path\\to\\matlab.exe"
|
|
534
|
-
code_to_execute = "disp('Test')"
|
|
535
|
-
mocker.patch("matlab_proxy.settings.system.is_windows", return_value=True)
|
|
536
|
-
|
|
537
|
-
# Act
|
|
538
|
-
cmd = settings._get_matlab_cmd(matlab_executable_path, code_to_execute, None)
|
|
539
|
-
|
|
540
|
-
# Assert
|
|
541
|
-
assert "-noDisplayDesktop" in cmd
|
|
542
|
-
assert "-wait" in cmd
|
|
543
|
-
assert "-log" in cmd
|
|
544
|
-
assert ".exe" in cmd[0] # Assert .exe suffix in matlab_executable_path
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
def test_get_matlab_cmd_with_startup_profiling(mocker):
|
|
548
|
-
# Arrange
|
|
549
|
-
mocker.patch("matlab_proxy.settings.system.is_windows", return_value=False)
|
|
550
|
-
mocker.patch(
|
|
551
|
-
"matlab_proxy.settings.mwi_env.Experimental.is_matlab_startup_profiling_enabled",
|
|
552
|
-
return_value=True,
|
|
553
|
-
)
|
|
554
|
-
|
|
555
|
-
matlab_executable_path = "/path/to/matlab"
|
|
556
|
-
code_to_execute = "disp('Test')"
|
|
557
|
-
|
|
558
|
-
# Act
|
|
559
|
-
cmd = settings._get_matlab_cmd(matlab_executable_path, code_to_execute, None)
|
|
560
|
-
|
|
561
|
-
# Assert
|
|
562
|
-
assert "-timing" in cmd
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
def test_get_matlab_settings_no_matlab_on_path(mocker):
|
|
566
|
-
# Arrange
|
|
567
|
-
mocker.patch("matlab_proxy.settings.shutil.which", return_value=None)
|
|
568
|
-
|
|
569
|
-
# Act
|
|
570
|
-
matlab_settings = settings.get_matlab_settings()
|
|
571
|
-
|
|
572
|
-
# Assert
|
|
573
|
-
assert isinstance(matlab_settings["error"], MatlabInstallError)
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
def test_get_matlab_settings_matlab_softlink(mocker, tmp_path):
|
|
577
|
-
# Arrange
|
|
578
|
-
matlab_root_path = Path(tmp_path)
|
|
579
|
-
matlab_exec_path = matlab_root_path / "bin" / "matlab"
|
|
580
|
-
mocker.patch("matlab_proxy.settings.shutil.which", return_value=matlab_exec_path)
|
|
581
|
-
mocker.patch(
|
|
582
|
-
"matlab_proxy.settings.mwi.validators.validate_matlab_root_path",
|
|
583
|
-
return_value=matlab_root_path,
|
|
584
|
-
)
|
|
585
|
-
|
|
586
|
-
# Act
|
|
587
|
-
matlab_settings = settings.get_matlab_settings()
|
|
588
|
-
|
|
589
|
-
# Assert
|
|
590
|
-
assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
|
|
591
|
-
assert matlab_settings["matlab_path"] == matlab_root_path
|
|
592
|
-
assert (
|
|
593
|
-
matlab_settings["matlab_version"] is None
|
|
594
|
-
) # There's no VersionInfo.xml file in the mock setup
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
def test_get_matlab_settings_matlab_wrapper(mocker, tmp_path):
|
|
598
|
-
# Arrange
|
|
599
|
-
matlab_exec_path = Path(tmp_path) / "matlab"
|
|
600
|
-
mocker.patch("matlab_proxy.settings.shutil.which", return_value=matlab_exec_path)
|
|
601
|
-
|
|
602
|
-
# Act
|
|
603
|
-
matlab_settings = settings.get_matlab_settings()
|
|
604
|
-
|
|
605
|
-
# Assert
|
|
606
|
-
assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
|
|
607
|
-
assert (
|
|
608
|
-
matlab_settings["matlab_path"] is None
|
|
609
|
-
) # Matlab root could not be determined because wrapper script is being used
|
|
610
|
-
assert matlab_settings["matlab_version"] is None
|
|
611
|
-
assert (
|
|
612
|
-
matlab_settings["error"] is None
|
|
613
|
-
) # Error has to be None when matlab executable is on PATH but root path could not be determined
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
def test_get_matlab_settings_valid_custom_matlab_root(mocker, monkeypatch, tmp_path):
|
|
617
|
-
# Arrange
|
|
618
|
-
matlab_root_path = Path(tmp_path)
|
|
619
|
-
matlab_exec_path = matlab_root_path / "bin" / "matlab"
|
|
620
|
-
matlab_version = "R2024b"
|
|
621
|
-
monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_root(), str(matlab_root_path))
|
|
622
|
-
mocker.patch(
|
|
623
|
-
"matlab_proxy.settings.mwi.validators.validate_matlab_root_path",
|
|
624
|
-
return_value=matlab_root_path,
|
|
625
|
-
)
|
|
626
|
-
mocker.patch(
|
|
627
|
-
"matlab_proxy.settings.get_matlab_version", return_value=matlab_version
|
|
628
|
-
)
|
|
629
|
-
|
|
630
|
-
# Act
|
|
631
|
-
matlab_settings = settings.get_matlab_settings()
|
|
632
|
-
|
|
633
|
-
# Assert
|
|
634
|
-
assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
|
|
635
|
-
assert matlab_settings["matlab_path"] == matlab_root_path
|
|
636
|
-
assert matlab_settings["matlab_version"] == matlab_version
|
|
637
|
-
assert matlab_settings["error"] is None
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
def test_get_matlab_settings_invalid_custom_matlab_root(mocker, monkeypatch, tmp_path):
|
|
641
|
-
# Arrange
|
|
642
|
-
matlab_root_path = Path(tmp_path)
|
|
643
|
-
monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_root(), str(matlab_root_path))
|
|
644
|
-
|
|
645
|
-
# Act
|
|
646
|
-
matlab_settings = settings.get_matlab_settings()
|
|
647
|
-
|
|
648
|
-
# Assert
|
|
649
|
-
# When custom MATLAB root is supplied, it must be the actual MATLAB root ie.
|
|
650
|
-
# VersionInfo.xml file must to be there
|
|
651
|
-
# matlab executable inside the bin folder must be there
|
|
652
|
-
# If not, MATLAB related settings should be None and custom MATLAB root error should be present
|
|
653
|
-
assert matlab_settings["matlab_cmd"] is None
|
|
654
|
-
assert matlab_settings["matlab_path"] is None
|
|
655
|
-
assert matlab_settings["matlab_version"] is None
|
|
656
|
-
assert (
|
|
657
|
-
isinstance(matlab_settings["error"], MatlabInstallError)
|
|
658
|
-
and mwi_env.get_env_name_custom_matlab_root()
|
|
659
|
-
in matlab_settings["error"].message
|
|
660
|
-
)
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
def test_get_cookie_jar(monkeypatch):
|
|
664
|
-
"""Test to check if Cookie Jar is returned as a part of server settings"""
|
|
665
|
-
monkeypatch.setenv(mwi_env.Experimental.get_env_name_use_cookie_cache(), "false")
|
|
666
|
-
assert (
|
|
667
|
-
settings.get_server_settings(matlab_proxy.get_default_config_name())[
|
|
668
|
-
"cookie_jar"
|
|
669
|
-
]
|
|
670
|
-
is None
|
|
671
|
-
)
|
|
672
|
-
|
|
673
|
-
monkeypatch.setenv(mwi_env.Experimental.get_env_name_use_cookie_cache(), "true")
|
|
674
|
-
assert isinstance(
|
|
675
|
-
settings.get_server_settings(matlab_proxy.get_default_config_name())[
|
|
676
|
-
"cookie_jar"
|
|
677
|
-
],
|
|
678
|
-
HttpOnlyCookieJar,
|
|
679
|
-
)
|
tests/unit/util/__init__.py
DELETED
tests/unit/util/mwi/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 The MathWorks, Inc.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 The MathWorks, Inc.
|