-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * impl changes * unused import * wrap login_config response in Py42Response * move login_config call to only after error * add login_type to exception message * more tests * rename connection method to match sdk method * changelog * use .format until py42 removal merges * use .format until py42 removal merges * style * refactor into client * style * rm old method and move docstring over * loginconfig property docstring * f-strings and style * correct changelog method name * Add REST doc link
- Loading branch information
Showing
8 changed files
with
119 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
"securitydata", | ||
"auditlogs", | ||
"cases", | ||
"loginconfig", | ||
], | ||
) |
This file contains 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 @@ | ||
from py42.response import Py42Response | ||
|
||
|
||
class LoginConfigurationClient: | ||
def __init__(self, connection): | ||
self._connection = connection | ||
|
||
def get_for_user(self, username): | ||
"""Retrieves login configuration for a given username. Possible `loginType` values are | ||
`LOCAL`, `LOCAL_2FA`, and `CLOUD_SSO`. If username does not exist the default | ||
return value is `LOCAL_2FA`. | ||
`REST Documentation: <https://console.us.code42.com/swagger/index.html?urls.primaryName=v3#/Feature/get>`__ | ||
Args: | ||
username (str): Username to retrieve login configuration for. | ||
Returns: | ||
:class:`py42.response.Py42Response` | ||
""" | ||
uri = f"{self._connection.host_address}/c42api/v3/LoginConfiguration" | ||
response = self._connection._session.get(uri, params={"username": username}) | ||
return Py42Response(response) |
This file contains 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 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 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,39 @@ | ||
import pytest | ||
from requests.sessions import Session | ||
|
||
from py42.clients.loginconfig import LoginConfigurationClient | ||
from py42.services._connection import Connection | ||
|
||
HOST_ADDRESS = "example.com" | ||
|
||
|
||
class TestLoginConfiguration: | ||
@pytest.fixture | ||
def mock_session(self, mocker): | ||
mock_session = mocker.MagicMock(spec=Session) | ||
mock_session.headers = {} | ||
return mock_session | ||
|
||
def test_get_for_user_calls_session_get_with_expected_uri_and_params( | ||
self, mock_session | ||
): | ||
connection = Connection.from_host_address(HOST_ADDRESS, session=mock_session) | ||
loginconfig = LoginConfigurationClient(connection) | ||
loginconfig.get_for_user("test@example.com") | ||
expected_uri = f"https://{HOST_ADDRESS}/c42api/v3/LoginConfiguration" | ||
expected_params = {"username": "test@example.com"} | ||
mock_session.get.assert_called_once_with(expected_uri, params=expected_params) | ||
|
||
def test_get_for_user_does_not_use_py42_connection_get_method( | ||
self, mocker, mock_session | ||
): | ||
"""Because the loginConfiguration endpoint is unauthenticated, we want to make | ||
sure we don't force the Connection's C42RenewableAuth object to make any | ||
authentication requests before making the loginConfig request. | ||
""" | ||
mock_get = mocker.patch("py42.services._connection.Connection.get") | ||
connection = Connection.from_host_address(HOST_ADDRESS, session=mock_session) | ||
loginconfig = LoginConfigurationClient(connection) | ||
loginconfig.get_for_user("test@example.com") | ||
assert mock_get.call_count == 0 | ||
assert mock_session.get.call_count == 1 |
This file contains 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 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