Skip to content
This repository was archived by the owner on Nov 11, 2022. It is now read-only.

Commit 22ac185

Browse files
Fixing some CRSF stuff
1 parent 48f1a14 commit 22ac185

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

core/settings.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import os
33
from pathlib import Path
4-
import rest_framework
54

65
CONFIGURATION = json.load(open((Path(__file__).parent / '../config.json').resolve()))
76

@@ -13,7 +12,21 @@
1312
# SECURITY WARNING: don't run with debug turned on in production!
1413
DEBUG = CONFIGURATION['DEBUG'] # int(os.environ.get('DEBUG', default=False))
1514

16-
ALLOWED_HOSTS = ['*']
15+
CORS_ALLOW_ALL_ORIGINS = True # If this is used then `CORS_ALLOWED_ORIGINS` will not have any effect
16+
CORS_ALLOW_CREDENTIALS = True
17+
18+
CSRF_TRUSTED_ORIGINS = [
19+
'https://*.yandex-academy.ru',
20+
'http://localhost',
21+
'http://localhost:8000',
22+
'http://localhost:80',
23+
'http://0.0.0.0',
24+
'http://0.0.0.0:80',
25+
'http://0.0.0.0:8000',
26+
'http://127.0.0.1:8000',
27+
'http://127.0.0.1',
28+
'http://127.0.0.1:80'
29+
]
1730

1831
# Application definition
1932

@@ -25,7 +38,8 @@
2538
'django.contrib.messages',
2639
'django.contrib.staticfiles',
2740
'rest_framework',
28-
'shop'
41+
'shop',
42+
'corsheaders'
2943
]
3044

3145
MIDDLEWARE = [
@@ -36,6 +50,8 @@
3650
'django.contrib.auth.middleware.AuthenticationMiddleware',
3751
'django.contrib.messages.middleware.MessageMiddleware',
3852
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
'corsheaders.middleware.CorsMiddleware',
54+
'django.middleware.common.CommonMiddleware'
3955
]
4056

4157
ROOT_URLCONF = 'core.urls'

unit_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import urllib.parse
77
import urllib.request
88

9-
API_BASEURL = 'http://localhost:80'
9+
API_BASEURL = 'https://responses-1920.usr.yandex-academy.ru'
1010

1111

1212
ROOT_ID = "069cb8d7-bbdd-47d3-ad8f-82ef4c269df1"
@@ -239,8 +239,8 @@ def test_nodes():
239239

240240
def test_sales():
241241
status, response = request(f'/sales?date=2022-02-04T00:00:00.000Z')
242-
print(response)
243-
print(status)
242+
#print(response)
243+
#print(status)
244244
assert status == 200, f"Expected HTTP status code 200, got {status}"
245245
print("Test sales passed.")
246246

@@ -270,7 +270,7 @@ def test_delete():
270270
def test_all():
271271
test_import()
272272
test_nodes()
273-
#test_sales() # I have sales, but sometimes DEPLOYED app responses with 500
273+
test_sales() # I have sales, but sometimes DEPLOYED app responses with 500
274274
#test_stats()
275275
test_delete()
276276

0 commit comments

Comments
 (0)