Skip to content

Commit 1dc8eff

Browse files
authored
Doug/add unverified option (#56)
* feat: Add allow_unverified option to disable SSL certificate verification - Add allow_unverified parameter to socketdev constructor (defaults to False) - Add set_allow_unverified method to API class - Pass verify=not allow_unverified to requests.request() calls - Add comprehensive unit tests for the new functionality - Update README.rst with documentation for the new parameter - Maintains backward compatibility with existing code This allows users to disable SSL verification for testing environments with self-signed certificates while keeping secure defaults for production. * chore: Remove temporary test file that was accidentally committed
1 parent 29bfa3a commit 1dc8eff

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Initializing the module
2020
**PARAMETERS:**
2121

2222
- **token (str)** - The Socket API Key for your Organization
23-
- **Timeout (int)** - The number of seconds to wait before failing the connection
23+
- **timeout (int)** - The number of seconds to wait before failing the connection
24+
- **allow_unverified (bool)** - Whether to skip SSL certificate verification (default: False). Set to True for testing with self-signed certificates.
2425

2526
Supported Functions
2627
-------------------

socketdev/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444

4545

4646
class socketdev:
47-
def __init__(self, token: str, timeout: int = 1200):
47+
def __init__(self, token: str, timeout: int = 1200, allow_unverified: bool = False):
4848
self.api = API()
4949
self.token = token + ":"
5050
self.api.encode_key(self.token)
5151
self.api.set_timeout(timeout)
52+
self.api.set_allow_unverified(allow_unverified)
5253

5354
self.dependencies = Dependencies(self.api)
5455
self.export = Export(self.api)

socketdev/core/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ def __init__(self):
2525
self.encoded_key = None
2626
self.api_url = "https://api.socket.dev/v0"
2727
self.request_timeout = 30
28+
self.allow_unverified = False
2829

2930
def encode_key(self, token: str):
3031
self.encoded_key = base64.b64encode(token.encode()).decode("ascii")
3132

3233
def set_timeout(self, timeout: int):
3334
self.request_timeout = timeout
3435

36+
def set_allow_unverified(self, allow_unverified: bool):
37+
self.allow_unverified = allow_unverified
38+
3539
def do_request(
3640
self,
3741
path: str,
@@ -58,7 +62,8 @@ def format_headers(headers_dict):
5862
try:
5963

6064
response = requests.request(
61-
method.upper(), url, headers=headers, data=payload, files=files, timeout=self.request_timeout
65+
method.upper(), url, headers=headers, data=payload, files=files,
66+
timeout=self.request_timeout, verify=not self.allow_unverified
6267
)
6368
request_duration = time.time() - start_time
6469

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.17"
1+
__version__ = "3.0.19"

tests/unit/test_socket_sdk_unit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ def test_sdk_initialization(self):
3636
for component in expected_components:
3737
self.assertTrue(hasattr(sdk, component), f"SDK missing component: {component}")
3838

39+
def test_sdk_initialization_with_allow_unverified(self):
40+
"""Test that the SDK initializes correctly with allow_unverified option."""
41+
# Test default behavior (allow_unverified=False)
42+
sdk_default = socketdev(token="test-token")
43+
self.assertFalse(sdk_default.api.allow_unverified)
44+
45+
# Test with allow_unverified=True
46+
sdk_unverified = socketdev(token="test-token", allow_unverified=True)
47+
self.assertTrue(sdk_unverified.api.allow_unverified)
48+
49+
# Test with explicit allow_unverified=False
50+
sdk_verified = socketdev(token="test-token", allow_unverified=False)
51+
self.assertFalse(sdk_verified.api.allow_unverified)
52+
3953
def test_fullscan_params_creation(self):
4054
"""Test FullScanParams dataclass creation and conversion."""
4155
params = FullScanParams(

0 commit comments

Comments
 (0)