diff --git a/README.rst b/README.rst index 7ba2530..bd16967 100644 --- a/README.rst +++ b/README.rst @@ -20,7 +20,8 @@ Initializing the module **PARAMETERS:** - **token (str)** - The Socket API Key for your Organization -- **Timeout (int)** - The number of seconds to wait before failing the connection +- **timeout (int)** - The number of seconds to wait before failing the connection +- **allow_unverified (bool)** - Whether to skip SSL certificate verification (default: False). Set to True for testing with self-signed certificates. Supported Functions ------------------- diff --git a/socketdev/__init__.py b/socketdev/__init__.py index 04a7227..0de575b 100644 --- a/socketdev/__init__.py +++ b/socketdev/__init__.py @@ -44,11 +44,12 @@ class socketdev: - def __init__(self, token: str, timeout: int = 1200): + def __init__(self, token: str, timeout: int = 1200, allow_unverified: bool = False): self.api = API() self.token = token + ":" self.api.encode_key(self.token) self.api.set_timeout(timeout) + self.api.set_allow_unverified(allow_unverified) self.dependencies = Dependencies(self.api) self.export = Export(self.api) diff --git a/socketdev/core/api.py b/socketdev/core/api.py index 566b53b..8856b7a 100644 --- a/socketdev/core/api.py +++ b/socketdev/core/api.py @@ -25,6 +25,7 @@ def __init__(self): self.encoded_key = None self.api_url = "https://api.socket.dev/v0" self.request_timeout = 30 + self.allow_unverified = False def encode_key(self, token: str): self.encoded_key = base64.b64encode(token.encode()).decode("ascii") @@ -32,6 +33,9 @@ def encode_key(self, token: str): def set_timeout(self, timeout: int): self.request_timeout = timeout + def set_allow_unverified(self, allow_unverified: bool): + self.allow_unverified = allow_unverified + def do_request( self, path: str, @@ -58,7 +62,8 @@ def format_headers(headers_dict): try: response = requests.request( - method.upper(), url, headers=headers, data=payload, files=files, timeout=self.request_timeout + method.upper(), url, headers=headers, data=payload, files=files, + timeout=self.request_timeout, verify=not self.allow_unverified ) request_duration = time.time() - start_time diff --git a/socketdev/version.py b/socketdev/version.py index 6e22e02..870a457 100644 --- a/socketdev/version.py +++ b/socketdev/version.py @@ -1 +1 @@ -__version__ = "3.0.17" +__version__ = "3.0.19" diff --git a/tests/unit/test_socket_sdk_unit.py b/tests/unit/test_socket_sdk_unit.py index f89767a..b64aaec 100644 --- a/tests/unit/test_socket_sdk_unit.py +++ b/tests/unit/test_socket_sdk_unit.py @@ -36,6 +36,20 @@ def test_sdk_initialization(self): for component in expected_components: self.assertTrue(hasattr(sdk, component), f"SDK missing component: {component}") + def test_sdk_initialization_with_allow_unverified(self): + """Test that the SDK initializes correctly with allow_unverified option.""" + # Test default behavior (allow_unverified=False) + sdk_default = socketdev(token="test-token") + self.assertFalse(sdk_default.api.allow_unverified) + + # Test with allow_unverified=True + sdk_unverified = socketdev(token="test-token", allow_unverified=True) + self.assertTrue(sdk_unverified.api.allow_unverified) + + # Test with explicit allow_unverified=False + sdk_verified = socketdev(token="test-token", allow_unverified=False) + self.assertFalse(sdk_verified.api.allow_unverified) + def test_fullscan_params_creation(self): """Test FullScanParams dataclass creation and conversion.""" params = FullScanParams(