def test_client_sender_authentication_ok(rf):
    authenticator = authentication.ClientSenderIdAuthentication()

    client_model_instance = factories.ClientFactory(
        name='test',
        access_key='test-key',
    )

    signer = sigauth.helpers.RequestSigner(
        secret='test-key',
        sender_id=str(client_model_instance.identifier),
    )
    headers = signer.get_signature_headers(
        url='/',
        body=None,
        method='get',
        content_type='text/plain',
    )
    request = rf.get('/', HTTP_X_SIGNATURE=headers[signer.header_name])

    client, _ = authenticator.authenticate(request)

    assert client == client_model_instance
def test_signature_check_middleware_valid_client(admin_client, settings):
    settings.MIDDLEWARE = SIGNATURE_CHECK_REQUIRED_MIDDLEWARE

    client_model_instance = factories.ClientFactory(
        name='test',
        access_key='test-key',
    )
    url = reverse('test_view')

    signer = sigauth.helpers.RequestSigner(
        secret='test-key',
        sender_id=str(client_model_instance.identifier),
    )
    headers = signer.get_signature_headers(
        url=url,
        body=None,
        method='get',
        content_type='text/plain',
    )
    response = admin_client.get(url, {},
                                HTTP_X_SIGNATURE=headers[signer.header_name])

    assert response.status_code == 200