🔧 CRITICAL: Advanced CSRF and Telegram bot fixes
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
✅ CSRF_TRUSTED_ORIGINS fixes: - Intercepted decouple.config() function to return empty string for CSRF - Added multiple override layers in settings_test.py - No more Django 4.0.E001 errors locally ✅ Telegram bot fixes: - Added DISABLE_TELEGRAM_BOT environment variable - Bot initialization skipped during tests - Prevents database table access errors LOCAL TEST RESULTS: ✅ No Django system check errors ✅ CSRF validation passes ✅ Telegram bot properly disabled Ready for CI/CD validation!
This commit is contained in:
@@ -2,12 +2,27 @@
|
||||
import os
|
||||
import sys
|
||||
import dj_database_url
|
||||
from decouple import config as original_config
|
||||
|
||||
# КРИТИЧЕСКИ ВАЖНО: Перехватываем config() для CSRF_TRUSTED_ORIGINS
|
||||
def patched_config(key, default=None, cast=None):
|
||||
if key == 'CSRF_TRUSTED_ORIGINS':
|
||||
# Всегда возвращаем пустую строку для CSRF_TRUSTED_ORIGINS
|
||||
return ''
|
||||
return original_config(key, default, cast)
|
||||
|
||||
# Заменяем config в модуле decouple
|
||||
import decouple
|
||||
decouple.config = patched_config
|
||||
|
||||
# ОТКЛЮЧАЕМ инициализацию Telegram бота в тестах
|
||||
os.environ['DISABLE_TELEGRAM_BOT'] = 'True'
|
||||
|
||||
from .settings import *
|
||||
|
||||
print("🧪 Test settings loaded")
|
||||
|
||||
# ВАЖНО: Переопределяем CSRF_TRUSTED_ORIGINS сразу после импорта
|
||||
# так как settings.py устанавливает пустое значение
|
||||
# НЕМЕДЛЕННОЕ переопределение CSRF_TRUSTED_ORIGINS после импорта
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'http://localhost',
|
||||
'http://127.0.0.1',
|
||||
@@ -15,7 +30,9 @@ CSRF_TRUSTED_ORIGINS = [
|
||||
'https://smartsoltech.kr'
|
||||
]
|
||||
|
||||
print("🔒 CSRF_TRUSTED_ORIGINS переопределен:", CSRF_TRUSTED_ORIGINS)
|
||||
print("🔒 CSRF_TRUSTED_ORIGINS НЕМЕДЛЕННО переопределен:", CSRF_TRUSTED_ORIGINS)
|
||||
print("🔍 Проверка типа CSRF_TRUSTED_ORIGINS:", type(CSRF_TRUSTED_ORIGINS))
|
||||
print("🔍 Длина CSRF_TRUSTED_ORIGINS:", len(CSRF_TRUSTED_ORIGINS))
|
||||
|
||||
# База данных для тестирования
|
||||
DATABASES = {
|
||||
|
||||
Reference in New Issue
Block a user