matlab-proxy 0.14.0__py3-none-any.whl → 0.15.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 +52 -10
- 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.14aa7840.js → main.ff1bfd69.js} +3 -3
- matlab_proxy/gui/static/js/main.ff1bfd69.js.map +1 -0
- matlab_proxy/util/__init__.py +8 -1
- matlab_proxy/util/mwi/download.py +145 -0
- matlab_proxy/util/mwi/embedded_connector/helpers.py +1 -1
- matlab_proxy/util/mwi/embedded_connector/request.py +1 -1
- {matlab_proxy-0.14.0.dist-info → matlab_proxy-0.15.1.dist-info}/METADATA +1 -1
- {matlab_proxy-0.14.0.dist-info → matlab_proxy-0.15.1.dist-info}/RECORD +49 -16
- {matlab_proxy-0.14.0.dist-info → matlab_proxy-0.15.1.dist-info}/top_level.txt +1 -0
- tests/integration/__init__.py +1 -0
- tests/integration/integration_tests_with_license/__init__.py +1 -0
- tests/integration/integration_tests_with_license/conftest.py +47 -0
- tests/integration/integration_tests_with_license/test_http_end_points.py +223 -0
- tests/integration/integration_tests_without_license/__init__.py +1 -0
- tests/integration/integration_tests_without_license/conftest.py +115 -0
- tests/integration/integration_tests_without_license/test_matlab_is_down_if_unlicensed.py +49 -0
- tests/integration/utils/__init__.py +1 -0
- tests/integration/utils/integration_tests_utils.py +352 -0
- tests/integration/utils/licensing.py +152 -0
- tests/unit/__init__.py +1 -0
- tests/unit/conftest.py +67 -0
- tests/unit/test_app.py +1113 -0
- tests/unit/test_app_state.py +582 -0
- tests/unit/test_constants.py +5 -0
- tests/unit/test_ddux.py +22 -0
- tests/unit/test_devel.py +246 -0
- tests/unit/test_non_dev_mode.py +169 -0
- tests/unit/test_settings.py +460 -0
- tests/unit/util/__init__.py +3 -0
- tests/unit/util/mwi/__init__.py +1 -0
- tests/unit/util/mwi/embedded_connector/__init__.py +1 -0
- tests/unit/util/mwi/embedded_connector/test_helpers.py +29 -0
- tests/unit/util/mwi/embedded_connector/test_request.py +64 -0
- tests/unit/util/mwi/test_custom_http_headers.py +281 -0
- tests/unit/util/mwi/test_logger.py +49 -0
- tests/unit/util/mwi/test_token_auth.py +289 -0
- tests/unit/util/mwi/test_validators.py +331 -0
- tests/unit/util/test_mw.py +550 -0
- tests/unit/util/test_util.py +135 -0
- tests/utils/__init__.py +1 -0
- tests/utils/logging_util.py +81 -0
- matlab_proxy/gui/static/js/main.14aa7840.js.map +0 -1
- /matlab_proxy/gui/static/js/{main.14aa7840.js.LICENSE.txt → main.ff1bfd69.js.LICENSE.txt} +0 -0
- {matlab_proxy-0.14.0.dist-info → matlab_proxy-0.15.1.dist-info}/LICENSE.md +0 -0
- {matlab_proxy-0.14.0.dist-info → matlab_proxy-0.15.1.dist-info}/WHEEL +0 -0
- {matlab_proxy-0.14.0.dist-info → matlab_proxy-0.15.1.dist-info}/entry_points.txt +0 -0
matlab_proxy/app.py
CHANGED
|
@@ -4,6 +4,7 @@ import asyncio
|
|
|
4
4
|
import json
|
|
5
5
|
import mimetypes
|
|
6
6
|
import pkgutil
|
|
7
|
+
import secrets
|
|
7
8
|
import sys
|
|
8
9
|
import uuid
|
|
9
10
|
|
|
@@ -18,7 +19,7 @@ from matlab_proxy import constants, settings, util
|
|
|
18
19
|
from matlab_proxy.app_state import AppState
|
|
19
20
|
from matlab_proxy.util import mwi
|
|
20
21
|
from matlab_proxy.util.mwi import environment_variables as mwi_env
|
|
21
|
-
from matlab_proxy.util.mwi import token_auth
|
|
22
|
+
from matlab_proxy.util.mwi import token_auth, download
|
|
22
23
|
from matlab_proxy.util.mwi.exceptions import AppError, InvalidTokenError, LicensingError
|
|
23
24
|
from matlab_proxy.constants import IS_CONCURRENCY_CHECK_ENABLED
|
|
24
25
|
|
|
@@ -617,21 +618,24 @@ async def matlab_view(req):
|
|
|
617
618
|
) as client_session:
|
|
618
619
|
try:
|
|
619
620
|
req_body = await transform_body(req)
|
|
621
|
+
req_url = await transform_request_url(
|
|
622
|
+
req, matlab_base_url=matlab_base_url
|
|
623
|
+
)
|
|
620
624
|
# Set content length in case of modification
|
|
621
625
|
reqH["Content-Length"] = str(len(req_body))
|
|
622
626
|
reqH["x-forwarded-proto"] = "http"
|
|
623
627
|
|
|
624
628
|
async with client_session.request(
|
|
625
629
|
req.method,
|
|
626
|
-
|
|
630
|
+
req_url,
|
|
627
631
|
headers={**reqH, **{"mwapikey": mwapikey}},
|
|
628
632
|
allow_redirects=False,
|
|
629
633
|
data=req_body,
|
|
634
|
+
params=None,
|
|
630
635
|
) as res:
|
|
631
636
|
headers = res.headers.copy()
|
|
632
637
|
body = await res.read()
|
|
633
638
|
headers.update(req.app["settings"]["mwi_custom_http_headers"])
|
|
634
|
-
|
|
635
639
|
return web.Response(headers=headers, status=res.status, body=body)
|
|
636
640
|
|
|
637
641
|
# Handles any pending HTTP requests from the browser when the MATLAB process is terminated before responding to them.
|
|
@@ -652,6 +656,34 @@ async def matlab_view(req):
|
|
|
652
656
|
raise web.HTTPNotFound()
|
|
653
657
|
|
|
654
658
|
|
|
659
|
+
async def transform_request_url(req, matlab_base_url):
|
|
660
|
+
"""
|
|
661
|
+
Performs any transformations that may be required on the URL.
|
|
662
|
+
|
|
663
|
+
If the request is identified as a download request it transforms the request URL to
|
|
664
|
+
support downloading the file.
|
|
665
|
+
|
|
666
|
+
The original constructed URL is returned, when there are no transformations to be applied.
|
|
667
|
+
|
|
668
|
+
Args:
|
|
669
|
+
req: The request object that contains the relative URL and other request information.
|
|
670
|
+
matlab_base_url: The base URL of the MATLAB service to which the relative URL should be appended.
|
|
671
|
+
|
|
672
|
+
Returns:
|
|
673
|
+
A string representing the transformed URL, or the original URL.
|
|
674
|
+
"""
|
|
675
|
+
original_request_url = f"{matlab_base_url}{req.rel_url}"
|
|
676
|
+
|
|
677
|
+
if download.is_download_request(req):
|
|
678
|
+
download_url = await download.get_download_url(req)
|
|
679
|
+
if download_url:
|
|
680
|
+
transformed_request_url = f"{matlab_base_url}{download_url}"
|
|
681
|
+
logger.debug(f"Transformed Request url: {transformed_request_url}")
|
|
682
|
+
return transformed_request_url
|
|
683
|
+
|
|
684
|
+
return original_request_url
|
|
685
|
+
|
|
686
|
+
|
|
655
687
|
async def transform_body(req):
|
|
656
688
|
"""Transform HTTP POST requests as required by the MATLAB JavaScript Desktop.
|
|
657
689
|
|
|
@@ -764,6 +796,18 @@ def configure_and_start(app):
|
|
|
764
796
|
|
|
765
797
|
web_logger = None if not mwi_env.is_web_logging_enabled() else logger
|
|
766
798
|
|
|
799
|
+
# Setup the session storage,
|
|
800
|
+
# Uniqified per session to prevent multiple proxy servers on the same FQDN from interfering with each other.
|
|
801
|
+
uniqify_session_cookie = secrets.token_hex()
|
|
802
|
+
fernet_key = fernet.Fernet.generate_key()
|
|
803
|
+
f = fernet.Fernet(fernet_key)
|
|
804
|
+
aiohttp_session_setup(
|
|
805
|
+
app,
|
|
806
|
+
EncryptedCookieStorage(
|
|
807
|
+
f, cookie_name="matlab-proxy-session-" + uniqify_session_cookie
|
|
808
|
+
),
|
|
809
|
+
)
|
|
810
|
+
|
|
767
811
|
# Setup runner
|
|
768
812
|
runner = web.AppRunner(app, logger=web_logger, access_log=web_logger)
|
|
769
813
|
loop.run_until_complete(runner.setup())
|
|
@@ -839,13 +883,6 @@ def create_app(config_name=matlab_proxy.get_default_config_name()):
|
|
|
839
883
|
app.router.add_route("*", f"{base_url}/{{proxyPath:.*}}", matlab_view)
|
|
840
884
|
app.on_cleanup.append(cleanup_background_tasks)
|
|
841
885
|
|
|
842
|
-
# Setup the session storage
|
|
843
|
-
fernet_key = fernet.Fernet.generate_key()
|
|
844
|
-
f = fernet.Fernet(fernet_key)
|
|
845
|
-
aiohttp_session_setup(
|
|
846
|
-
app, EncryptedCookieStorage(f, cookie_name="matlab-proxy-session")
|
|
847
|
-
)
|
|
848
|
-
|
|
849
886
|
return app
|
|
850
887
|
|
|
851
888
|
|
|
@@ -925,3 +962,8 @@ def main():
|
|
|
925
962
|
desired_configuration_name = util.parse_cli_args()["config"]
|
|
926
963
|
|
|
927
964
|
create_and_start_app(config_name=desired_configuration_name)
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
# In support of enabling debugging in a Python Debugger (VSCode)
|
|
968
|
+
if __name__ == "__main__":
|
|
969
|
+
main()
|
matlab_proxy/constants.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "./static/css/main.47712126.css",
|
|
4
|
-
"main.js": "./static/js/main.
|
|
4
|
+
"main.js": "./static/js/main.ff1bfd69.js",
|
|
5
5
|
"static/media/mathworks-pictograms.svg?20181009": "./static/media/mathworks-pictograms.f6f087b008b5a9435f26.svg",
|
|
6
6
|
"static/media/MATLAB-env-blur.png": "./static/media/MATLAB-env-blur.4fc94edbc82d3184e5cb.png",
|
|
7
7
|
"static/media/mathworks.svg?20181004": "./static/media/mathworks.80a3218e1ba29f0573fb.svg",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"static/media/gripper.svg": "./static/media/gripper.9defbc5e76d0de8bb6e0.svg",
|
|
36
36
|
"static/media/arrow.svg": "./static/media/arrow.0c2968b90bd9a64c8c3f.svg",
|
|
37
37
|
"main.47712126.css.map": "./static/css/main.47712126.css.map",
|
|
38
|
-
"main.
|
|
38
|
+
"main.ff1bfd69.js.map": "./static/js/main.ff1bfd69.js.map"
|
|
39
39
|
},
|
|
40
40
|
"entrypoints": [
|
|
41
41
|
"static/css/main.47712126.css",
|
|
42
|
-
"static/js/main.
|
|
42
|
+
"static/js/main.ff1bfd69.js"
|
|
43
43
|
]
|
|
44
44
|
}
|
matlab_proxy/gui/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="MATLAB"/><meta name="internal_mw_identifier" content="MWI_MATLAB_PROXY_IDENTIFIER"/><link rel="manifest" href="./manifest.json"/><title>MATLAB</title><script defer="defer" src="./static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="MATLAB"/><meta name="internal_mw_identifier" content="MWI_MATLAB_PROXY_IDENTIFIER"/><link rel="manifest" href="./manifest.json"/><title>MATLAB</title><script defer="defer" src="./static/js/main.ff1bfd69.js"></script><link href="./static/css/main.47712126.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|