teams test auth bot

This commit is contained in:
patrick-motsch 2026-02-16 21:37:37 +01:00
parent 3f9d791688
commit b08355ee45

View file

@ -700,6 +700,73 @@ async def testVoice(
raise HTTPException(status_code=500, detail=f"TTS-Test fehlgeschlagen: {str(e)}")
# =========================================================================
# Auth Detection Test Endpoint
# =========================================================================
@router.post("/{instanceId}/test-auth")
@limiter.limit("3/minute")
async def testAuth(
request: Request,
instanceId: str,
context: RequestContext = Depends(getRequestContext),
):
"""
Run auth detection tests against a Teams meeting URL.
Tests 5 browser configuration variants to determine which ones
receive the /v2/ (authenticated) vs light-meetings (anonymous) page.
Does NOT join the meeting only checks which page Teams serves.
"""
import aiohttp
mandateId = _validateInstanceAccess(instanceId, context)
interface = _getInterface(context, instanceId)
effectiveConfig = _getInstanceConfig(instanceId)
body = await request.json()
meetingUrl = body.get("meetingUrl")
if not meetingUrl:
raise HTTPException(status_code=400, detail="meetingUrl is required")
# Load system bot credentials for the auth test variant
email = None
password = None
systemBot = interface.getActiveSystemBot(mandateId)
if systemBot:
email = systemBot.get("email")
encryptedPwd = systemBot.get("encryptedPassword")
if encryptedPwd:
from modules.shared.configuration import decryptValue
password = decryptValue(encryptedPwd, userId=str(context.user.id), keyName="systemBotPassword")
# Forward to browser bot service
browserBotUrl = effectiveConfig._getEffectiveBrowserBotUrl()
if not browserBotUrl:
raise HTTPException(status_code=503, detail="Browser Bot URL not configured")
browserBotUrl = browserBotUrl.rstrip("/")
payload = {
"meetingUrl": meetingUrl,
"botAccountEmail": email,
"botAccountPassword": password,
}
try:
# Generous timeout: 5 variants × ~45s each = ~225s max
timeout = aiohttp.ClientTimeout(total=300)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.post(f"{browserBotUrl}/api/bot/test-auth", json=payload) as resp:
if resp.status == 200:
return await resp.json()
else:
errorText = await resp.text()
logger.error(f"Auth test failed: {resp.status} - {errorText}")
raise HTTPException(status_code=resp.status, detail=f"Browser Bot error: {errorText}")
except aiohttp.ClientError as e:
logger.error(f"Auth test connection error: {e}")
raise HTTPException(status_code=503, detail=f"Browser Bot connection failed: {str(e)}")
# =========================================================================
# Browser Bot Communication Endpoints (HTTP Fallback + WebSocket)
# =========================================================================