-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tls_cert_support.py
More file actions
executable file
·70 lines (49 loc) · 2.51 KB
/
test_tls_cert_support.py
File metadata and controls
executable file
·70 lines (49 loc) · 2.51 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
"""Test TLS certificate bundle support in githubapi module."""
import pytest
from unittest.mock import patch, MagicMock
import os
def test_github_verify_default():
"""Test that GitHub class defaults to verify=True."""
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
with patch("githubapi.requests.Session") as mock_session_class:
mock_session = MagicMock()
mock_session_class.return_value = mock_session
from githubapi import GitHub
_gh = GitHub()
# Verify that session.verify is set to True by default
assert mock_session.verify == True
def test_github_verify_false():
"""Test that GitHub class accepts verify=False."""
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
with patch("githubapi.requests.Session") as mock_session_class:
mock_session = MagicMock()
mock_session_class.return_value = mock_session
from githubapi import GitHub
_gh = GitHub(verify=False)
# Verify that session.verify is set to False
assert mock_session.verify == False
def test_github_verify_cert_bundle():
"""Test that GitHub class accepts verify with certificate bundle path."""
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
with patch("githubapi.requests.Session") as mock_session_class:
mock_session = MagicMock()
mock_session_class.return_value = mock_session
from githubapi import GitHub
cert_path = "/path/to/cert.pem"
_gh = GitHub(verify=cert_path)
# Verify that session.verify is set to the certificate path
assert mock_session.verify == cert_path
def test_github_token_required():
"""Test that GitHub class requires a token."""
with patch.dict(os.environ, {}, clear=True):
with pytest.raises(ValueError, match="GITHUB_TOKEN environment variable must be set"):
from githubapi import GitHub
_gh = GitHub()
def test_github_hostname_validation():
"""Test that GitHub class validates hostname."""
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
with pytest.raises(ValueError, match="Invalid server hostname"):
from githubapi import GitHub
_gh = GitHub(hostname="invalid hostname with spaces")
if __name__ == "__main__":
pytest.main([__file__, "-v"])