تحويل لوحة الإدارة الداخلية من secret header إلى session auth حقيقي مع صلاحيات admin. إضافة دعم إدارة الأدوار من داخل لوحة الإدارة نفسها، مع حماية الحسابات المعتمدة عبر INTERNAL_ADMIN_EMAILS. تحسين بيانات المستخدم في الواجهة والباكند لتشمل role وis_allowlisted_admin. إضافة اختبار frontend مخصص لصفحة /internal/admin بدل الاعتماد فقط على build واختبار routes. تحسين إضافي في الأداء عبر إزالة الاعتماد على pdfjs-dist/pdf.worker في عدّ صفحات PDF واستبداله بمسار أخف باستخدام pdf-lib. تحسين تقسيم الـ chunks في build لتقليل أثر الحزم الكبيرة وفصل أجزاء مثل network, icons, pdf-core, وeditor. التحقق الذي تم: نجاح build للواجهة. نجاح اختبار صفحة الإدارة الداخلية في frontend. نجاح اختبارات auth/admin في backend. نجاح full backend suite مسبقًا مع EXIT:0. ولو تريد نسخة أقصر جدًا، استخدم هذه: آخر التحديثات: تم تحسين نظام الإدارة الداخلية ليعتمد على صلاحيات وجلسات حقيقية بدل secret header، مع إضافة إدارة أدوار من لوحة admin نفسها، وإضافة اختبارات frontend مخصصة للوحة، وتحسين أداء الواجهة عبر إزالة pdf.worker وتحسين تقسيم الـ chunks في build. جميع الاختبارات والتحققات الأساسية المطلوبة نجح
80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
"""Tests for session-backed authentication routes."""
|
|
|
|
|
|
class TestAuthRoutes:
|
|
def test_register_success(self, client):
|
|
response = client.post(
|
|
'/api/auth/register',
|
|
json={'email': 'user@example.com', 'password': 'secretpass123'},
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
data = response.get_json()
|
|
assert data['user']['email'] == 'user@example.com'
|
|
assert data['user']['plan'] == 'free'
|
|
assert data['user']['role'] == 'user'
|
|
|
|
def test_register_assigns_admin_role_for_allowlisted_email(self, app, client):
|
|
app.config['INTERNAL_ADMIN_EMAILS'] = ('admin@example.com',)
|
|
|
|
response = client.post(
|
|
'/api/auth/register',
|
|
json={'email': 'admin@example.com', 'password': 'secretpass123'},
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
assert response.get_json()['user']['role'] == 'admin'
|
|
|
|
def test_register_duplicate_email(self, client):
|
|
client.post(
|
|
'/api/auth/register',
|
|
json={'email': 'user@example.com', 'password': 'secretpass123'},
|
|
)
|
|
response = client.post(
|
|
'/api/auth/register',
|
|
json={'email': 'user@example.com', 'password': 'secretpass123'},
|
|
)
|
|
|
|
assert response.status_code == 409
|
|
assert 'already exists' in response.get_json()['error'].lower()
|
|
|
|
def test_login_and_me(self, client):
|
|
client.post(
|
|
'/api/auth/register',
|
|
json={'email': 'user@example.com', 'password': 'secretpass123'},
|
|
)
|
|
client.post('/api/auth/logout')
|
|
|
|
login_response = client.post(
|
|
'/api/auth/login',
|
|
json={'email': 'user@example.com', 'password': 'secretpass123'},
|
|
)
|
|
me_response = client.get('/api/auth/me')
|
|
|
|
assert login_response.status_code == 200
|
|
assert me_response.status_code == 200
|
|
me_data = me_response.get_json()
|
|
assert me_data['authenticated'] is True
|
|
assert me_data['user']['email'] == 'user@example.com'
|
|
|
|
def test_login_invalid_password(self, client):
|
|
client.post(
|
|
'/api/auth/register',
|
|
json={'email': 'user@example.com', 'password': 'secretpass123'},
|
|
)
|
|
client.post('/api/auth/logout')
|
|
|
|
response = client.post(
|
|
'/api/auth/login',
|
|
json={'email': 'user@example.com', 'password': 'wrongpass123'},
|
|
)
|
|
|
|
assert response.status_code == 401
|
|
assert 'invalid email or password' in response.get_json()['error'].lower()
|
|
|
|
def test_me_without_session(self, client):
|
|
response = client.get('/api/auth/me')
|
|
|
|
assert response.status_code == 200
|
|
assert response.get_json() == {'authenticated': False, 'user': None}
|