| 1 | from unittest.mock import patch |
| 2 | |
| 3 | from nice_go._aws_cognito_authenticator import AwsCognitoAuthenticator |
| 4 | |
| 5 | |
| 6 | async def test_refresh_token(mock_authenticator: AwsCognitoAuthenticator) -> None: |
| 7 | with patch("nice_go._aws_cognito_authenticator.boto3.client") as mock_boto3_client: |
| 8 | mock_boto3_client.return_value.initiate_auth.return_value = { |
| 9 | "AuthenticationResult": {"IdToken": "test_token"}, |
| 10 | } |
| 11 | result = mock_authenticator.refresh_token("refresh_token") |
| 12 | |
| 13 | assert result.id_token == "test_token" |
| 14 | |
| 15 | |
| 16 | async def test_get_new_token(mock_authenticator: AwsCognitoAuthenticator) -> None: |
| 17 | with patch( |
| 18 | "nice_go._aws_cognito_authenticator.boto3.client", |
| 19 | ) as mock_boto3_client, patch( |
| 20 | "nice_go._aws_cognito_authenticator.AWSSRP", |
| 21 | ) as mock_awssrp: |
| 22 | mock_boto3_client.return_value.initiate_auth.return_value = { |
| 23 | "ChallengeParameters": {"key": "value"}, |
| 24 | } |
| 25 | mock_boto3_client.return_value.respond_to_auth_challenge.return_value = { |
| 26 | "AuthenticationResult": {"IdToken": "test_token"}, |
| 27 | } |
| 28 | mock_awssrp.return_value.get_auth_params.return_value = {"key": "value"} |
| 29 | mock_awssrp.return_value.process_challenge.return_value = {"key": "value"} |
| 30 | result = mock_authenticator.get_new_token("username", "password") |
| 31 | |
| 32 | assert result.id_token == "test_token" |
| 33 | assert result.refresh_token is None |