Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Handle CORS at ASGI level (#11415)

Patryk Zawadzkif573c10454ac
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48ff793db4..5cb3783e04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ All notable, unreleased changes to this project will be documented in this file.
- `PRODUCT_MEDIA_UPDATED`
- `PRODUCT_MEDIA_DELETED`
- `THUMBNAIL_CREATED`
+- CORS is now handled in the ASGI layer - #11415 by @patrys
# 3.11.0
diff --git a/poetry.lock b/poetry.lock
index 20e93a2863..35bc75fbb3 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -329,33 +329,24 @@ files = [
[[package]]
name = "black"
-version = "22.10.0"
+version = "22.12.0"
description = "The uncompromising code formatter."
category = "dev"
optional = false
python-versions = ">=3.7"
files = [
- {file = "black-22.10.0-1fixedarch-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:5cc42ca67989e9c3cf859e84c2bf014f6633db63d1cbdf8fdb666dcd9e77e3fa"},
- {file = "black-22.10.0-1fixedarch-cp311-cp311-macosx_11_0_x86_64.whl", hash = "sha256:5d8f74030e67087b219b032aa33a919fae8806d49c867846bfacde57f43972ef"},
- {file = "black-22.10.0-1fixedarch-cp37-cp37m-macosx_10_16_x86_64.whl", hash = "sha256:197df8509263b0b8614e1df1756b1dd41be6738eed2ba9e9769f3880c2b9d7b6"},
- {file = "black-22.10.0-1fixedarch-cp38-cp38-macosx_10_16_x86_64.whl", hash = "sha256:2644b5d63633702bc2c5f3754b1b475378fbbfb481f62319388235d0cd104c2d"},
- {file = "black-22.10.0-1fixedarch-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:e41a86c6c650bcecc6633ee3180d80a025db041a8e2398dcc059b3afa8382cd4"},
- {file = "black-22.10.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2039230db3c6c639bd84efe3292ec7b06e9214a2992cd9beb293d639c6402edb"},
- {file = "black-22.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:14ff67aec0a47c424bc99b71005202045dc09270da44a27848d534600ac64fc7"},
- {file = "black-22.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:819dc789f4498ecc91438a7de64427c73b45035e2e3680c92e18795a839ebb66"},
- {file = "black-22.10.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:5b9b29da4f564ba8787c119f37d174f2b69cdfdf9015b7d8c5c16121ddc054ae"},
- {file = "black-22.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8b49776299fece66bffaafe357d929ca9451450f5466e997a7285ab0fe28e3b"},
- {file = "black-22.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:21199526696b8f09c3997e2b4db8d0b108d801a348414264d2eb8eb2532e540d"},
- {file = "black-22.10.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1e464456d24e23d11fced2bc8c47ef66d471f845c7b7a42f3bd77bf3d1789650"},
- {file = "black-22.10.0-cp37-cp37m-win_amd64.whl", hash = "sha256:9311e99228ae10023300ecac05be5a296f60d2fd10fff31cf5c1fa4ca4b1988d"},
- {file = "black-22.10.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:fba8a281e570adafb79f7755ac8721b6cf1bbf691186a287e990c7929c7692ff"},
- {file = "black-22.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:915ace4ff03fdfff953962fa672d44be269deb2eaf88499a0f8805221bc68c87"},
- {file = "black-22.10.0-cp38-cp38-win_amd64.whl", hash = "sha256:444ebfb4e441254e87bad00c661fe32df9969b2bf224373a448d8aca2132b395"},
- {file = "black-22.10.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:974308c58d057a651d182208a484ce80a26dac0caef2895836a92dd6ebd725e0"},
- {file = "black-22.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:72ef3925f30e12a184889aac03d77d031056860ccae8a1e519f6cbb742736383"},
- {file = "black-22.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:432247333090c8c5366e69627ccb363bc58514ae3e63f7fc75c54b1ea80fa7de"},
- {file = "black-22.10.0-py3-none-any.whl", hash = "sha256:c957b2b4ea88587b46cf49d1dc17681c1e672864fd7af32fc1e9664d572b3458"},
- {file = "black-22.10.0.tar.gz", hash = "sha256:f513588da599943e0cde4e32cc9879e825d58720d6557062d1098c5ad80080e1"},
+ {file = "black-22.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9eedd20838bd5d75b80c9f5487dbcb06836a43833a37846cf1d8c1cc01cef59d"},
+ {file = "black-22.12.0-cp310-cp310-win_amd64.whl", hash = "sha256:159a46a4947f73387b4d83e87ea006dbb2337eab6c879620a3ba52699b1f4351"},
+ {file = "black-22.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d30b212bffeb1e252b31dd269dfae69dd17e06d92b87ad26e23890f3efea366f"},
+ {file = "black-22.12.0-cp311-cp311-win_amd64.whl", hash = "sha256:7412e75863aa5c5411886804678b7d083c7c28421210180d67dfd8cf1221e1f4"},
+ {file = "black-22.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c116eed0efb9ff870ded8b62fe9f28dd61ef6e9ddd28d83d7d264a38417dcee2"},
+ {file = "black-22.12.0-cp37-cp37m-win_amd64.whl", hash = "sha256:1f58cbe16dfe8c12b7434e50ff889fa479072096d79f0a7f25e4ab8e94cd8350"},
+ {file = "black-22.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:77d86c9f3db9b1bf6761244bc0b3572a546f5fe37917a044e02f3166d5aafa7d"},
+ {file = "black-22.12.0-cp38-cp38-win_amd64.whl", hash = "sha256:82d9fe8fee3401e02e79767016b4907820a7dc28d70d137eb397b92ef3cc5bfc"},
+ {file = "black-22.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:101c69b23df9b44247bd88e1d7e90154336ac4992502d4197bdac35dd7ee3320"},
+ {file = "black-22.12.0-cp39-cp39-win_amd64.whl", hash = "sha256:559c7a1ba9a006226f09e4916060982fd27334ae1998e7a38b3f33a37f7a2148"},
+ {file = "black-22.12.0-py3-none-any.whl", hash = "sha256:436cc9167dd28040ad90d3b404aec22cedf24a6e4d7de221bec2730ec0c97bcf"},
+ {file = "black-22.12.0.tar.gz", hash = "sha256:229351e5a18ca30f447bf724d007f890f97e13af070bb6ad4c0a441cd7596a2f"},
]
[package.dependencies]
@@ -451,6 +442,16 @@ files = [
{file = "Brotli-1.0.9-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b83bb06a0192cccf1eb8d0a28672a1b79c74c3a8a5f2619625aeb6f28b3a82bb"},
{file = "Brotli-1.0.9-cp310-cp310-win32.whl", hash = "sha256:26d168aac4aaec9a4394221240e8a5436b5634adc3cd1cdf637f6645cecbf181"},
{file = "Brotli-1.0.9-cp310-cp310-win_amd64.whl", hash = "sha256:622a231b08899c864eb87e85f81c75e7b9ce05b001e59bbfbf43d4a71f5f32b2"},
+ {file = "Brotli-1.0.9-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:cc0283a406774f465fb45ec7efb66857c09ffefbe49ec20b7882eff6d3c86d3a"},
+ {file = "Brotli-1.0.9-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:11d3283d89af7033236fa4e73ec2cbe743d4f6a81d41bd234f24bf63dde979df"},
+ {file = "Brotli-1.0.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3c1306004d49b84bd0c4f90457c6f57ad109f5cc6067a9664e12b7b79a9948ad"},
+ {file = "Brotli-1.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b1375b5d17d6145c798661b67e4ae9d5496920d9265e2f00f1c2c0b5ae91fbde"},
+ {file = "Brotli-1.0.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cab1b5964b39607a66adbba01f1c12df2e55ac36c81ec6ed44f2fca44178bf1a"},
+ {file = "Brotli-1.0.9-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:8ed6a5b3d23ecc00ea02e1ed8e0ff9a08f4fc87a1f58a2530e71c0f48adf882f"},
+ {file = "Brotli-1.0.9-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:cb02ed34557afde2d2da68194d12f5719ee96cfb2eacc886352cb73e3808fc5d"},
+ {file = "Brotli-1.0.9-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:b3523f51818e8f16599613edddb1ff924eeb4b53ab7e7197f85cbc321cdca32f"},
+ {file = "Brotli-1.0.9-cp311-cp311-win32.whl", hash = "sha256:ba72d37e2a924717990f4d7482e8ac88e2ef43fb95491eb6e0d124d77d2a150d"},
+ {file = "Brotli-1.0.9-cp311-cp311-win_amd64.whl", hash = "sha256:3ffaadcaeafe9d30a7e4e1e97ad727e4f5610b9fa2f7551998471e3736738679"},
{file = "Brotli-1.0.9-cp35-cp35m-macosx_10_6_intel.whl", hash = "sha256:c83aa123d56f2e060644427a882a36b3c12db93727ad7a7b9efd7d7f3e9cc2c4"},
{file = "Brotli-1.0.9-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:6b2ae9f5f67f89aade1fab0f7fd8f2832501311c363a21579d02defa844d9296"},
{file = "Brotli-1.0.9-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:68715970f16b6e92c574c30747c95cf8cf62804569647386ff032195dc89a430"},
@@ -495,7 +496,17 @@ files = [
{file = "Brotli-1.0.9-cp39-cp39-win32.whl", hash = "sha256:cfc391f4429ee0a9370aa93d812a52e1fee0f37a81861f4fdd1f4fb28e8547c3"},
{file = "Brotli-1.0.9-cp39-cp39-win_amd64.whl", hash = "sha256:854c33dad5ba0fbd6ab69185fec8dab89e13cda6b7d191ba111987df74f38761"},
{file = "Brotli-1.0.9-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:9749a124280a0ada4187a6cfd1ffd35c350fb3af79c706589d98e088c5044267"},
+ {file = "Brotli-1.0.9-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:73fd30d4ce0ea48010564ccee1a26bfe39323fde05cb34b5863455629db61dc7"},
+ {file = "Brotli-1.0.9-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:02177603aaca36e1fd21b091cb742bb3b305a569e2402f1ca38af471777fb019"},
{file = "Brotli-1.0.9-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:76ffebb907bec09ff511bb3acc077695e2c32bc2142819491579a695f77ffd4d"},
+ {file = "Brotli-1.0.9-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:b43775532a5904bc938f9c15b77c613cb6ad6fb30990f3b0afaea82797a402d8"},
+ {file = "Brotli-1.0.9-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:5bf37a08493232fbb0f8229f1824b366c2fc1d02d64e7e918af40acd15f3e337"},
+ {file = "Brotli-1.0.9-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:330e3f10cd01da535c70d09c4283ba2df5fb78e915bea0a28becad6e2ac010be"},
+ {file = "Brotli-1.0.9-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:e1abbeef02962596548382e393f56e4c94acd286bd0c5afba756cffc33670e8a"},
+ {file = "Brotli-1.0.9-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:3148362937217b7072cf80a2dcc007f09bb5ecb96dae4617316638194113d5be"},
+ {file = "Brotli-1.0.9-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:336b40348269f9b91268378de5ff44dc6fbaa2268194f85177b53463d313842a"},
+ {file = "Brotli-1.0.9-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3b8b09a16a1950b9ef495a0f8b9d0a87599a9d1f179e2d4ac014b2ec831f87e7"},
+ {file = "Brotli-1.0.9-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:c8e521a0ce7cf690ca84b8cc2272ddaf9d8a50294fd086da67e517439614c755"},
{file = "Brotli-1.0.9.zip", hash = "sha256:4d1b810aa0ed773f81dceda2cc7b403d01057458730e309856356d4ef4188438"},
]
@@ -800,7 +811,6 @@ optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
files = [
{file = "codecov-2.1.12-py2.py3-none-any.whl", hash = "sha256:585dc217dc3d8185198ceb402f85d5cb5dbfa0c5f350a5abcdf9e347776a5b47"},
- {file = "codecov-2.1.12-py3.8.egg", hash = "sha256:782a8e5352f22593cbc5427a35320b99490eb24d9dcfa2155fd99d2b75cfb635"},
{file = "codecov-2.1.12.tar.gz", hash = "sha256:a0da46bb5025426da895af90938def8ee12d37fcbcbbbc15b6dc64cf7ebc51c1"},
]
@@ -907,6 +917,8 @@ files = [
{file = "cryptography-39.0.1-cp36-abi3-win32.whl", hash = "sha256:fe913f20024eb2cb2f323e42a64bdf2911bb9738a15dba7d3cce48151034e3a8"},
{file = "cryptography-39.0.1-cp36-abi3-win_amd64.whl", hash = "sha256:ced4e447ae29ca194449a3f1ce132ded8fcab06971ef5f618605aacaa612beac"},
{file = "cryptography-39.0.1-pp38-pypy38_pp73-macosx_10_12_x86_64.whl", hash = "sha256:807ce09d4434881ca3a7594733669bd834f5b2c6d5c7e36f8c00f691887042ad"},
+ {file = "cryptography-39.0.1-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c5caeb8188c24888c90b5108a441c106f7faa4c4c075a2bcae438c6e8ca73cef"},
+ {file = "cryptography-39.0.1-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:4789d1e3e257965e960232345002262ede4d094d1a19f4d3b52e48d4d8f3b885"},
{file = "cryptography-39.0.1-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:96f1157a7c08b5b189b16b47bc9db2332269d6680a196341bf30046330d15388"},
{file = "cryptography-39.0.1-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:e422abdec8b5fa8462aa016786680720d78bdce7a30c652b7fadf83a4ba35336"},
{file = "cryptography-39.0.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl", hash = "sha256:b0afd054cd42f3d213bf82c629efb1ee5f22eba35bf0eec88ea9ea7304f511a2"},
@@ -1358,27 +1370,33 @@ sftp = ["paramiko"]
[[package]]
name = "django-stubs"
-version = "1.8.0"
+version = "1.14.0"
description = "Mypy stubs for Django"
category = "dev"
optional = false
-python-versions = ">=3.6"
+python-versions = ">=3.7"
files = [
- {file = "django-stubs-1.8.0.tar.gz", hash = "sha256:717967d7fee0a6af0746724a0be80d72831a982a40fa8f245a6a46f4cafd157b"},
- {file = "django_stubs-1.8.0-py3-none-any.whl", hash = "sha256:bde9e44e3c4574c2454e74a3e607cc3bc23b0441bb7d1312cd677d5e30984b74"},
+ {file = "django-stubs-1.14.0.tar.gz", hash = "sha256:d53bcd4975a54ca5c9abbbd33b61f40d44191971018f2ea54f73b0a6a99e1a8b"},
+ {file = "django_stubs-1.14.0-py3-none-any.whl", hash = "sha256:b081d64d923171f79d4e57899b0980da847e4046b91166e3658a6151645a36c5"},
]
[package.dependencies]
django = "*"
-django-stubs-ext = "*"
-mypy = ">=0.790"
+django-stubs-ext = ">=0.7.0"
+mypy = ">=0.980"
+tomli = "*"
+types-pytz = "*"
+types-PyYAML = "*"
typing-extensions = "*"
+[package.extras]
+compatible-mypy = ["mypy (>=0.991,<1.0)"]
+
[[package]]
name = "django-stubs-ext"
version = "0.7.0"
description = "Monkey-patching and extensions for django-stubs"
-category = "dev"
+category = "main"
optional = false
python-versions = ">=3.7"
files = [
@@ -2723,36 +2741,38 @@ files = [
[[package]]
name = "mypy"
-version = "0.982"
+version = "1.0.0"
description = "Optional static typing for Python"
category = "dev"
optional = false
python-versions = ">=3.7"
files = [
- {file = "mypy-0.982-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:5085e6f442003fa915aeb0a46d4da58128da69325d8213b4b35cc7054090aed5"},
- {file = "mypy-0.982-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:41fd1cf9bc0e1c19b9af13a6580ccb66c381a5ee2cf63ee5ebab747a4badeba3"},
- {file = "mypy-0.982-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:f793e3dd95e166b66d50e7b63e69e58e88643d80a3dcc3bcd81368e0478b089c"},
- {file = "mypy-0.982-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:86ebe67adf4d021b28c3f547da6aa2cce660b57f0432617af2cca932d4d378a6"},
- {file = "mypy-0.982-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:175f292f649a3af7082fe36620369ffc4661a71005aa9f8297ea473df5772046"},
- {file = "mypy-0.982-cp310-cp310-win_amd64.whl", hash = "sha256:8ee8c2472e96beb1045e9081de8e92f295b89ac10c4109afdf3a23ad6e644f3e"},
- {file = "mypy-0.982-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:58f27ebafe726a8e5ccb58d896451dd9a662a511a3188ff6a8a6a919142ecc20"},
- {file = "mypy-0.982-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d6af646bd46f10d53834a8e8983e130e47d8ab2d4b7a97363e35b24e1d588947"},
- {file = "mypy-0.982-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:e7aeaa763c7ab86d5b66ff27f68493d672e44c8099af636d433a7f3fa5596d40"},
- {file = "mypy-0.982-cp37-cp37m-win_amd64.whl", hash = "sha256:724d36be56444f569c20a629d1d4ee0cb0ad666078d59bb84f8f887952511ca1"},
- {file = "mypy-0.982-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:14d53cdd4cf93765aa747a7399f0961a365bcddf7855d9cef6306fa41de01c24"},
- {file = "mypy-0.982-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:26ae64555d480ad4b32a267d10cab7aec92ff44de35a7cd95b2b7cb8e64ebe3e"},
- {file = "mypy-0.982-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:6389af3e204975d6658de4fb8ac16f58c14e1bacc6142fee86d1b5b26aa52bda"},
- {file = "mypy-0.982-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7b35ce03a289480d6544aac85fa3674f493f323d80ea7226410ed065cd46f206"},
- {file = "mypy-0.982-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:c6e564f035d25c99fd2b863e13049744d96bd1947e3d3d2f16f5828864506763"},
- {file = "mypy-0.982-cp38-cp38-win_amd64.whl", hash = "sha256:cebca7fd333f90b61b3ef7f217ff75ce2e287482206ef4a8b18f32b49927b1a2"},
- {file = "mypy-0.982-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:a705a93670c8b74769496280d2fe6cd59961506c64f329bb179970ff1d24f9f8"},
- {file = "mypy-0.982-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:75838c649290d83a2b83a88288c1eb60fe7a05b36d46cbea9d22efc790002146"},
- {file = "mypy-0.982-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:91781eff1f3f2607519c8b0e8518aad8498af1419e8442d5d0afb108059881fc"},
- {file = "mypy-0.982-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaa97b9ddd1dd9901a22a879491dbb951b5dec75c3b90032e2baa7336777363b"},
- {file = "mypy-0.982-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a692a8e7d07abe5f4b2dd32d731812a0175626a90a223d4b58f10f458747dd8a"},
- {file = "mypy-0.982-cp39-cp39-win_amd64.whl", hash = "sha256:eb7a068e503be3543c4bd329c994103874fa543c1727ba5288393c21d912d795"},
- {file = "mypy-0.982-py3-none-any.whl", hash = "sha256:1021c241e8b6e1ca5a47e4d52601274ac078a89845cfde66c6d5f769819ffa1d"},
- {file = "mypy-0.982.tar.gz", hash = "sha256:85f7a343542dc8b1ed0a888cdd34dca56462654ef23aa673907305b260b3d746"},
+ {file = "mypy-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e0626db16705ab9f7fa6c249c017c887baf20738ce7f9129da162bb3075fc1af"},
+ {file = "mypy-1.0.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1ace23f6bb4aec4604b86c4843276e8fa548d667dbbd0cb83a3ae14b18b2db6c"},
+ {file = "mypy-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:87edfaf344c9401942883fad030909116aa77b0fa7e6e8e1c5407e14549afe9a"},
+ {file = "mypy-1.0.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:0ab090d9240d6b4e99e1fa998c2d0aa5b29fc0fb06bd30e7ad6183c95fa07593"},
+ {file = "mypy-1.0.0-cp310-cp310-win_amd64.whl", hash = "sha256:7cc2c01dfc5a3cbddfa6c13f530ef3b95292f926329929001d45e124342cd6b7"},
+ {file = "mypy-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:14d776869a3e6c89c17eb943100f7868f677703c8a4e00b3803918f86aafbc52"},
+ {file = "mypy-1.0.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bb2782a036d9eb6b5a6efcdda0986774bf798beef86a62da86cb73e2a10b423d"},
+ {file = "mypy-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cfca124f0ac6707747544c127880893ad72a656e136adc935c8600740b21ff5"},
+ {file = "mypy-1.0.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:8845125d0b7c57838a10fd8925b0f5f709d0e08568ce587cc862aacce453e3dd"},
+ {file = "mypy-1.0.0-cp311-cp311-win_amd64.whl", hash = "sha256:01b1b9e1ed40544ef486fa8ac022232ccc57109f379611633ede8e71630d07d2"},
+ {file = "mypy-1.0.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:c7cf862aef988b5fbaa17764ad1d21b4831436701c7d2b653156a9497d92c83c"},
+ {file = "mypy-1.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cd187d92b6939617f1168a4fe68f68add749902c010e66fe574c165c742ed88"},
+ {file = "mypy-1.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:4e5175026618c178dfba6188228b845b64131034ab3ba52acaffa8f6c361f805"},
+ {file = "mypy-1.0.0-cp37-cp37m-win_amd64.whl", hash = "sha256:2f6ac8c87e046dc18c7d1d7f6653a66787a4555085b056fe2d599f1f1a2a2d21"},
+ {file = "mypy-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7306edca1c6f1b5fa0bc9aa645e6ac8393014fa82d0fa180d0ebc990ebe15964"},
+ {file = "mypy-1.0.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:3cfad08f16a9c6611e6143485a93de0e1e13f48cfb90bcad7d5fde1c0cec3d36"},
+ {file = "mypy-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:67cced7f15654710386e5c10b96608f1ee3d5c94ca1da5a2aad5889793a824c1"},
+ {file = "mypy-1.0.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:a86b794e8a56ada65c573183756eac8ac5b8d3d59daf9d5ebd72ecdbb7867a43"},
+ {file = "mypy-1.0.0-cp38-cp38-win_amd64.whl", hash = "sha256:50979d5efff8d4135d9db293c6cb2c42260e70fb010cbc697b1311a4d7a39ddb"},
+ {file = "mypy-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3ae4c7a99e5153496243146a3baf33b9beff714464ca386b5f62daad601d87af"},
+ {file = "mypy-1.0.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5e398652d005a198a7f3c132426b33c6b85d98aa7dc852137a2a3be8890c4072"},
+ {file = "mypy-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be78077064d016bc1b639c2cbcc5be945b47b4261a4f4b7d8923f6c69c5c9457"},
+ {file = "mypy-1.0.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:92024447a339400ea00ac228369cd242e988dd775640755fa4ac0c126e49bb74"},
+ {file = "mypy-1.0.0-cp39-cp39-win_amd64.whl", hash = "sha256:fe523fcbd52c05040c7bee370d66fee8373c5972171e4fbc323153433198592d"},
+ {file = "mypy-1.0.0-py3-none-any.whl", hash = "sha256:2efa963bdddb27cb4a0d42545cd137a8d2b883bd181bbc4525b568ef6eca258f"},
+ {file = "mypy-1.0.0.tar.gz", hash = "sha256:f34495079c8d9da05b183f9f7daec2878280c2ad7cc81da686ef0b484cea2ecf"},
]
[package.dependencies]
@@ -2762,19 +2782,20 @@ typing-extensions = ">=3.10"
[package.extras]
dmypy = ["psutil (>=4.0)"]
+install-types = ["pip"]
python2 = ["typed-ast (>=1.4.0,<2)"]
reports = ["lxml"]
[[package]]
name = "mypy-extensions"
-version = "0.4.3"
-description = "Experimental type system extensions for programs checked with the mypy typechecker."
+version = "1.0.0"
+description = "Type system extensions for programs checked with the mypy type checker."
category = "dev"
optional = false
-python-versions = "*"
+python-versions = ">=3.5"
files = [
- {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
- {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
+ {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"},
+ {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"},
]
[[package]]
@@ -2867,13 +2888,13 @@ files = [
[[package]]
name = "petl"
-version = "1.7.11"
+version = "1.7.12"
description = "A Python package for extracting, transforming and loading tables of data."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
files = [
- {file = "petl-1.7.11.tar.gz", hash = "sha256:b067760e7de988031f6c16cec8b19f2ef7ac2d02ff07cb9365331e88fcfbed3c"},
+ {file = "petl-1.7.12.tar.gz", hash = "sha256:d4a94e0d6f1274062fe92353b99a007ee12c7c84b4c31c0cb9713ed5dbda22e7"},
]
[package.extras]
@@ -3143,6 +3164,8 @@ python-versions = ">=3.6"
files = [
{file = "psycopg2-2.9.5-cp310-cp310-win32.whl", hash = "sha256:d3ef67e630b0de0779c42912fe2cbae3805ebaba30cda27fea2a3de650a9414f"},
{file = "psycopg2-2.9.5-cp310-cp310-win_amd64.whl", hash = "sha256:4cb9936316d88bfab614666eb9e32995e794ed0f8f6b3b718666c22819c1d7ee"},
+ {file = "psycopg2-2.9.5-cp311-cp311-win32.whl", hash = "sha256:093e3894d2d3c592ab0945d9eba9d139c139664dcf83a1c440b8a7aa9bb21955"},
+ {file = "psycopg2-2.9.5-cp311-cp311-win_amd64.whl", hash = "sha256:920bf418000dd17669d2904472efeab2b20546efd0548139618f8fa305d1d7ad"},
{file = "psycopg2-2.9.5-cp36-cp36m-win32.whl", hash = "sha256:b9ac1b0d8ecc49e05e4e182694f418d27f3aedcfca854ebd6c05bb1cffa10d6d"},
{file = "psycopg2-2.9.5-cp36-cp36m-win_amd64.whl", hash = "sha256:fc04dd5189b90d825509caa510f20d1d504761e78b8dfb95a0ede180f71d50e5"},
{file = "psycopg2-2.9.5-cp37-cp37m-win32.whl", hash = "sha256:922cc5f0b98a5f2b1ff481f5551b95cd04580fd6f0c72d9b22e6c0145a4840e0"},
@@ -3162,18 +3185,7 @@ category = "main"
optional = false
python-versions = "*"
files = [
- {file = "pyasn1-0.4.8-py2.4.egg", hash = "sha256:fec3e9d8e36808a28efb59b489e4528c10ad0f480e57dcc32b4de5c9d8c9fdf3"},
- {file = "pyasn1-0.4.8-py2.5.egg", hash = "sha256:0458773cfe65b153891ac249bcf1b5f8f320b7c2ce462151f8fa74de8934becf"},
- {file = "pyasn1-0.4.8-py2.6.egg", hash = "sha256:5c9414dcfede6e441f7e8f81b43b34e834731003427e5b09e4e00e3172a10f00"},
- {file = "pyasn1-0.4.8-py2.7.egg", hash = "sha256:6e7545f1a61025a4e58bb336952c5061697da694db1cae97b116e9c46abcf7c8"},
{file = "pyasn1-0.4.8-py2.py3-none-any.whl", hash = "sha256:39c7e2ec30515947ff4e87fb6f456dfc6e84857d34be479c9d4a4ba4bf46aa5d"},
- {file = "pyasn1-0.4.8-py3.1.egg", hash = "sha256:78fa6da68ed2727915c4767bb386ab32cdba863caa7dbe473eaae45f9959da86"},
- {file = "pyasn1-0.4.8-py3.2.egg", hash = "sha256:08c3c53b75eaa48d71cf8c710312316392ed40899cb34710d092e96745a358b7"},
- {file = "pyasn1-0.4.8-py3.3.egg", hash = "sha256:03840c999ba71680a131cfaee6fab142e1ed9bbd9c693e285cc6aca0d555e576"},
- {file = "pyasn1-0.4.8-py3.4.egg", hash = "sha256:7ab8a544af125fb704feadb008c99a88805126fb525280b2270bb25cc1d78a12"},
- {file = "pyasn1-0.4.8-py3.5.egg", hash = "sha256:e89bf84b5437b532b0803ba5c9a5e054d21fec423a89952a74f87fa2c9b7bce2"},
- {file = "pyasn1-0.4.8-py3.6.egg", hash = "sha256:014c0e9976956a08139dc0712ae195324a75e142284d5f87f1a87ee1b068a359"},
- {file = "pyasn1-0.4.8-py3.7.egg", hash = "sha256:99fcc3c8d804d1bc6d9a099921e39d827026409a58f2a720dcdb89374ea0c776"},
{file = "pyasn1-0.4.8.tar.gz", hash = "sha256:aef77c9fb94a3ac588e87841208bdec464471d9871bd5050a287cc9a475cd0ba"},
]
@@ -3186,18 +3198,7 @@ optional = false
python-versions = "*"
files = [
{file = "pyasn1-modules-0.2.8.tar.gz", hash = "sha256:905f84c712230b2c592c19470d3ca8d552de726050d1d1716282a1f6146be65e"},
- {file = "pyasn1_modules-0.2.8-py2.4.egg", hash = "sha256:0fe1b68d1e486a1ed5473f1302bd991c1611d319bba158e98b106ff86e1d7199"},
- {file = "pyasn1_modules-0.2.8-py2.5.egg", hash = "sha256:fe0644d9ab041506b62782e92b06b8c68cca799e1a9636ec398675459e031405"},
- {file = "pyasn1_modules-0.2.8-py2.6.egg", hash = "sha256:a99324196732f53093a84c4369c996713eb8c89d360a496b599fb1a9c47fc3eb"},
- {file = "pyasn1_modules-0.2.8-py2.7.egg", hash = "sha256:0845a5582f6a02bb3e1bde9ecfc4bfcae6ec3210dd270522fee602365430c3f8"},
{file = "pyasn1_modules-0.2.8-py2.py3-none-any.whl", hash = "sha256:a50b808ffeb97cb3601dd25981f6b016cbb3d31fbf57a8b8a87428e6158d0c74"},
- {file = "pyasn1_modules-0.2.8-py3.1.egg", hash = "sha256:f39edd8c4ecaa4556e989147ebf219227e2cd2e8a43c7e7fcb1f1c18c5fd6a3d"},
- {file = "pyasn1_modules-0.2.8-py3.2.egg", hash = "sha256:b80486a6c77252ea3a3e9b1e360bc9cf28eaac41263d173c032581ad2f20fe45"},
- {file = "pyasn1_modules-0.2.8-py3.3.egg", hash = "sha256:65cebbaffc913f4fe9e4808735c95ea22d7a7775646ab690518c056784bc21b4"},
- {file = "pyasn1_modules-0.2.8-py3.4.egg", hash = "sha256:15b7c67fabc7fc240d87fb9aabf999cf82311a6d6fb2c70d00d3d0604878c811"},
- {file = "pyasn1_modules-0.2.8-py3.5.egg", hash = "sha256:426edb7a5e8879f1ec54a1864f16b882c2837bfd06eee62f2c982315ee2473ed"},
- {file = "pyasn1_modules-0.2.8-py3.6.egg", hash = "sha256:cbac4bc38d117f2a49aeedec4407d23e8866ea4ac27ff2cf7fb3e5b570df19e0"},
- {file = "pyasn1_modules-0.2.8-py3.7.egg", hash = "sha256:c29a5e5cc7a3f05926aff34e097e84f8589cd790ce0ed41b67aed6857b26aafd"},
]
[package.dependencies]
@@ -3449,6 +3450,25 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""}
[package.extras]
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"]
+[[package]]
+name = "pytest-asyncio"
+version = "0.20.3"
+description = "Pytest support for asyncio"
+category = "dev"
+optional = false
+python-versions = ">=3.7"
+files = [
+ {file = "pytest-asyncio-0.20.3.tar.gz", hash = "sha256:83cbf01169ce3e8eb71c6c278ccb0574d1a7a3bb8eaaf5e50e0ad342afb33b36"},
+ {file = "pytest_asyncio-0.20.3-py3-none-any.whl", hash = "sha256:f129998b209d04fcc65c96fc85c11e5316738358909a8399e93be553d7656442"},
+]
+
+[package.dependencies]
+pytest = ">=6.1.0"
+
+[package.extras]
+docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"]
+testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy (>=0.931)", "pytest-trio (>=0.7.0)"]
+
[[package]]
name = "pytest-celery"
version = "0.0.0"
@@ -3605,6 +3625,7 @@ optional = false
python-versions = "*"
files = [
{file = "python-crontab-2.6.0.tar.gz", hash = "sha256:1e35ed7a3cdc3100545b43e196d34754e6551e7f95e4caebbe0e1c0ca41c2f1b"},
+ {file = "python_crontab-2.6.0-py3-none-any.whl", hash = "sha256:f308a64b8b1d072da4a235e9320398a242e92d080c1d8143bd0c600b24e160f8"},
]
[package.dependencies]
@@ -4305,6 +4326,18 @@ files = [
{file = "types_pytz-2022.6.0.1-py3-none-any.whl", hash = "sha256:bea605ce5d5a5d52a8e1afd7656c9b42476e18a0f888de6be91587355313ddf4"},
]
+[[package]]
+name = "types-pyyaml"
+version = "6.0.12.5"
+description = "Typing stubs for PyYAML"
+category = "dev"
+optional = false
+python-versions = "*"
+files = [
+ {file = "types-PyYAML-6.0.12.5.tar.gz", hash = "sha256:3b61b7a8111ce368eb366e4a13f3e94e568bc2ed6227e01520a50ee07993bf38"},
+ {file = "types_PyYAML-6.0.12.5-py3-none-any.whl", hash = "sha256:dcaf87b65b839e7b641721346ef8b12a87f94071e15205a64ac93ca0e0afc77a"},
+]
+
[[package]]
name = "types-redis"
version = "4.3.21.4"
@@ -4906,4 +4939,4 @@ test = ["pytest"]
[metadata]
lock-version = "2.0"
python-versions = "~3.9"
-content-hash = "4264f9b6c4c67d0e0415f6ce579d1646b58b12199766fb14be745dad23339316"
+content-hash = "aa2dd6b276d12bf5816734c3ec147cb13be8a610aa5a86a637d8ad0b53b26d06"
diff --git a/pyproject.toml b/pyproject.toml
index 083d9f3078..c25b871226 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -103,12 +103,14 @@ documentation = "https://docs.saleor.io/"
pylint-django = "^2.4.4"
pylint-plugin-utils = "^0"
pytest = "^7.0.1"
+ pytest-asyncio = "^0.20.3"
pytest-celery = "^0.0.0"
pytest-cov = "^4.0.0"
pytest-django = "4.5.2"
pytest-django-queries = "~1.2"
pytest-mock = "^3.6.1"
pytest-recording = "^0.12.0"
+ pytest-socket = "^0.5.1"
pytest-xdist = "^3.0.2"
mypy = "^1.0.0"
mypy-extensions = "^1.0.0"
@@ -119,8 +121,7 @@ documentation = "https://docs.saleor.io/"
types-pytz = "^2022.1.1"
types-pkg-resources = "^0.1.3"
types-python-dateutil = "^2.8.19"
- django-stubs = "^1.13.1"
- pytest-socket = "^0.5.1"
+ django-stubs = "^1.14.0"
before_after = "^1.0.1"
types-certifi = "^2021.10.8"
types-freezegun = "^1.1.7"
diff --git a/requirements_dev.txt b/requirements_dev.txt
index fa459af0c8..6768c13580 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -163,6 +163,7 @@ pylint-plugin-utils==0.7 ; python_version >= "3.9" and python_version < "3.10"
pylint==2.16.1 ; python_version >= "3.9" and python_version < "3.10"
pymeta3==0.5.1 ; python_version >= "3.9" and python_version < "3.10"
pyphen==0.13.2 ; python_version >= "3.9" and python_version < "3.10"
+pytest-asyncio==0.20.3 ; python_version >= "3.9" and python_version < "3.10"
pytest-celery==0.0.0 ; python_version >= "3.9" and python_version < "3.10"
pytest-cov==4.0.0 ; python_version >= "3.9" and python_version < "3.10"
pytest-django-queries==1.2.0 ; python_version >= "3.9" and python_version < "3.10"
diff --git a/saleor/__main__.py b/saleor/__main__.py
new file mode 100644
index 0000000000..f384ab04b9
--- /dev/null
+++ b/saleor/__main__.py
@@ -0,0 +1,7 @@
+import uvicorn
+
+config = uvicorn.Config(
+ "saleor.asgi:application", port=8000, reload=True, lifespan="off"
+)
+server = uvicorn.Server(config)
+server.run()
diff --git a/saleor/asgi/__init__.py b/saleor/asgi/__init__.py
index 65b73546f7..3c181c0229 100644
--- a/saleor/asgi/__init__.py
+++ b/saleor/asgi/__init__.py
@@ -10,9 +10,11 @@ import os
from django.core.asgi import get_asgi_application
+from saleor.asgi.cors_handler import cors_handler
from saleor.asgi.health_check import health_check
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saleor.settings")
application = get_asgi_application()
-application = health_check(application, "/health/")
+application = health_check(application, "/health/") # type: ignore[arg-type] # Django's ASGI app is less strict than the spec # noqa: E501
+application = cors_handler(application)
diff --git a/saleor/asgi/cors_handler.py b/saleor/asgi/cors_handler.py
new file mode 100644
index 0000000000..8c514c5657
--- /dev/null
+++ b/saleor/asgi/cors_handler.py
@@ -0,0 +1,69 @@
+from fnmatch import fnmatchcase
+from typing import Tuple, cast
+
+from asgiref.typing import (
+ ASGI3Application,
+ ASGIReceiveCallable,
+ ASGISendCallable,
+ HTTPResponseBodyEvent,
+ HTTPResponseStartEvent,
+ HTTPScope,
+ Scope,
+)
+from django.conf import settings
+
+
+def cors_handler(application: ASGI3Application) -> ASGI3Application:
+ async def cors_wrapper(
+ scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable
+ ) -> None:
+ # handle CORS preflight requests
+ if scope.get("type") == "http" and scope.get("method") == "OPTIONS":
+ scope = cast(HTTPScope, scope)
+ response_headers: list[Tuple[bytes, bytes]] = [
+ (b"access-control-allow-credentials", b"true"),
+ (
+ b"access-control-allow-headers",
+ b"Origin, Content-Type, Accept, Authorization, "
+ b"Authorization-Bearer",
+ ),
+ (b"access-control-allow-methods", b"POST, OPTIONS"),
+ (b"access-control-max-age", b"600"),
+ (b"vary", b"Origin"),
+ ]
+ # determine the origin of the request
+ request_origin: str = ""
+ for header, value in scope.get("headers", []):
+ if header == b"origin":
+ request_origin = value.decode("latin1")
+ # if the origin is allowed, add the appropriate CORS headers
+ origin_match = False
+ if request_origin:
+ for allowed_origin in settings.ALLOWED_GRAPHQL_ORIGINS:
+ if fnmatchcase(request_origin, allowed_origin):
+ origin_match = True
+ break
+ if origin_match:
+ response_headers.append(
+ (
+ b"access-control-allow-origin",
+ request_origin.encode("latin1"),
+ )
+ )
+ await send(
+ HTTPResponseStartEvent(
+ type="http.response.start",
+ status=200 if origin_match else 400,
+ headers=sorted(response_headers),
+ trailers=False,
+ )
+ )
+ await send(
+ HTTPResponseBodyEvent(
+ type="http.response.body", body=b"", more_body=False
+ )
+ )
+ else:
+ await application(scope, receive, send)
+
+ return cors_wrapper
diff --git a/saleor/asgi/health_check.py b/saleor/asgi/health_check.py
index af53223216..b642674bdb 100644
--- a/saleor/asgi/health_check.py
+++ b/saleor/asgi/health_check.py
@@ -1,15 +1,30 @@
-def health_check(application, health_url):
- async def health_check_wrapper(scope, receive, send):
- if scope.get("path") != health_url:
+from asgiref.typing import (
+ ASGI3Application,
+ ASGIReceiveCallable,
+ ASGISendCallable,
+ HTTPResponseBodyEvent,
+ HTTPResponseStartEvent,
+ Scope,
+)
+
+
+def health_check(application: ASGI3Application, health_url: str) -> ASGI3Application:
+ async def health_check_wrapper(
+ scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable
+ ) -> None:
+ if scope.get("type") == "http" and scope.get("path") != health_url:
await application(scope, receive, send)
return
await send(
- {
- "type": "http.response.start",
- "status": 200,
- "headers": [(b"content-type", b"text/plain")],
- }
+ HTTPResponseStartEvent(
+ type="http.response.start",
+ status=200,
+ headers=[(b"content-type", b"text/plain")],
+ trailers=False,
+ )
+ )
+ await send(
+ HTTPResponseBodyEvent(type="http.response.body", body=b"", more_body=False)
)
- await send({"type": "http.response.body"})
return health_check_wrapper
diff --git a/saleor/asgi/tests/__init__.py b/saleor/asgi/tests/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/asgi/tests/conftest.py b/saleor/asgi/tests/conftest.py
new file mode 100644
index 0000000000..e6ed224cf8
--- /dev/null
+++ b/saleor/asgi/tests/conftest.py
@@ -0,0 +1,28 @@
+import pytest
+from asgiref.typing import (
+ ASGI3Application,
+ ASGIReceiveCallable,
+ ASGISendCallable,
+ HTTPResponseBodyEvent,
+ HTTPResponseStartEvent,
+ Scope,
+)
+
+
+def asgi_app() -> ASGI3Application:
+ async def fake_app(
+ scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable
+ ) -> None:
+ await send(
+ HTTPResponseStartEvent(
+ type="http.response.start",
+ status=200,
+ headers=[(b"content-type", b"text/plain")],
+ )
+ )
+ await send(
+ HTTPResponseBodyEvent(type="http.response.body", body=b"", more_body=False)
+ )
+
+ return fake_app
diff --git a/saleor/asgi/tests/test_cors.py b/saleor/asgi/tests/test_cors.py
new file mode 100644
index 0000000000..bbe0244198
--- /dev/null
+++ b/saleor/asgi/tests/test_cors.py
@@ -0,0 +1,128 @@
+from typing import List
+
+import pytest
+from asgiref.typing import (
+ ASGI3Application,
+ ASGIReceiveEvent,
+ HTTPResponseBodyEvent,
+ HTTPResponseStartEvent,
+ HTTPScope,
+)
+
+from ..cors_handler import cors_handler
+
+ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"
+ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials"
+ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"
+ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods"
+
+
+def build_scope(origin: str) -> HTTPScope:
+ return {
+ "type": "http",
+ "asgi": {"spec_version": "2.1", "version": "3.0"},
+ "http_version": "2",
+ "method": "OPTIONS",
+ "scheme": "https",
+ "path": "/",
+ "raw_path": b"/",
+ "query_string": b"",
+ "root_path": "",
+ "headers": [
+ (b"hostname", b"localhost:3000"),
+ (b"origin", origin.encode("latin1")),
+ ],
+ "client": ("127.0.0.1", 80),
+ "server": None,
+ "extensions": {},
+ }
+
+
+async def run_app(app: ASGI3Application, scope: HTTPScope) -> List[dict]:
+ events = []
+
+ async def send(event) -> None:
+ events.append(event)
+
+ async def receive() -> ASGIReceiveEvent:
+ raise NotImplementedError()
+
+ await app(scope, receive, send)
+ return events
+
+
+async def test_access_control_header(asgi_app: ASGI3Application, settings):
+ settings.ALLOWED_GRAPHQL_ORIGINS = ["*"]
+ cors_app = cors_handler(asgi_app)
+ events = await run_app(cors_app, build_scope("http://localhost:3000"))
+ assert events == [
+ HTTPResponseStartEvent(
+ type="http.response.start",
+ status=200,
+ headers=[
+ (b"access-control-allow-credentials", b"true"),
+ (
+ b"access-control-allow-headers",
+ b"Origin, Content-Type, Accept, Authorization, "
+ b"Authorization-Bearer",
+ ),
+ (b"access-control-allow-methods", b"POST, OPTIONS"),
+ (b"access-control-allow-origin", b"http://localhost:3000"),
+ (b"access-control-max-age", b"600"),
+ (b"vary", b"Origin"),
+ ],
+ trailers=False,
+ ),
+ HTTPResponseBodyEvent(type="http.response.body", body=b"", more_body=False),
+ ]
+
+
+ "allowed_origins,origin",
+ [
+ (["*"], "http://example.org"),
+ (["*"], "https://example.org"),
+ (["*"], "http://localhost:3000"),
+ (["*"], "http://localhost:9000"),
+ (["*"], "file://"),
+ (["http://example.org"], "http://example.org"),
+ (["http://example.org", "https://example.org"], "http://example.org"),
+ (["http://example.org", "https://example.org"], "https://example.org"),
+ (["https://*.example.org"], "https://api.example.org"),
+ ],
+)
+async def test_access_control_allowed_origins(
+ asgi_app, settings, allowed_origins, origin
+):
+ settings.ALLOWED_GRAPHQL_ORIGINS = allowed_origins
+ cors_app = cors_handler(asgi_app)
+ events = await run_app(cors_app, build_scope(origin))
+ assert events[0]["type"] == "http.response.start"
+ assert events[0]["status"] == 200
+ assert (b"access-control-allow-origin", origin.encode("latin1")) in events[0][
+ "headers"
+ ]
+
+
+ "allowed_origins,origin",
+ [
+ (["http://example.org"], "https://example.org"),
+ (["http://example.org"], "http://localhost:3000"),
+ (["http://example.org"], "file://example.org"),
+ (["http://example.org"], "http://example.org:8000"),
+ (["http://example.org", "https://example.org"], "http://api.example.org"),
+ (["https://*.example.org"], "https://apiexample.com"),
+ ],
+)
+async def test_access_control_disallowed_origins(
+ asgi_app, settings, allowed_origins, origin
+):
+ settings.ALLOWED_GRAPHQL_ORIGINS = allowed_origins
+ cors_app = cors_handler(asgi_app)
+ events = await run_app(cors_app, build_scope(origin))
+ assert events[0]["type"] == "http.response.start"
+ assert events[0]["status"] == 400
+ assert (b"access-control-allow-origin", origin.encode("latin1")) not in events[0][
+ "headers"
+ ]
diff --git a/saleor/graphql/core/tests/test_view.py b/saleor/graphql/core/tests/test_view.py
index 285521ad44..52735f32f4 100644
--- a/saleor/graphql/core/tests/test_view.py
+++ b/saleor/graphql/core/tests/test_view.py
@@ -7,13 +7,7 @@ from graphql.execution.base import ExecutionResult
from .... import __version__ as saleor_version
from ....demo.views import EXAMPLE_QUERY
-from ...tests.fixtures import (
- ACCESS_CONTROL_ALLOW_CREDENTIALS,
- ACCESS_CONTROL_ALLOW_HEADERS,
- ACCESS_CONTROL_ALLOW_METHODS,
- ACCESS_CONTROL_ALLOW_ORIGIN,
- API_PATH,
-)
+from ...tests.fixtures import API_PATH
from ...tests.utils import get_graphql_content, get_graphql_content_from_response
from ...views import generate_cache_key
@@ -90,11 +84,6 @@ def test_graphql_view_get_enabled_or_disabled(client, settings, playground_on, s
assert response.status_code == status
-def test_graphql_view_options(client):
- response = client.options(API_PATH)
- assert response.status_code == 200
-
-
@pytest.mark.parametrize("method", ("put", "patch", "delete"))
def test_graphql_view_not_allowed(method, client):
func = getattr(client, method)
@@ -102,80 +91,6 @@ def test_graphql_view_not_allowed(method, client):
assert response.status_code == 405
-def test_graphql_view_access_control_header(client, settings):
- settings.ALLOWED_GRAPHQL_ORIGINS = ["*"]
- origin = "http://localhost:3000"
- response = client.options(API_PATH, HTTP_ORIGIN=origin)
- assert response[ACCESS_CONTROL_ALLOW_ORIGIN] == origin
- assert response[ACCESS_CONTROL_ALLOW_CREDENTIALS] == "true"
- assert response[ACCESS_CONTROL_ALLOW_METHODS] == "POST, OPTIONS"
- assert (
- response[ACCESS_CONTROL_ALLOW_HEADERS]
- == "Origin, Content-Type, Accept, Authorization, Authorization-Bearer"
- )
-
- response = client.options(API_PATH)
- assert all(
- [
- field not in response
- for field in (
- ACCESS_CONTROL_ALLOW_ORIGIN,
- ACCESS_CONTROL_ALLOW_CREDENTIALS,
- ACCESS_CONTROL_ALLOW_HEADERS,
- ACCESS_CONTROL_ALLOW_METHODS,
- )
- ]
- )
-
-
- "allowed_origins,allowed,not_allowed",
- [
- (
- ["*"],
- [
- "http://example.org",
- "https://example.org",
- "http://localhost:3000",
- "http://localhost:9000",
- "file://",
- ],
- [],
- ),
- (
- ["http://example.org"],
- ["http://example.org"],
- [
- "https://example.org",
- "http://localhost:3000",
- "http://localhost:9000",
- "file://",
- ],
- ),
- (
- ["http://example.org", "https://example.org"],
- ["http://example.org", "https://example.org"],
- ["http://localhost:3000", "http://localhost:9000", "file://"],
- ),
- (
- ["http://localhost:3000", "http://localhost:9000"],
- ["http://localhost:3000", "http://localhost:9000"],
- ["http://example.org", "https://example.org", "file://"],
- ),
- ],
-)
-def test_graphql_view_access_control_allowed_origins(
- client, settings, allowed_origins, allowed, not_allowed
-):
- settings.ALLOWED_GRAPHQL_ORIGINS = allowed_origins
- for origin in allowed:
- response = client.options(API_PATH, HTTP_ORIGIN=origin)
- assert response[ACCESS_CONTROL_ALLOW_ORIGIN] == origin
- for origin in not_allowed:
- response = client.options(API_PATH, HTTP_ORIGIN=origin)
- assert ACCESS_CONTROL_ALLOW_ORIGIN not in response
-
-
def test_invalid_request_body_non_debug(client):
data = "invalid-data"
response = client.post(API_PATH, data, content_type="application/json")
diff --git a/saleor/graphql/tests/fixtures.py b/saleor/graphql/tests/fixtures.py
index b71e8286ea..0d4c478ce4 100644
--- a/saleor/graphql/tests/fixtures.py
+++ b/saleor/graphql/tests/fixtures.py
@@ -18,10 +18,6 @@ from ..utils import handled_errors_logger, unhandled_errors_logger
from .utils import assert_no_permission
API_PATH = reverse("api")
-ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"
-ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials"
-ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"
-ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods"
class ApiClient(Client):
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index 4a312d5d93..d4537813a4 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -1,4 +1,3 @@
-import fnmatch
import hashlib
import importlib
import json
@@ -54,7 +53,6 @@ class GraphQLView(View):
# https://github.com/prisma/graphql-playground)
# - file upload (https://github.com/lmcgartland/graphene-file-upload)
# - query batching
- # - CORS
schema = None
executor = None
@@ -105,27 +103,13 @@ class GraphQLView(View):
if settings.PLAYGROUND_ENABLED:
return self.render_playground(request)
return HttpResponseNotAllowed(["OPTIONS", "POST"])
- if request.method == "OPTIONS":
- response = self.options(request, *args, **kwargs)
elif request.method == "POST":
- response = self.handle_query(request)
+ return self.handle_query(request)
else:
- return HttpResponseNotAllowed(["GET", "OPTIONS", "POST"])
- # Add access control headers
- if "HTTP_ORIGIN" in request.META:
- for origin in settings.ALLOWED_GRAPHQL_ORIGINS:
- if fnmatch.fnmatchcase(request.META["HTTP_ORIGIN"], origin):
- response["Access-Control-Allow-Origin"] = request.META[
- "HTTP_ORIGIN"
- ]
- response["Access-Control-Allow-Methods"] = "POST, OPTIONS"
- response["Access-Control-Allow-Headers"] = (
- "Origin, Content-Type, Accept, Authorization, "
- "Authorization-Bearer"
- )
- response["Access-Control-Allow-Credentials"] = "true"
- break
- return response
+ if settings.PLAYGROUND_ENABLED:
+ return HttpResponseNotAllowed(["GET", "OPTIONS", "POST"])
+ else:
+ return HttpResponseNotAllowed(["OPTIONS", "POST"])
def render_playground(self, request):
return render(
diff --git a/saleor/plugins/admin_email/plugin.py b/saleor/plugins/admin_email/plugin.py
index 089d04f9ab..f380896e21 100644
--- a/saleor/plugins/admin_email/plugin.py
+++ b/saleor/plugins/admin_email/plugin.py
@@ -169,7 +169,7 @@ class AdminEmailPlugin(BasePlugin):
configuration = {item["name"]: item["value"] for item in self.configuration}
self.config = EmailConfig(
host=configuration["host"] or settings.EMAIL_HOST,
- port=configuration["port"] or settings.EMAIL_PORT,
+ port=configuration["port"] or str(settings.EMAIL_PORT),
username=configuration["username"] or settings.EMAIL_HOST_USER,
password=configuration["password"] or settings.EMAIL_HOST_PASSWORD,
sender_name=configuration["sender_name"],
diff --git a/saleor/settings.py b/saleor/settings.py
index 659f4a939a..62e22910ce 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -129,14 +129,14 @@ email_config = dj_email_url.parse(
EMAIL_URL or "console://[email protected]:console@example/"
)
-EMAIL_FILE_PATH = email_config["EMAIL_FILE_PATH"]
-EMAIL_HOST_USER = email_config["EMAIL_HOST_USER"]
-EMAIL_HOST_PASSWORD = email_config["EMAIL_HOST_PASSWORD"]
-EMAIL_HOST = email_config["EMAIL_HOST"]
-EMAIL_PORT = email_config["EMAIL_PORT"]
-EMAIL_BACKEND = email_config["EMAIL_BACKEND"]
-EMAIL_USE_TLS = email_config["EMAIL_USE_TLS"]
-EMAIL_USE_SSL = email_config["EMAIL_USE_SSL"]
+EMAIL_FILE_PATH: str = email_config["EMAIL_FILE_PATH"]
+EMAIL_HOST_USER: str = email_config["EMAIL_HOST_USER"]
+EMAIL_HOST_PASSWORD: str = email_config["EMAIL_HOST_PASSWORD"]
+EMAIL_HOST: str = email_config["EMAIL_HOST"]
+EMAIL_PORT: int = email_config["EMAIL_PORT"]
+EMAIL_BACKEND: str = email_config["EMAIL_BACKEND"]
+EMAIL_USE_TLS: bool = email_config["EMAIL_USE_TLS"]
+EMAIL_USE_SSL: bool = email_config["EMAIL_USE_SSL"]
# If enabled, make sure you have set proper storefront address in ALLOWED_CLIENT_HOSTS.
ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL = get_bool_from_env(
@@ -148,13 +148,13 @@ ENABLE_SSL = get_bool_from_env("ENABLE_SSL", False)
if ENABLE_SSL:
SECURE_SSL_REDIRECT = not DEBUG
-DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL", EMAIL_HOST_USER)
+DEFAULT_FROM_EMAIL: str = os.environ.get("DEFAULT_FROM_EMAIL", EMAIL_HOST_USER)
-MEDIA_ROOT = os.path.join(PROJECT_ROOT, "media")
-MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
+MEDIA_ROOT: str = os.path.join(PROJECT_ROOT, "media")
+MEDIA_URL: str = os.environ.get("MEDIA_URL", "/media/")
-STATIC_ROOT = os.path.join(PROJECT_ROOT, "static")
-STATIC_URL = os.environ.get("STATIC_URL", "/static/")
+STATIC_ROOT: str = os.path.join(PROJECT_ROOT, "static")
+STATIC_URL: str = os.environ.get("STATIC_URL", "/static/")
STATICFILES_DIRS = [
("images", os.path.join(PROJECT_ROOT, "saleor", "static", "images"))
]
diff --git a/setup.cfg b/setup.cfg
index 8d2b933c50..3fc87422c0 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -17,7 +17,8 @@ exclude_lines =
@overload
[tool:pytest]
-addopts = -n auto --record-mode=none --ds=saleor.tests.settings --disable-socket
+addopts = -n auto --record-mode=none --ds=saleor.tests.settings --disable-socket --allow-unix-socket
+asyncio_mode = auto
testpaths = saleor
filterwarnings =
ignore::DeprecationWarning