Skip to content

Commit 120b4b4

Browse files
Copilotaegilops
andcommitted
Add comprehensive tests for TLS certificate support
- Test default verify=True behavior - Test verify=False behavior for insecure connections - Test custom certificate bundle path - Test token requirement validation - Test hostname validation Co-authored-by: aegilops <41705651+aegilops@users.noreply.github.com>
1 parent 3e14459 commit 120b4b4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test_tls_cert_support.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""Test TLS certificate bundle support in githubapi module."""
2+
3+
import pytest
4+
from unittest.mock import patch, MagicMock
5+
import os
6+
7+
8+
def test_github_verify_default():
9+
"""Test that GitHub class defaults to verify=True."""
10+
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
11+
with patch("githubapi.requests.Session") as mock_session_class:
12+
mock_session = MagicMock()
13+
mock_session_class.return_value = mock_session
14+
15+
from githubapi import GitHub
16+
17+
gh = GitHub()
18+
19+
# Verify that session.verify is set to True by default
20+
assert mock_session.verify == True
21+
22+
23+
def test_github_verify_false():
24+
"""Test that GitHub class accepts verify=False."""
25+
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
26+
with patch("githubapi.requests.Session") as mock_session_class:
27+
mock_session = MagicMock()
28+
mock_session_class.return_value = mock_session
29+
30+
from githubapi import GitHub
31+
32+
gh = GitHub(verify=False)
33+
34+
# Verify that session.verify is set to False
35+
assert mock_session.verify == False
36+
37+
38+
def test_github_verify_cert_bundle():
39+
"""Test that GitHub class accepts verify with certificate bundle path."""
40+
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
41+
with patch("githubapi.requests.Session") as mock_session_class:
42+
mock_session = MagicMock()
43+
mock_session_class.return_value = mock_session
44+
45+
from githubapi import GitHub
46+
47+
cert_path = "/path/to/cert.pem"
48+
gh = GitHub(verify=cert_path)
49+
50+
# Verify that session.verify is set to the certificate path
51+
assert mock_session.verify == cert_path
52+
53+
54+
def test_github_token_required():
55+
"""Test that GitHub class requires a token."""
56+
with patch.dict(os.environ, {}, clear=True):
57+
with pytest.raises(ValueError, match="GITHUB_TOKEN environment variable must be set"):
58+
from githubapi import GitHub
59+
gh = GitHub()
60+
61+
62+
def test_github_hostname_validation():
63+
"""Test that GitHub class validates hostname."""
64+
with patch.dict(os.environ, {"GITHUB_TOKEN": "test_token"}):
65+
with pytest.raises(ValueError, match="Invalid server hostname"):
66+
from githubapi import GitHub
67+
gh = GitHub(hostname="invalid hostname with spaces")
68+
69+
70+
if __name__ == "__main__":
71+
pytest.main([__file__, "-v"])

0 commit comments

Comments
 (0)