matlab-proxy 0.15.1__py3-none-any.whl → 0.17.0__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 +33 -17
- matlab_proxy/app_state.py +90 -6
- matlab_proxy/constants.py +1 -0
- matlab_proxy/gui/asset-manifest.json +3 -3
- matlab_proxy/gui/index.html +1 -1
- matlab_proxy/gui/static/js/{main.ff1bfd69.js → main.5b5ca2f2.js} +3 -3
- matlab_proxy/gui/static/js/main.5b5ca2f2.js.map +1 -0
- matlab_proxy/settings.py +7 -4
- matlab_proxy/util/mwi/token_auth.py +19 -5
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.17.0.dist-info}/METADATA +1 -1
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.17.0.dist-info}/RECORD +22 -22
- tests/integration/integration_tests_with_license/test_http_end_points.py +4 -4
- tests/integration/integration_tests_without_license/conftest.py +4 -3
- tests/unit/test_app.py +15 -1
- tests/unit/test_app_state.py +86 -4
- tests/unit/test_constants.py +2 -1
- tests/unit/util/mwi/test_token_auth.py +23 -9
- matlab_proxy/gui/static/js/main.ff1bfd69.js.map +0 -1
- /matlab_proxy/gui/static/js/{main.ff1bfd69.js.LICENSE.txt → main.5b5ca2f2.js.LICENSE.txt} +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.17.0.dist-info}/LICENSE.md +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.17.0.dist-info}/WHEEL +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.17.0.dist-info}/entry_points.txt +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.17.0.dist-info}/top_level.txt +0 -0
matlab_proxy/settings.py
CHANGED
|
@@ -17,6 +17,7 @@ from cryptography.x509.oid import NameOID
|
|
|
17
17
|
|
|
18
18
|
import matlab_proxy
|
|
19
19
|
from matlab_proxy import constants
|
|
20
|
+
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
20
21
|
from matlab_proxy.util import mwi, system
|
|
21
22
|
from matlab_proxy.util.mwi import environment_variables as mwi_env
|
|
22
23
|
from matlab_proxy.util.mwi import token_auth
|
|
@@ -197,11 +198,12 @@ def get_dev_settings(config):
|
|
|
197
198
|
"mwi_logs_root_dir": get_mwi_logs_root_dir(dev=True),
|
|
198
199
|
"mw_context_tags": get_mw_context_tags(matlab_proxy.get_default_config_name()),
|
|
199
200
|
"mwi_server_url": None,
|
|
200
|
-
"mwi_is_token_auth_enabled": mwi_auth_token
|
|
201
|
+
"mwi_is_token_auth_enabled": mwi_auth_token is not None,
|
|
201
202
|
"mwi_auth_status": False,
|
|
202
203
|
"mwi_auth_token": mwi_auth_token,
|
|
203
204
|
"mwi_auth_token_hash": mwi_auth_token_hash,
|
|
204
|
-
"
|
|
205
|
+
"mwi_auth_token_name_for_http": MWI_AUTH_TOKEN_NAME_FOR_HTTP,
|
|
206
|
+
"mwi_auth_token_name_for_env": mwi_env.get_env_name_mwi_auth_token().lower(),
|
|
205
207
|
"mwi_use_existing_license": mwi.validators.validate_use_existing_licensing(
|
|
206
208
|
os.getenv(mwi_env.get_env_name_mwi_use_existing_license(), "")
|
|
207
209
|
),
|
|
@@ -322,11 +324,12 @@ def get_server_settings(config_name):
|
|
|
322
324
|
"mw_context_tags": get_mw_context_tags(config_name),
|
|
323
325
|
# The url where the matlab-proxy server is accessible at
|
|
324
326
|
"mwi_server_url": None,
|
|
325
|
-
"mwi_is_token_auth_enabled": mwi_auth_token
|
|
327
|
+
"mwi_is_token_auth_enabled": mwi_auth_token is not None,
|
|
326
328
|
"mwi_auth_status": False,
|
|
327
329
|
"mwi_auth_token": mwi_auth_token,
|
|
328
330
|
"mwi_auth_token_hash": mwi_auth_token_hash,
|
|
329
|
-
"
|
|
331
|
+
"mwi_auth_token_name_for_http": MWI_AUTH_TOKEN_NAME_FOR_HTTP,
|
|
332
|
+
"mwi_auth_token_name_for_env": mwi_env.get_env_name_mwi_auth_token().lower(),
|
|
330
333
|
"mwi_use_existing_license": mwi.validators.validate_use_existing_licensing(
|
|
331
334
|
os.getenv(mwi_env.get_env_name_mwi_use_existing_license(), "")
|
|
332
335
|
),
|
|
@@ -59,7 +59,7 @@ def generate_mwi_auth_token_and_hash():
|
|
|
59
59
|
def get_mwi_auth_token_access_str(app_settings):
|
|
60
60
|
"""Returns formatted string with mwi token for use with server URL"""
|
|
61
61
|
if app_settings["mwi_is_token_auth_enabled"]:
|
|
62
|
-
mwi_auth_token_name = app_settings["
|
|
62
|
+
mwi_auth_token_name = app_settings["mwi_auth_token_name_for_http"]
|
|
63
63
|
mwi_auth_token = app_settings["mwi_auth_token"]
|
|
64
64
|
return f"?{mwi_auth_token_name}={mwi_auth_token}"
|
|
65
65
|
|
|
@@ -134,7 +134,20 @@ async def _get_token_name(request):
|
|
|
134
134
|
str : token name
|
|
135
135
|
"""
|
|
136
136
|
app_settings = request.app["settings"]
|
|
137
|
-
return app_settings["
|
|
137
|
+
return app_settings["mwi_auth_token_name_for_env"]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _get_token_name_for_http(request):
|
|
141
|
+
"""Gets the name of the token from settings.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
request (HTTPRequest) : Used to get to app settings
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
str : token name
|
|
148
|
+
"""
|
|
149
|
+
app_settings = request.app["settings"]
|
|
150
|
+
return app_settings["mwi_auth_token_name_for_http"]
|
|
138
151
|
|
|
139
152
|
|
|
140
153
|
async def _get_token(request):
|
|
@@ -238,11 +251,11 @@ async def _is_valid_token_in_url_query(request):
|
|
|
238
251
|
query_string = request.query_string
|
|
239
252
|
logger.debug(f"url query parameters found:{query_string}")
|
|
240
253
|
if query_string:
|
|
241
|
-
token_name =
|
|
254
|
+
token_name = _get_token_name_for_http(request)
|
|
242
255
|
parsed_token = parse_qs(request.query_string).get(token_name)
|
|
243
256
|
if parsed_token:
|
|
244
257
|
parsed_token = parsed_token[0]
|
|
245
|
-
logger.debug(
|
|
258
|
+
logger.debug("parsed_token from url query string.")
|
|
246
259
|
return await _is_valid_token(parsed_token, request)
|
|
247
260
|
|
|
248
261
|
logger.debug("Token not found in url query.")
|
|
@@ -262,8 +275,9 @@ async def _is_valid_token_in_headers(request):
|
|
|
262
275
|
"""
|
|
263
276
|
logger.debug("Checking for token in request headers...")
|
|
264
277
|
headers = request.headers
|
|
265
|
-
token_name =
|
|
278
|
+
token_name = _get_token_name_for_http(request)
|
|
266
279
|
if token_name in headers:
|
|
280
|
+
logger.debug(f"Token found in headers: {token_name}")
|
|
267
281
|
is_valid_token = await _is_valid_token(headers[token_name], request)
|
|
268
282
|
if is_valid_token:
|
|
269
283
|
await _store_token_hash_into_session(request)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
matlab_proxy/__init__.py,sha256=6cwi8buKCMtw9OeWaOYUHEoqwl5MyJ_s6GxgNuqPuNg,1673
|
|
2
|
-
matlab_proxy/app.py,sha256
|
|
3
|
-
matlab_proxy/app_state.py,sha256
|
|
4
|
-
matlab_proxy/constants.py,sha256=
|
|
2
|
+
matlab_proxy/app.py,sha256=aoKkhw_E71uCJeMzqr9VE4mrIRd_4Aqt3Uw4nrYiZZY,34386
|
|
3
|
+
matlab_proxy/app_state.py,sha256=-8gduqMymI7U_NwNRtL26skrjOlnDRiM2vXqBTfMnKo,59525
|
|
4
|
+
matlab_proxy/constants.py,sha256=gHL6bYgRDyzufMx1XF9tbtC9vsS_yQlfYPNommti8tA,972
|
|
5
5
|
matlab_proxy/default_configuration.py,sha256=DxQaHzAivzstiPl_nDfxs8SOyP9oaK9v3RP4LtroJl4,843
|
|
6
6
|
matlab_proxy/devel.py,sha256=nR6XPVBUEdQ-RZGtYvX1YHTp8gj9cuw5Hp8ahasMBc8,14310
|
|
7
|
-
matlab_proxy/settings.py,sha256=
|
|
7
|
+
matlab_proxy/settings.py,sha256=Q901JN7zwcySVOs7EQ69m4Ngishmo9ihFzqbPxXajh4,24915
|
|
8
8
|
matlab_proxy/gui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
matlab_proxy/gui/asset-manifest.json,sha256=
|
|
9
|
+
matlab_proxy/gui/asset-manifest.json,sha256=XqmLvi3DDOGSbBxNZwjuaNJXoYjZiG2HasxvZnEzPEo,3516
|
|
10
10
|
matlab_proxy/gui/favicon.ico,sha256=7w7Ki1uQP2Rgwc64dOV4-NrTu97I3WsZw8OvRSoY1A0,130876
|
|
11
|
-
matlab_proxy/gui/index.html,sha256=
|
|
11
|
+
matlab_proxy/gui/index.html,sha256=lWKKMXjAyOc-vk6t4rasj49sa2UgXAAlMdWYCd5V8N8,637
|
|
12
12
|
matlab_proxy/gui/manifest.json,sha256=NwDbrALM5auYyj2bbEf4aGwAUDqNl1FzMFQpPiG2Ty4,286
|
|
13
13
|
matlab_proxy/gui/robots.txt,sha256=kNJLw79pisHhc3OVAimMzKcq3x9WT6sF9IS4xI0crdI,67
|
|
14
14
|
matlab_proxy/gui/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -16,9 +16,9 @@ matlab_proxy/gui/static/css/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
|
16
16
|
matlab_proxy/gui/static/css/main.47712126.css,sha256=OT5ccyC0a6fVg956C-8b6uDVbZZVgcpXbHjdO6v4ZBI,274313
|
|
17
17
|
matlab_proxy/gui/static/css/main.47712126.css.map,sha256=RdfmXfQvzvvh4XZuDWShm8CD8pA2Gb2K6MtMzrgJyKM,350495
|
|
18
18
|
matlab_proxy/gui/static/js/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
-
matlab_proxy/gui/static/js/main.
|
|
20
|
-
matlab_proxy/gui/static/js/main.
|
|
21
|
-
matlab_proxy/gui/static/js/main.
|
|
19
|
+
matlab_proxy/gui/static/js/main.5b5ca2f2.js,sha256=XvoCZpW63pLcHvS9meZxIId_yQPC3w5SuGIij5VwOEc,294436
|
|
20
|
+
matlab_proxy/gui/static/js/main.5b5ca2f2.js.LICENSE.txt,sha256=3cj3DrwM51esz1ogL9VVU1ZyXyXJ6u-Ec2CI9CCcI_A,1689
|
|
21
|
+
matlab_proxy/gui/static/js/main.5b5ca2f2.js.map,sha256=mCDweY7BuQ4Ld5c6Z521rjPGrIlIzG2b_DjxsW_eo6M,938339
|
|
22
22
|
matlab_proxy/gui/static/media/MATLAB-env-blur.4fc94edbc82d3184e5cb.png,sha256=QpmQTLDvBu2-b7ev83Rvpt0Q72R6wdQGkuJMPPpjv7M,220290
|
|
23
23
|
matlab_proxy/gui/static/media/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
matlab_proxy/gui/static/media/arrow.0c2968b90bd9a64c8c3f.svg,sha256=XtmvDWzGZnwCZm08TKBnqt5hc1wphJnNupG0Fx_faAY,327
|
|
@@ -65,7 +65,7 @@ matlab_proxy/util/mwi/download.py,sha256=-GJj3yOsL4vF_9baqRXkgBI-vu_OwjZMQVkJXFS
|
|
|
65
65
|
matlab_proxy/util/mwi/environment_variables.py,sha256=bIz0QFWo0pgyvSeJ_kAobUCS17V05CSmFWm3zYIOIsA,7139
|
|
66
66
|
matlab_proxy/util/mwi/exceptions.py,sha256=93HrHbOq24KI4Md2el23XN01wIqVShEK29Pbt2V0Jr8,4628
|
|
67
67
|
matlab_proxy/util/mwi/logger.py,sha256=e7wTPclrtJ-aX5mPk_pUJMX7-1QD_snGBW1P2ks-ETE,3311
|
|
68
|
-
matlab_proxy/util/mwi/token_auth.py,sha256=
|
|
68
|
+
matlab_proxy/util/mwi/token_auth.py,sha256=UbIWqo7qADaZdijFvorLYsZbxzaB8TycGP8nk305ru0,9997
|
|
69
69
|
matlab_proxy/util/mwi/validators.py,sha256=BMMOD-0tdjGIALm1MmG4yXVRoD2ZUXkrJXLWP_D5FGo,11712
|
|
70
70
|
matlab_proxy/util/mwi/embedded_connector/__init__.py,sha256=SVSckEJ4zQQ2KkNPT_un8ndMAImcMOTrai7ShAbmFY4,114
|
|
71
71
|
matlab_proxy/util/mwi/embedded_connector/helpers.py,sha256=p6TedefbvhlZT64IMwFjrb0panWCXf-T3XPoztDbxM0,3391
|
|
@@ -73,18 +73,18 @@ matlab_proxy/util/mwi/embedded_connector/request.py,sha256=-6DL9K8JWjX5u5XVOEGaq
|
|
|
73
73
|
tests/integration/__init__.py,sha256=ttzJ8xKWGxOJZz56qOiWOn6sp5LGomkZMn_w4KJLRMU,42
|
|
74
74
|
tests/integration/integration_tests_with_license/__init__.py,sha256=vVYZCur-QhmIGCxUmn-WZjIywtDQidaLDmlmrRHRlgY,37
|
|
75
75
|
tests/integration/integration_tests_with_license/conftest.py,sha256=sCaIXB8d4vf05C7JWSVA7g5gnPjbpRq3dftuBpWyp1s,1599
|
|
76
|
-
tests/integration/integration_tests_with_license/test_http_end_points.py,sha256=
|
|
76
|
+
tests/integration/integration_tests_with_license/test_http_end_points.py,sha256=SDJIoyo-hh2Ns9uWaDeO87N0jY3svhKOn29HFFyx_jM,7485
|
|
77
77
|
tests/integration/integration_tests_without_license/__init__.py,sha256=vVYZCur-QhmIGCxUmn-WZjIywtDQidaLDmlmrRHRlgY,37
|
|
78
|
-
tests/integration/integration_tests_without_license/conftest.py,sha256=
|
|
78
|
+
tests/integration/integration_tests_without_license/conftest.py,sha256=n-oppKWxavyy1O0J6DywO3DnOHuYc7yUZRXm3Bt4szU,3526
|
|
79
79
|
tests/integration/integration_tests_without_license/test_matlab_is_down_if_unlicensed.py,sha256=tkdyhfZBpfJpbnEzjURyV-GE0p43YxOa9xooJf-JoM4,1653
|
|
80
80
|
tests/integration/utils/__init__.py,sha256=ttzJ8xKWGxOJZz56qOiWOn6sp5LGomkZMn_w4KJLRMU,42
|
|
81
81
|
tests/integration/utils/integration_tests_utils.py,sha256=IbJ9CedFHiz3k85FBY-8GwotTnjPF3jF4AHdKio7jqk,10321
|
|
82
82
|
tests/integration/utils/licensing.py,sha256=rEBjvMXO8R3mL6KnePu2lojmOsjD4GXl9frf9N0Wacs,4842
|
|
83
83
|
tests/unit/__init__.py,sha256=KfwQxxM5a1kMRtNbhz8tb7YfHp8e2d0tNLB55wYvDS8,37
|
|
84
84
|
tests/unit/conftest.py,sha256=Hfxq3h8IZuLJkRMh5jdEFiq78CIAdKvm-6KryRDZ0FY,1918
|
|
85
|
-
tests/unit/test_app.py,sha256=
|
|
86
|
-
tests/unit/test_app_state.py,sha256=
|
|
87
|
-
tests/unit/test_constants.py,sha256=
|
|
85
|
+
tests/unit/test_app.py,sha256=xiiEQu1iNK0h3Yuwn3c-hgvNhC1EXKFgTbE_7U3mSrs,37731
|
|
86
|
+
tests/unit/test_app_state.py,sha256=xwXOmyzamL89eg4q2s4IpFKWDN4r2lZwsHBafqDkins,21854
|
|
87
|
+
tests/unit/test_constants.py,sha256=ieDKc7bL8zWsd_D4dv2n8iftXr2h-bkS5p6zVan0BtQ,125
|
|
88
88
|
tests/unit/test_ddux.py,sha256=a2J2iM8j_nnfJVuMI38p5AjwrRdoMj3N88gFgS2I4hg,713
|
|
89
89
|
tests/unit/test_devel.py,sha256=A-1iVhSSwmywaW65QIRcUS2Fk7nJxceCcCm7CJtNdEc,7982
|
|
90
90
|
tests/unit/test_non_dev_mode.py,sha256=0v27y27SLOWvw6jf_GhLLNg-RMsZS_OyGAnqoQYPpSA,5515
|
|
@@ -95,16 +95,16 @@ tests/unit/util/test_util.py,sha256=jhZOgErpD6b3JeusLBOPVvu6iZ3_ttwlEVV8uKLUvrw,
|
|
|
95
95
|
tests/unit/util/mwi/__init__.py,sha256=pl5jqyCHEwZEviiL8OC-SHulb1rBecstQCFF6qVjL9Y,37
|
|
96
96
|
tests/unit/util/mwi/test_custom_http_headers.py,sha256=UfrhclS0j6WhShtg1ki2oF1kK8JqRC29uevH4tuDqF4,11182
|
|
97
97
|
tests/unit/util/mwi/test_logger.py,sha256=zWImNitMYKPJunXWJjEDEtCEKwBz615PC844ZLwoxIg,1845
|
|
98
|
-
tests/unit/util/mwi/test_token_auth.py,sha256=-
|
|
98
|
+
tests/unit/util/mwi/test_token_auth.py,sha256=-eBsaQ5JC7pyd9PXt48Rqs4cWjg6I-eOkp_gFVEwYhk,10538
|
|
99
99
|
tests/unit/util/mwi/test_validators.py,sha256=YeOP0-T7SFNeiC7JIQj7cV4ja3d6PhswsTz27IEgJHQ,10852
|
|
100
100
|
tests/unit/util/mwi/embedded_connector/__init__.py,sha256=pl5jqyCHEwZEviiL8OC-SHulb1rBecstQCFF6qVjL9Y,37
|
|
101
101
|
tests/unit/util/mwi/embedded_connector/test_helpers.py,sha256=vYTWNUTuDeaygo16JGMTvWeI_CLOnvPkwNJmLndvJhE,890
|
|
102
102
|
tests/unit/util/mwi/embedded_connector/test_request.py,sha256=PR-jddnXDEiip-lD7A_QSvRwEkwo3eQ8owZlk-r9vnk,1867
|
|
103
103
|
tests/utils/__init__.py,sha256=ttzJ8xKWGxOJZz56qOiWOn6sp5LGomkZMn_w4KJLRMU,42
|
|
104
104
|
tests/utils/logging_util.py,sha256=VBy_NRvwau3C_CVTBjK5RMROrQimnJYHO2U0aKSZiRw,2234
|
|
105
|
-
matlab_proxy-0.
|
|
106
|
-
matlab_proxy-0.
|
|
107
|
-
matlab_proxy-0.
|
|
108
|
-
matlab_proxy-0.
|
|
109
|
-
matlab_proxy-0.
|
|
110
|
-
matlab_proxy-0.
|
|
105
|
+
matlab_proxy-0.17.0.dist-info/LICENSE.md,sha256=oF0h3UdSF-rlUiMGYwi086ZHqelzz7yOOk9HFDv9ELo,2344
|
|
106
|
+
matlab_proxy-0.17.0.dist-info/METADATA,sha256=_UnbcVVZElb72b3PjnP85kmOmqYdzoXv1tcsEGkVD5s,10108
|
|
107
|
+
matlab_proxy-0.17.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
108
|
+
matlab_proxy-0.17.0.dist-info/entry_points.txt,sha256=DbBLYgnRt8UGiOpd0zHigRTyyMdZYhMdvCvSYP7wPN0,244
|
|
109
|
+
matlab_proxy-0.17.0.dist-info/top_level.txt,sha256=9uVTjsUCAS4TwsxueTBxrBg3PdBiTSsYowAkHPv9VY0,19
|
|
110
|
+
matlab_proxy-0.17.0.dist-info/RECORD,,
|
|
@@ -12,7 +12,7 @@ import re
|
|
|
12
12
|
from requests.adapters import HTTPAdapter, Retry
|
|
13
13
|
from urllib.parse import urlparse, parse_qs
|
|
14
14
|
from tests.utils.logging_util import create_integ_test_logger
|
|
15
|
-
from
|
|
15
|
+
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
16
16
|
|
|
17
17
|
_logger = create_integ_test_logger(__name__)
|
|
18
18
|
|
|
@@ -64,9 +64,9 @@ class RealMATLABServer:
|
|
|
64
64
|
parsed_url = urlparse(utils.get_connection_string(self.mwi_app_port))
|
|
65
65
|
|
|
66
66
|
self.headers = {
|
|
67
|
-
|
|
68
|
-
parse_qs(parsed_url.query)[
|
|
69
|
-
if
|
|
67
|
+
MWI_AUTH_TOKEN_NAME_FOR_HTTP: (
|
|
68
|
+
parse_qs(parsed_url.query)[MWI_AUTH_TOKEN_NAME_FOR_HTTP][0]
|
|
69
|
+
if MWI_AUTH_TOKEN_NAME_FOR_HTTP in parse_qs(parsed_url.query)
|
|
70
70
|
else ""
|
|
71
71
|
)
|
|
72
72
|
}
|
|
@@ -6,6 +6,7 @@ import requests
|
|
|
6
6
|
from tests.utils.logging_util import create_integ_test_logger
|
|
7
7
|
import os
|
|
8
8
|
from urllib.parse import urlparse, parse_qs
|
|
9
|
+
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
9
10
|
|
|
10
11
|
_logger = create_integ_test_logger(__name__)
|
|
11
12
|
|
|
@@ -34,9 +35,9 @@ def parse_matlab_proxy_url():
|
|
|
34
35
|
parsed_url = urlparse(utils.get_connection_string(mwi_app_port))
|
|
35
36
|
|
|
36
37
|
headers = {
|
|
37
|
-
|
|
38
|
-
parse_qs(parsed_url.query)[
|
|
39
|
-
if
|
|
38
|
+
MWI_AUTH_TOKEN_NAME_FOR_HTTP: (
|
|
39
|
+
parse_qs(parsed_url.query)[MWI_AUTH_TOKEN_NAME_FOR_HTTP][0]
|
|
40
|
+
if MWI_AUTH_TOKEN_NAME_FOR_HTTP in parse_qs(parsed_url.query)
|
|
40
41
|
else ""
|
|
41
42
|
)
|
|
42
43
|
}
|
tests/unit/test_app.py
CHANGED
|
@@ -284,6 +284,20 @@ async def test_get_status_route(test_server):
|
|
|
284
284
|
assert resp.status == HTTPStatus.OK
|
|
285
285
|
|
|
286
286
|
|
|
287
|
+
async def test_clear_client_id_route(test_server):
|
|
288
|
+
"""Test to check endpoint: "/clear_client_id"
|
|
289
|
+
|
|
290
|
+
Args:
|
|
291
|
+
test_server (aiohttp_client): A aiohttp_client server for sending POST request.
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
state = test_server.server.app["state"]
|
|
295
|
+
state.active_client = "mock_client_id"
|
|
296
|
+
resp = await test_server.post("/clear_client_id")
|
|
297
|
+
assert resp.status == HTTPStatus.OK
|
|
298
|
+
assert state.active_client is None
|
|
299
|
+
|
|
300
|
+
|
|
287
301
|
async def test_get_env_config(test_server):
|
|
288
302
|
"""Test to check endpoint : "/get_env_config"
|
|
289
303
|
|
|
@@ -1031,7 +1045,7 @@ async def test_update_entitlement_with_correct_entitlement(set_licensing_info):
|
|
|
1031
1045
|
assert resp.status == HTTPStatus.OK
|
|
1032
1046
|
|
|
1033
1047
|
|
|
1034
|
-
async def test_get_auth_token_route(test_server
|
|
1048
|
+
async def test_get_auth_token_route(test_server):
|
|
1035
1049
|
"""Test to check endpoint : "/get_auth_token"
|
|
1036
1050
|
|
|
1037
1051
|
Args:
|
tests/unit/test_app_state.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright 2023 The MathWorks, Inc.
|
|
1
|
+
# Copyright 2023-2024 The MathWorks, Inc.
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import os
|
|
@@ -7,9 +7,10 @@ from pathlib import Path
|
|
|
7
7
|
from typing import Optional
|
|
8
8
|
|
|
9
9
|
import pytest
|
|
10
|
-
from matlab_proxy import settings
|
|
11
10
|
|
|
11
|
+
from matlab_proxy import settings
|
|
12
12
|
from matlab_proxy.app_state import AppState
|
|
13
|
+
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
13
14
|
from matlab_proxy.util.mwi.exceptions import LicensingError, MatlabError
|
|
14
15
|
from tests.unit.util import MockResponse
|
|
15
16
|
|
|
@@ -55,7 +56,7 @@ def app_state_fixture(sample_settings_fixture):
|
|
|
55
56
|
|
|
56
57
|
@pytest.fixture
|
|
57
58
|
def sample_token_headers_fixture():
|
|
58
|
-
return {
|
|
59
|
+
return {MWI_AUTH_TOKEN_NAME_FOR_HTTP: "asdf"}
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
@pytest.fixture
|
|
@@ -76,7 +77,10 @@ def app_state_with_token_auth_fixture(
|
|
|
76
77
|
((mwi_auth_token_name, mwi_auth_token_hash),) = sample_token_headers_fixture.items()
|
|
77
78
|
app_state_fixture.matlab_session_files["matlab_ready_file"] = tmp_matlab_ready_file
|
|
78
79
|
app_state_fixture.settings["mwi_is_token_auth_enabled"] = True
|
|
79
|
-
app_state_fixture.settings["
|
|
80
|
+
app_state_fixture.settings["mwi_auth_token_name_for_env"] = mwi_auth_token_name
|
|
81
|
+
app_state_fixture.settings["mwi_auth_token_name_for_http"] = (
|
|
82
|
+
MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
83
|
+
)
|
|
80
84
|
app_state_fixture.settings["mwi_auth_token_hash"] = mwi_auth_token_hash
|
|
81
85
|
app_state_fixture.settings["mwi_server_url"] = "http://localhost:8888"
|
|
82
86
|
|
|
@@ -580,3 +584,81 @@ async def test_start_matlab_without_xvfb(app_state_fixture, mocker):
|
|
|
580
584
|
assert app_state_fixture.processes["xvfb"] is None
|
|
581
585
|
# Check if Matlab started
|
|
582
586
|
assert app_state_fixture.processes["matlab"] is mock_matlab
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
@pytest.mark.parametrize(
|
|
590
|
+
"is_desktop, client_id, is_client_id_present, expected_is_active_client",
|
|
591
|
+
[
|
|
592
|
+
(False, None, False, None),
|
|
593
|
+
(False, "mock_id", False, None),
|
|
594
|
+
(True, None, True, True),
|
|
595
|
+
(True, "mock_id", False, True),
|
|
596
|
+
],
|
|
597
|
+
ids=[
|
|
598
|
+
"request_from_non-desktop_client",
|
|
599
|
+
"request_from_non-desktop_client_having_mock_id",
|
|
600
|
+
"request_from_desktop_client",
|
|
601
|
+
"request_from_desktop_client_having_mock_id",
|
|
602
|
+
],
|
|
603
|
+
)
|
|
604
|
+
async def test_get_session_status(
|
|
605
|
+
app_state_fixture,
|
|
606
|
+
is_desktop,
|
|
607
|
+
client_id,
|
|
608
|
+
is_client_id_present,
|
|
609
|
+
expected_is_active_client,
|
|
610
|
+
):
|
|
611
|
+
"""Test to check if correnct session response is returned based on various conditions.
|
|
612
|
+
|
|
613
|
+
Args:
|
|
614
|
+
app_state_fixture (AppState): Object of AppState class with defaults set
|
|
615
|
+
is_desktop (bool): A flag indicating whether the client is a desktop client.
|
|
616
|
+
client_id (str or None): The client ID. If None, a new client ID may be generated.
|
|
617
|
+
is_client_id_present (bool): Indicates whether the expected value of client_id is string or not.
|
|
618
|
+
expected_is_active_client (bool): Indicates the expected value of is_active_client
|
|
619
|
+
|
|
620
|
+
"""
|
|
621
|
+
# The value of transfer_session is a Don't Care condition as initially the value of client_id is always None.
|
|
622
|
+
output_client_id, output_is_active_client = app_state_fixture.get_session_status(
|
|
623
|
+
is_desktop, client_id, transfer_session=False
|
|
624
|
+
)
|
|
625
|
+
assert isinstance(output_client_id, str) == is_client_id_present, (
|
|
626
|
+
"Expected client_id to be a string got None"
|
|
627
|
+
if is_client_id_present
|
|
628
|
+
else "Expected client_id to be None got a string value"
|
|
629
|
+
)
|
|
630
|
+
assert (
|
|
631
|
+
output_is_active_client == expected_is_active_client
|
|
632
|
+
), f"Expected is_active_client to be {expected_is_active_client} got {output_is_active_client}"
|
|
633
|
+
# For clean up of task_detect_client_status
|
|
634
|
+
app_state_fixture.active_client = None
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
async def test_get_session_status_can_transfer_session(app_state_fixture):
|
|
638
|
+
"""Test to check whether transer session changes client id to the new id
|
|
639
|
+
|
|
640
|
+
Args:
|
|
641
|
+
app_state_fixture (AppState): Object of AppState class with defaults set
|
|
642
|
+
"""
|
|
643
|
+
app_state_fixture.active_client = "mock_id"
|
|
644
|
+
app_state_fixture.get_session_status(
|
|
645
|
+
is_desktop=True, client_id="new_id", transfer_session=True
|
|
646
|
+
)
|
|
647
|
+
assert app_state_fixture.active_client == "new_id"
|
|
648
|
+
# For clean up of task_detect_client_status
|
|
649
|
+
app_state_fixture.active_client = None
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
async def test_detect_active_client_status_can_reset_active_client(app_state_fixture):
|
|
653
|
+
"""Test to check whether the value of active client is being reset due to the client inactivity.
|
|
654
|
+
|
|
655
|
+
Args:
|
|
656
|
+
app_state_fixture (AppState): Object of AppState class with defaults set
|
|
657
|
+
"""
|
|
658
|
+
app_state_fixture.active_client = "mock_id"
|
|
659
|
+
await app_state_fixture.detect_active_client_status(
|
|
660
|
+
sleep_time=0, max_inactive_count=0
|
|
661
|
+
)
|
|
662
|
+
assert (
|
|
663
|
+
app_state_fixture.active_client == None
|
|
664
|
+
), f"Expected the active_client to be None"
|
tests/unit/test_constants.py
CHANGED
|
@@ -6,6 +6,7 @@ from aiohttp_session import setup as aiohttp_session_setup
|
|
|
6
6
|
from aiohttp_session.cookie_storage import EncryptedCookieStorage
|
|
7
7
|
from cryptography import fernet
|
|
8
8
|
|
|
9
|
+
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
9
10
|
from matlab_proxy.util.mwi import environment_variables as mwi_env
|
|
10
11
|
from matlab_proxy.util.mwi import token_auth
|
|
11
12
|
|
|
@@ -105,10 +106,11 @@ def fake_server_with_auth_enabled(
|
|
|
105
106
|
|
|
106
107
|
app = web.Application()
|
|
107
108
|
app["settings"] = {
|
|
108
|
-
"mwi_is_token_auth_enabled": mwi_auth_token
|
|
109
|
+
"mwi_is_token_auth_enabled": mwi_auth_token is not None,
|
|
109
110
|
"mwi_auth_token": mwi_auth_token,
|
|
110
111
|
"mwi_auth_token_hash": mwi_auth_token_hash,
|
|
111
|
-
"
|
|
112
|
+
"mwi_auth_token_name_for_http": MWI_AUTH_TOKEN_NAME_FOR_HTTP,
|
|
113
|
+
"mwi_auth_token_name_for_env": mwi_env.get_env_name_mwi_auth_token().lower(),
|
|
112
114
|
}
|
|
113
115
|
app.router.add_get("/", fake_endpoint)
|
|
114
116
|
app.router.add_post("/", fake_endpoint)
|
|
@@ -127,7 +129,7 @@ async def test_set_value_with_token(
|
|
|
127
129
|
resp = await fake_server_with_auth_enabled.post(
|
|
128
130
|
"/",
|
|
129
131
|
data={"value": "foo"},
|
|
130
|
-
headers={
|
|
132
|
+
headers={MWI_AUTH_TOKEN_NAME_FOR_HTTP: get_custom_auth_token_str},
|
|
131
133
|
)
|
|
132
134
|
assert resp.status == web.HTTPOk.status_code
|
|
133
135
|
assert await resp.text() == "thanks for the data"
|
|
@@ -158,7 +160,9 @@ async def test_set_value_with_token_hash(
|
|
|
158
160
|
"/",
|
|
159
161
|
data={"value": "foo"},
|
|
160
162
|
headers={
|
|
161
|
-
|
|
163
|
+
MWI_AUTH_TOKEN_NAME_FOR_HTTP: token_auth._generate_hash(
|
|
164
|
+
get_custom_auth_token_str
|
|
165
|
+
)
|
|
162
166
|
},
|
|
163
167
|
)
|
|
164
168
|
assert resp.status == web.HTTPOk.status_code
|
|
@@ -193,7 +197,9 @@ async def test_set_value_without_token(fake_server_with_auth_enabled):
|
|
|
193
197
|
|
|
194
198
|
async def test_set_value_with_invalid_token(fake_server_with_auth_enabled):
|
|
195
199
|
resp2 = await fake_server_with_auth_enabled.post(
|
|
196
|
-
"/",
|
|
200
|
+
"/",
|
|
201
|
+
data={"value": "foobar"},
|
|
202
|
+
headers={MWI_AUTH_TOKEN_NAME_FOR_HTTP: "invalid-token"},
|
|
197
203
|
)
|
|
198
204
|
assert resp2.status == web.HTTPForbidden.status_code
|
|
199
205
|
|
|
@@ -205,7 +211,11 @@ async def test_set_value_with_token_in_params(
|
|
|
205
211
|
resp = await fake_server_with_auth_enabled.post(
|
|
206
212
|
"/",
|
|
207
213
|
data={"value": "foofoo"},
|
|
208
|
-
params={
|
|
214
|
+
params={
|
|
215
|
+
MWI_AUTH_TOKEN_NAME_FOR_HTTP: token_auth._generate_hash(
|
|
216
|
+
get_custom_auth_token_str
|
|
217
|
+
)
|
|
218
|
+
},
|
|
209
219
|
)
|
|
210
220
|
assert resp.status == web.HTTPOk.status_code
|
|
211
221
|
assert await resp.text() == "thanks for the data"
|
|
@@ -232,7 +242,11 @@ async def test_get_value_with_token_in_query_params(
|
|
|
232
242
|
fake_server_with_auth_enabled.server.app["value"] = "bar"
|
|
233
243
|
resp = await fake_server_with_auth_enabled.get(
|
|
234
244
|
"/",
|
|
235
|
-
params={
|
|
245
|
+
params={
|
|
246
|
+
MWI_AUTH_TOKEN_NAME_FOR_HTTP: token_auth._generate_hash(
|
|
247
|
+
get_custom_auth_token_str
|
|
248
|
+
)
|
|
249
|
+
},
|
|
236
250
|
)
|
|
237
251
|
assert resp.status == web.HTTPOk.status_code
|
|
238
252
|
assert await resp.text() == "value: bar"
|
|
@@ -257,7 +271,7 @@ def fake_server_without_auth_enabled(loop, aiohttp_client, monkeypatch):
|
|
|
257
271
|
"mwi_is_token_auth_enabled": mwi_auth_token != None,
|
|
258
272
|
"mwi_auth_token": mwi_auth_token,
|
|
259
273
|
"mwi_auth_token_hash": mwi_auth_token_hash,
|
|
260
|
-
"
|
|
274
|
+
"mwi_auth_token_name_for_env": mwi_env.get_env_name_mwi_auth_token().lower(),
|
|
261
275
|
}
|
|
262
276
|
app.router.add_get("/", fake_endpoint)
|
|
263
277
|
app.router.add_post("/", fake_endpoint)
|
|
@@ -283,7 +297,7 @@ async def test_get_value_in_query_params(
|
|
|
283
297
|
# Server should respond even if token is provided when not needed.
|
|
284
298
|
fake_server_without_auth_enabled.server.app["value"] = "bar2"
|
|
285
299
|
resp = await fake_server_without_auth_enabled.get(
|
|
286
|
-
"/", params={"
|
|
300
|
+
"/", params={"mwi-auth-token": get_custom_auth_token_str}
|
|
287
301
|
)
|
|
288
302
|
assert resp.status == web.HTTPOk.status_code
|
|
289
303
|
assert await resp.text() == "value: bar2"
|