-
Notifications
You must be signed in to change notification settings - Fork 141
fix: improve certifi error message and docs for SOAR (#191) #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dandye
merged 4 commits into
google:main
from
Som0111:fix/secops-soar-certifi-error-message-191
Sep 7, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4312a27
fix: improve certifi error message and docs for SOAR (#191)
Som0111 dde1505
fix: address review comments - PowerShell syntax, aiohttp SSL, ruff S…
Som0111 52a2a2d
fix: catch aiohttp.ClientSSLError in bindings.py and update error mes…
Som0111 b4259e7
fix: update copyright year to 2026 in test files
Som0111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import pytest_asyncio | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture(loop_scope="session", autouse=True) | ||
| async def setup_bindings(): | ||
| """Overrides tests/conftest.py's fixture: these unit tests mock | ||
| bindings/http_client directly and must not require real SOAR | ||
| credentials or network access.""" | ||
| yield | ||
89 changes: 89 additions & 0 deletions
89
server/secops-soar/tests/unit/test_certificate_error_handling.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Tests that certificate errors get a helpful message instead of the | ||
| generic "wrong SOAR credentials" one, and that HttpClient doesn't swallow | ||
| SSL errors as a plain None result (see issue #191).""" | ||
|
|
||
| import ssl | ||
| from unittest import mock | ||
|
|
||
| import aiohttp | ||
| import pytest | ||
|
|
||
| from secops_soar_mcp import bindings | ||
| from secops_soar_mcp.http_client import HttpClient | ||
|
|
||
|
|
||
| class _RaisingSession: | ||
| """Minimal aiohttp session stand-in whose .get() raises.""" | ||
|
|
||
| def __init__(self, exc: Exception): | ||
| self._exc = exc | ||
|
|
||
| def get(self, *args, **kwargs): | ||
| raise self._exc | ||
|
|
||
| async def close(self): | ||
| pass | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_http_client_get_reraises_ssl_error(): | ||
| client = HttpClient("https://example.com", "app-key") | ||
| client._session = _RaisingSession(ssl.SSLCertVerificationError("bad cert")) | ||
|
|
||
| with pytest.raises(ssl.SSLError): | ||
| await client.get("/some/endpoint") | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_http_client_get_swallows_generic_connection_error(): | ||
| client = HttpClient("https://example.com", "app-key") | ||
| client._session = _RaisingSession(aiohttp.ClientConnectionError("refused")) | ||
|
|
||
| assert await client.get("/some/endpoint") is None | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_get_valid_scopes_reports_certificate_issue_not_credentials(): | ||
| with ( | ||
| mock.patch.object( | ||
| bindings, | ||
| "http_client", | ||
| new=mock.AsyncMock(get=mock.AsyncMock(side_effect=ssl.SSLCertVerificationError())), | ||
| ), | ||
| pytest.raises(RuntimeError) as exc_info, | ||
| ): | ||
| await bindings._get_valid_scopes() | ||
|
|
||
| message = str(exc_info.value) | ||
| assert "certifi" in message.lower() | ||
| assert "certificate" in message.lower() | ||
| assert "not" in message.lower() and "credentials" in message.lower() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_get_valid_scopes_still_blames_credentials_when_no_data(): | ||
| with ( | ||
| mock.patch.object( | ||
| bindings, | ||
| "http_client", | ||
| new=mock.AsyncMock(get=mock.AsyncMock(return_value=None)), | ||
| ), | ||
| pytest.raises(RuntimeError) as exc_info, | ||
| ): | ||
| await bindings._get_valid_scopes() | ||
|
|
||
| assert "credentials" in str(exc_info.value).lower() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.