1+ """
2+ Test configuration for auth module tests.
3+ """
4+
5+ import pytest
6+ import sys
7+ import os
8+ from unittest .mock import MagicMock , patch
9+ import base64
10+ import json
11+
12+ # Add the backend directory to the Python path for imports
13+ sys .path .insert (0 , os .path .join (os .path .dirname (__file__ ), '..' , '..' , '..' , 'backend' ))
14+
15+ @pytest .fixture
16+ def mock_sample_headers ():
17+ """Mock headers with EasyAuth authentication data."""
18+ return {
19+ "x-ms-client-principal-id" : "12345678-1234-1234-1234-123456789012" ,
20+ "x-ms-client-principal-name" : "testuser@example.com" ,
21+ "x-ms-client-principal-idp" : "aad" ,
22+ "x-ms-token-aad-id-token" : "sample.jwt.token" ,
23+ "x-ms-client-principal" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsInRpZCI6IjEyMzQ1Njc4LTEyMzQtMTIzNC0xMjM0LTEyMzQ1Njc4OTAxMiJ9"
24+ }
25+
26+ @pytest .fixture
27+ def mock_empty_headers ():
28+ """Mock headers without authentication data."""
29+ return {
30+ "content-type" : "application/json" ,
31+ "user-agent" : "test-agent"
32+ }
33+
34+ @pytest .fixture
35+ def mock_valid_base64_principal ():
36+ """Mock valid base64 encoded principal with tenant ID."""
37+ mock_data = {
38+ "typ" : "JWT" ,
39+ "alg" : "RS256" ,
40+ "tid" : "87654321-4321-4321-4321-210987654321" ,
41+ "oid" : "12345678-1234-1234-1234-123456789012" ,
42+ "preferred_username" : "testuser@example.com" ,
43+ "name" : "Test User"
44+ }
45+
46+ json_str = json .dumps (mock_data )
47+ return base64 .b64encode (json_str .encode ('utf-8' )).decode ('utf-8' )
48+
49+ @pytest .fixture
50+ def mock_invalid_base64_principal ():
51+ """Mock invalid base64 encoded principal."""
52+ return "invalid_base64_string!"
53+
54+ @pytest .fixture
55+ def sample_user_mock ():
56+ """Mock sample_user data for testing."""
57+ return {
58+ "x-ms-client-principal-id" : "00000000-0000-0000-0000-000000000000" ,
59+ "x-ms-client-principal-name" : "testusername@contoso.com" ,
60+ "x-ms-client-principal-idp" : "aad" ,
61+ "x-ms-token-aad-id-token" : "your_aad_id_token" ,
62+ "x-ms-client-principal" : "your_base_64_encoded_token"
63+ }
0 commit comments