mock.sentinel.rsa_path

Here are the examples of the python api mock.sentinel.rsa_path taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: box-python-sdk Source File: test_jwt_auth.py
@contextmanager
def jwt_auth_init_mocks(
        mock_network_layer,
        successful_token_response,
        jwt_algorithm,
        jwt_key_id,
        rsa_passphrase,
        enterprise_id=None,
):
    # pylint:disable=redefined-outer-name
    fake_client_id = 'fake_client_id'
    fake_client_secret = 'fake_client_secret'
    assertion = Mock()
    data = {
        'grant_type': JWTAuth._GRANT_TYPE,  # pylint:disable=protected-access
        'client_id': fake_client_id,
        'client_secret': fake_client_secret,
        'assertion': assertion,
        'box_device_id': '0',
        'box_device_name': 'my_awesome_device',
    }

    mock_network_layer.request.return_value = successful_token_response
    key_file_read_data = b'key_file_read_data'
    with patch('boxsdk.auth.jwt_auth.open', mock_open(read_data=key_file_read_data), create=True) as jwt_auth_open:
        with patch('cryptography.hazmat.primitives.serialization.load_pem_private_key') as load_pem_private_key:
            oauth = JWTAuth(
                client_id=fake_client_id,
                client_secret=fake_client_secret,
                enterprise_id=enterprise_id,
                rsa_private_key_file_sys_path=sentinel.rsa_path,
                rsa_private_key_passphrase=rsa_passphrase,
                network_layer=mock_network_layer,
                box_device_name='my_awesome_device',
                jwt_algorithm=jwt_algorithm,
                jwt_key_id=jwt_key_id,
            )

            jwt_auth_open.assert_called_once_with(sentinel.rsa_path, 'rb')
            jwt_auth_open.return_value.read.assert_called_once_with()  # pylint:disable=no-member
            load_pem_private_key.assert_called_once_with(
                key_file_read_data,
                password=rsa_passphrase,
                backend=default_backend(),
            )

            yield oauth, assertion, fake_client_id, load_pem_private_key.return_value

    mock_network_layer.request.assert_called_once_with(
        'POST',
        '{0}/token'.format(API.OAUTH2_API_URL),
        data=data,
        headers={'content-type': 'application/x-www-form-urlencoded'},
        access_token=None,
    )
    assert oauth.access_token == successful_token_response.json()['access_token']