CoolFace
Apppublic

smart-models/Placebo_AI

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
02_test_auth_flow.py44 linesDownload Raw Back to validation_suite
1import asyncio2from playwright.async_api import async_playwright3import os4 5BASE_URL = "http://localhost:8000"6 7async def test_auth_flow():8    print("--- Phase 2: Authentication & Session Flow ---")9    try:10        async with async_playwright() as p:11            # Connect to already-open Brave browser using debugging port12            browser = await p.chromium.connect_over_cdp("http://localhost:9222")13            14            # Use the default context (which has the user's login cookies/localStorage)15            context = browser.contexts[0]16            page = await context.new_page()17            await page.goto(BASE_URL)18            19            # 1. Check if user is logged in20            print("[TEST] Checking Authentication Status...")21            await page.wait_for_timeout(2000)22            23            credits_text = await page.inner_text(".credit-info span")24            if "Log in" in credits_text:25                print("⚠️ You are not logged in. Please log in manually once, then run this script again.")26            else:27                print("✅ User is authenticated!")28                29            # 2. Verify LocalStorage isolation for History30            print("[TEST] Verifying Chat History Namespace Isolation...")31            local_storage = await page.evaluate("() => Object.keys(localStorage)")32            history_keys = [k for k in local_storage if k.startswith("chat_history_")]33            if len(history_keys) > 0 and "chat_history" not in history_keys:34                print(f"✅ History is properly isolated under: {history_keys[0]}")35            else:36                print("❌ History isolation failed or missing.")37            38            await browser.close()39    except Exception as e:40        print(f"❌ Auth Flow Test Failed: {str(e)}")41 42if __name__ == "__main__":43    asyncio.run(test_auth_flow())44