File size: 2,974 Bytes
d122202
 
 
 
 
93db655
d122202
93db655
 
 
 
d122202
93db655
d122202
38f91de
d122202
 
 
 
 
38f91de
d122202
 
 
 
 
 
 
38f91de
d122202
 
 
 
 
38f91de
d122202
 
 
 
 
38f91de
d122202
 
 
 
 
38f91de
d122202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38f91de
d122202
 
38f91de
d122202
 
 
 
 
 
38f91de
d122202
 
38f91de
d122202
 
 
 
 
 
 
 
 
38f91de
d122202
 
 
 
 
 
38f91de
 
d122202
 
38f91de
d122202
 
 
 
 
 
38f91de
d122202
38f91de
d122202
 
 
 
38f91de
d122202
 
 
38f91de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
tests/conftest.py - Pytest configuration and shared fixtures
"""

import json
import os
from pathlib import Path
from typing import Any, Dict

import pytest

from llmguardian.core.config import Config
from llmguardian.core.logger import SecurityLogger


@pytest.fixture(scope="session")
def test_data_dir() -> Path:
    """Get test data directory"""
    return Path(__file__).parent / "data"


@pytest.fixture(scope="session")
def test_config() -> Dict[str, Any]:
    """Load test configuration"""
    config_path = Path(__file__).parent / "config" / "test_config.json"
    with open(config_path) as f:
        return json.load(f)


@pytest.fixture
def security_logger():
    """Create a security logger for testing"""
    return SecurityLogger(log_path=str(Path(__file__).parent / "logs"))


@pytest.fixture
def config(test_config):
    """Create a configuration instance for testing"""
    return Config(config_data=test_config)


@pytest.fixture
def temp_dir(tmpdir):
    """Create a temporary directory for test files"""
    return Path(tmpdir)


@pytest.fixture
def sample_text_data():
    """Sample text data for testing"""
    return {
        "clean": "This is a clean text without sensitive information.",
        "with_pii": "Contact john.doe@example.com or call 123-456-7890",
        "with_phi": "Patient medical record #12345: Diagnosis notes",
        "with_financial": "Credit card: 4111-1111-1111-1111",
        "with_credentials": "API key: xyz123abc",
        "with_location": "IP: 192.168.1.1, GPS: 37.7749, -122.4194",
        "mixed": """
            Name: John Doe
            Email: john.doe@example.com
            SSN: 123-45-6789
            Credit Card: 4111-1111-1111-1111
            Medical ID: PHI123456
            Password: secret123
        """,
    }


@pytest.fixture
def sample_vectors():
    """Sample vector data for testing"""
    return {
        "clean": [0.1, 0.2, 0.3],
        "suspicious": [0.9, 0.8, 0.7],
        "anomalous": [10.0, -10.0, 5.0],
    }


@pytest.fixture
def test_rules():
    """Test privacy rules"""
    return {
        "test_rule_1": {
            "name": "Test Rule 1",
            "category": "PII",
            "level": "CONFIDENTIAL",
            "patterns": [r"\b\w+@\w+\.\w+\b"],
            "actions": ["mask"],
        },
        "test_rule_2": {
            "name": "Test Rule 2",
            "category": "PHI",
            "level": "RESTRICTED",
            "patterns": [r"medical.*\d+"],
            "actions": ["block", "alert"],
        },
    }


@pytest.fixture(autouse=True)
def setup_teardown():
    """Setup and teardown for each test"""
    # Setup
    test_log_dir = Path(__file__).parent / "logs"
    test_log_dir.mkdir(exist_ok=True)

    yield

    # Teardown
    for f in test_log_dir.glob("*.log"):
        f.unlink()


@pytest.fixture
def mock_security_logger(mocker):
    """Create a mocked security logger"""
    return mocker.patch("llmguardian.core.logger.SecurityLogger")