forked from SocketDev/socket-python-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
80 lines (64 loc) · 2.56 KB
/
test_config.py
File metadata and controls
80 lines (64 loc) · 2.56 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
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
import pytest
from socketsecurity.core.socket_config import SocketConfig
def test_config_default_values():
"""Test that config initializes with correct default values"""
config = SocketConfig(api_key="test_key")
assert config.api_key == "test_key"
assert config.api_url == "https://api.socket.dev/v0"
assert config.timeout == 30
assert config.allow_unverified_ssl is False
assert config.org_id is None
assert config.org_slug is None
assert config.full_scan_path is None
assert config.repository_path is None
assert config.security_policy == {}
def test_config_custom_values():
"""Test that config accepts custom values"""
config = SocketConfig(
api_key="test_key",
api_url="https://custom.api.dev/v1",
timeout=60,
allow_unverified_ssl=True
)
assert config.api_key == "test_key"
assert config.api_url == "https://custom.api.dev/v1"
assert config.timeout == 60
assert config.allow_unverified_ssl is True
def test_config_api_key_required():
"""Test that api_key is required"""
with pytest.raises(ValueError):
SocketConfig(api_key=None)
with pytest.raises(ValueError):
SocketConfig(api_key="")
def test_config_invalid_timeout():
"""Test that timeout must be positive"""
with pytest.raises(ValueError):
SocketConfig(api_key="test_key", timeout=0)
with pytest.raises(ValueError):
SocketConfig(api_key="test_key", timeout=-1)
def test_config_invalid_api_url():
"""Test that api_url must be valid HTTPS URL"""
with pytest.raises(ValueError):
SocketConfig(api_key="test_key", api_url="not_a_url")
with pytest.raises(ValueError):
SocketConfig(api_key="test_key", api_url="http://insecure.com") # Must be HTTPS
def test_config_update_org_details():
"""Test updating org details"""
config = SocketConfig(api_key="test_key")
config.org_id = "test_org_id"
config.org_slug = "test-org"
config.full_scan_path = "orgs/test-org/full-scans"
config.repository_path = "orgs/test-org/repos"
assert config.org_id == "test_org_id"
assert config.org_slug == "test-org"
assert config.full_scan_path == "orgs/test-org/full-scans"
assert config.repository_path == "orgs/test-org/repos"
def test_config_update_security_policy():
"""Test updating security policy"""
config = SocketConfig(api_key="test_key")
test_policy = {
"rule1": {"action": "block"},
"rule2": {"action": "warn"}
}
config.security_policy = test_policy
assert config.security_policy == test_policy