-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathtest_claude_config.py
More file actions
54 lines (36 loc) · 1.85 KB
/
test_claude_config.py
File metadata and controls
54 lines (36 loc) · 1.85 KB
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
"""Tests for Claude Code config file reader."""
import json
from pathlib import Path
from pyfakefs.fake_filesystem import FakeFilesystem
from cycode.cli.apps.ai_guardrails.scan.claude_config import get_user_email, load_claude_config
def test_load_claude_config_valid(fs: FakeFilesystem) -> None:
"""Test loading a valid ~/.claude.json file."""
config = {'oauthAccount': {'emailAddress': 'user@example.com'}}
config_path = Path.home() / '.claude.json'
fs.create_file(config_path, contents=json.dumps(config))
result = load_claude_config(config_path)
assert result == config
def test_load_claude_config_missing_file(fs: FakeFilesystem) -> None:
"""Test loading when ~/.claude.json does not exist."""
fs.create_dir(Path.home())
config_path = Path.home() / '.claude.json'
result = load_claude_config(config_path)
assert result is None
def test_load_claude_config_corrupt_file(fs: FakeFilesystem) -> None:
"""Test loading when ~/.claude.json contains invalid JSON."""
config_path = Path.home() / '.claude.json'
fs.create_file(config_path, contents='not valid json {{{')
result = load_claude_config(config_path)
assert result is None
def test_get_user_email_present() -> None:
"""Test extracting email when oauthAccount.emailAddress exists."""
config = {'oauthAccount': {'emailAddress': 'user@example.com'}}
assert get_user_email(config) == 'user@example.com'
def test_get_user_email_missing_oauth_account() -> None:
"""Test extracting email when oauthAccount key is missing."""
config = {'someOtherKey': 'value'}
assert get_user_email(config) is None
def test_get_user_email_missing_email_address() -> None:
"""Test extracting email when oauthAccount exists but emailAddress is missing."""
config = {'oauthAccount': {'someOtherField': 'value'}}
assert get_user_email(config) is None