matlab-proxy 0.15.1__py3-none-any.whl → 0.16.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_state.py +9 -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.522d83ba.js} +3 -3
- matlab_proxy/gui/static/js/main.522d83ba.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.16.0.dist-info}/METADATA +1 -1
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.16.0.dist-info}/RECORD +21 -21
- 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 +1 -1
- tests/unit/test_app_state.py +8 -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.522d83ba.js.LICENSE.txt} +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.16.0.dist-info}/LICENSE.md +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.16.0.dist-info}/WHEEL +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.16.0.dist-info}/entry_points.txt +0 -0
- {matlab_proxy-0.15.1.dist-info → matlab_proxy-0.16.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
2
|
matlab_proxy/app.py,sha256=-QcfNOCyXAQu58Gq-bSU4iHtJrVglxgD0c-n6nTzumo,33819
|
|
3
|
-
matlab_proxy/app_state.py,sha256=
|
|
4
|
-
matlab_proxy/constants.py,sha256=
|
|
3
|
+
matlab_proxy/app_state.py,sha256=tHZpv2pEk_zb55FKDvnIIcIg-S3i-r52h5WHot-wITI,55450
|
|
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=Y0bASwFy_ZO21iJjvOmN9Rf4pgvKRqpVMxVQ5g0eU2Q,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=R6bC4lxj_0V0mmXr4Rqf9mHQoDWkNY0CpKBGNvxWaWs,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.522d83ba.js,sha256=6Mr6KC2dNysr7aA1VUObaA-2XZDPeZbA7FWl3W3GH68,294192
|
|
20
|
+
matlab_proxy/gui/static/js/main.522d83ba.js.LICENSE.txt,sha256=3cj3DrwM51esz1ogL9VVU1ZyXyXJ6u-Ec2CI9CCcI_A,1689
|
|
21
|
+
matlab_proxy/gui/static/js/main.522d83ba.js.map,sha256=dJifP1EbrR0Dli2vzs_uRFhJ10MG_6Zwaw2GtWWEkq0,937322
|
|
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=8hR0pWEIWrXU2UTZLLug9spaadp5Hb33960RE3jy4mw,37300
|
|
86
|
+
tests/unit/test_app_state.py,sha256=wuEAYCXT262Ew01tRVP_SwRDa_M6MlzkkKuGTlcbGaY,18790
|
|
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.16.0.dist-info/LICENSE.md,sha256=oF0h3UdSF-rlUiMGYwi086ZHqelzz7yOOk9HFDv9ELo,2344
|
|
106
|
+
matlab_proxy-0.16.0.dist-info/METADATA,sha256=OhfB2b3xNfmm_1jHPjgpc2wOXa_te8IO4xxjmLNi0Q4,10108
|
|
107
|
+
matlab_proxy-0.16.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
108
|
+
matlab_proxy-0.16.0.dist-info/entry_points.txt,sha256=DbBLYgnRt8UGiOpd0zHigRTyyMdZYhMdvCvSYP7wPN0,244
|
|
109
|
+
matlab_proxy-0.16.0.dist-info/top_level.txt,sha256=9uVTjsUCAS4TwsxueTBxrBg3PdBiTSsYowAkHPv9VY0,19
|
|
110
|
+
matlab_proxy-0.16.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
|
@@ -1031,7 +1031,7 @@ async def test_update_entitlement_with_correct_entitlement(set_licensing_info):
|
|
|
1031
1031
|
assert resp.status == HTTPStatus.OK
|
|
1032
1032
|
|
|
1033
1033
|
|
|
1034
|
-
async def test_get_auth_token_route(test_server
|
|
1034
|
+
async def test_get_auth_token_route(test_server):
|
|
1035
1035
|
"""Test to check endpoint : "/get_auth_token"
|
|
1036
1036
|
|
|
1037
1037
|
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
|
|
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"
|