2026-08-08 11:57:08 +07:00
|
|
|
"""
|
|
|
|
|
Kontrak route autentikasi. Token asli siswa tetap dipakai untuk login;
|
|
|
|
|
response dan log tidak boleh mengekspos credential.
|
feat(teacher): manajemen akun guru canonical + first-run otomatis; cabut backend CSV (PG only)
- feat: ./elemes.sh teacher — upsert satu akun guru canonical (prompt nama default TEACHER_NAME, token tersembunyi via stdin, rotasi token saat guru sudah ada, idempotent); TEACHER_NAME/TEACHER_TOKEN di .env
- feat: first-run otomatis — db_init jalankan alembic upgrade head + bootstrap guru bila TEACHER_TOKEN terisi (run/runbuild/runclearbuild)
- refactor: backend CSV dicabut penuh — hapus mount tokens_siswa.csv, TOKENS_FILE, STORAGE_BACKEND=csv, csv_backend.py, csv_importer.py, generate_tokens.py, script migrate/verify/export CSV, command generatetoken/dbimport/dbverify/dbexport/synclessons; storage fail-loud postgresql-only
- fix: dbrestore gagal diam-diam saat restore ke DB berisi data (dump tanpa --clean) — dbbackup kini --clean --if-exists + dbrestore reset schema public; roundtrip terverifikasi
- test: suite kontrak PG-native + route auth/progress integrasi PG; 183 passed container, 96 passed host, frontend 91 passed
- docs: README, documentation.md, docs/01/02/11, load-test/README disinkronkan ke realita PostgreSQL-only; proposal.md dipertahankan (historis)
- chore: load-test token sintetis di-seed ke PG (content_parser), config.py bersih TOKENS_FILE, .dockerignore/.gitignore dibersihkan
2026-08-09 11:21:08 +07:00
|
|
|
|
|
|
|
|
Integrasi PostgreSQL (butuh DATABASE_URL) — backend CSV sudah dicabut.
|
2026-08-08 11:57:08 +07:00
|
|
|
"""
|
|
|
|
|
|
feat(teacher): manajemen akun guru canonical + first-run otomatis; cabut backend CSV (PG only)
- feat: ./elemes.sh teacher — upsert satu akun guru canonical (prompt nama default TEACHER_NAME, token tersembunyi via stdin, rotasi token saat guru sudah ada, idempotent); TEACHER_NAME/TEACHER_TOKEN di .env
- feat: first-run otomatis — db_init jalankan alembic upgrade head + bootstrap guru bila TEACHER_TOKEN terisi (run/runbuild/runclearbuild)
- refactor: backend CSV dicabut penuh — hapus mount tokens_siswa.csv, TOKENS_FILE, STORAGE_BACKEND=csv, csv_backend.py, csv_importer.py, generate_tokens.py, script migrate/verify/export CSV, command generatetoken/dbimport/dbverify/dbexport/synclessons; storage fail-loud postgresql-only
- fix: dbrestore gagal diam-diam saat restore ke DB berisi data (dump tanpa --clean) — dbbackup kini --clean --if-exists + dbrestore reset schema public; roundtrip terverifikasi
- test: suite kontrak PG-native + route auth/progress integrasi PG; 183 passed container, 96 passed host, frontend 91 passed
- docs: README, documentation.md, docs/01/02/11, load-test/README disinkronkan ke realita PostgreSQL-only; proposal.md dipertahankan (historis)
- chore: load-test token sintetis di-seed ke PG (content_parser), config.py bersih TOKENS_FILE, .dockerignore/.gitignore dibersihkan
2026-08-09 11:21:08 +07:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2026-08-08 11:57:08 +07:00
|
|
|
from services.tests.conftest import STUDENT_TOKEN, TEACHER_TOKEN
|
|
|
|
|
|
feat(teacher): manajemen akun guru canonical + first-run otomatis; cabut backend CSV (PG only)
- feat: ./elemes.sh teacher — upsert satu akun guru canonical (prompt nama default TEACHER_NAME, token tersembunyi via stdin, rotasi token saat guru sudah ada, idempotent); TEACHER_NAME/TEACHER_TOKEN di .env
- feat: first-run otomatis — db_init jalankan alembic upgrade head + bootstrap guru bila TEACHER_TOKEN terisi (run/runbuild/runclearbuild)
- refactor: backend CSV dicabut penuh — hapus mount tokens_siswa.csv, TOKENS_FILE, STORAGE_BACKEND=csv, csv_backend.py, csv_importer.py, generate_tokens.py, script migrate/verify/export CSV, command generatetoken/dbimport/dbverify/dbexport/synclessons; storage fail-loud postgresql-only
- fix: dbrestore gagal diam-diam saat restore ke DB berisi data (dump tanpa --clean) — dbbackup kini --clean --if-exists + dbrestore reset schema public; roundtrip terverifikasi
- test: suite kontrak PG-native + route auth/progress integrasi PG; 183 passed container, 96 passed host, frontend 91 passed
- docs: README, documentation.md, docs/01/02/11, load-test/README disinkronkan ke realita PostgreSQL-only; proposal.md dipertahankan (historis)
- chore: load-test token sintetis di-seed ke PG (content_parser), config.py bersih TOKENS_FILE, .dockerignore/.gitignore dibersihkan
2026-08-09 11:21:08 +07:00
|
|
|
pytestmark = pytest.mark.skipif(
|
|
|
|
|
not os.environ.get("DATABASE_URL"), reason="butuh PostgreSQL nyata"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _seed(seed_demo_users):
|
|
|
|
|
yield
|
|
|
|
|
|
2026-08-08 11:57:08 +07:00
|
|
|
|
|
|
|
|
def test_login_success_sets_httponly_cookie(client):
|
|
|
|
|
resp = client.post("/login", json={"token": STUDENT_TOKEN})
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
body = resp.get_json()
|
|
|
|
|
assert body["success"] is True
|
|
|
|
|
assert body["student_name"] == "Budi Santoso"
|
|
|
|
|
assert body["is_teacher"] is False
|
|
|
|
|
set_cookie = resp.headers.get("Set-Cookie", "")
|
|
|
|
|
assert "student_token=" in set_cookie
|
|
|
|
|
assert "HttpOnly" in set_cookie
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_login_teacher(client):
|
|
|
|
|
resp = client.post("/login", json={"token": TEACHER_TOKEN})
|
|
|
|
|
assert resp.get_json()["is_teacher"] is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_login_invalid_token(client):
|
|
|
|
|
resp = client.post("/login", json={"token": "TOKEN_SALAH"})
|
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
assert resp.get_json()["success"] is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_validate_token_route(client):
|
|
|
|
|
resp = client.post("/validate-token", json={"token": TEACHER_TOKEN})
|
|
|
|
|
body = resp.get_json()
|
|
|
|
|
assert body["success"] is True
|
|
|
|
|
assert body["is_teacher"] is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_validate_token_from_cookie(client):
|
|
|
|
|
client.set_cookie("student_token", STUDENT_TOKEN)
|
|
|
|
|
resp = client.post("/validate-token", json={})
|
|
|
|
|
assert resp.get_json()["success"] is True
|
|
|
|
|
assert resp.get_json()["student_name"] == "Budi Santoso"
|