Home / Function/ test_digestauth_only_on_4xx() — requests Function Reference

test_digestauth_only_on_4xx() — requests Function Reference

Architecture documentation for the test_digestauth_only_on_4xx() function in test_lowlevel.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  45a3b6b4_7df6_24a4_7eb3_9e0861b7fdc9["test_digestauth_only_on_4xx()"]
  48561d17_8bd1_bf20_5710_ec3053a534d2["test_lowlevel.py"]
  45a3b6b4_7df6_24a4_7eb3_9e0861b7fdc9 -->|defined in| 48561d17_8bd1_bf20_5710_ec3053a534d2
  7ab3c4d7_8531_6cbe_e871_9880cb1ee6de["consume_socket_content()"]
  45a3b6b4_7df6_24a4_7eb3_9e0861b7fdc9 -->|calls| 7ab3c4d7_8531_6cbe_e871_9880cb1ee6de
  style 45a3b6b4_7df6_24a4_7eb3_9e0861b7fdc9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/test_lowlevel.py lines 238–272

def test_digestauth_only_on_4xx():
    """Ensure we only send digestauth on 4xx challenges.

    See https://github.com/psf/requests/issues/3772.
    """
    text_200_chal = (b'HTTP/1.1 200 OK\r\n'
                     b'Content-Length: 0\r\n'
                     b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'
                     b', opaque="372825293d1c26955496c80ed6426e9e", '
                     b'realm="me@kennethreitz.com", qop=auth\r\n\r\n')

    auth = requests.auth.HTTPDigestAuth('user', 'pass')

    def digest_response_handler(sock):
        # Respond to GET with a 200 containing www-authenticate header.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content.startswith(b"GET / HTTP/1.1")
        sock.send(text_200_chal)

        # Verify the client didn't respond with auth.
        request_content = consume_socket_content(sock, timeout=0.5)
        assert request_content == b''

        return request_content

    close_server = threading.Event()
    server = Server(digest_response_handler, wait_to_close_event=close_server)

    with server as (host, port):
        url = f'http://{host}:{port}/'
        r = requests.get(url, auth=auth)
        # Verify server didn't receive auth from us.
        assert r.status_code == 200
        assert len(r.history) == 0
        close_server.set()

Domain

Subdomains

Frequently Asked Questions

What does test_digestauth_only_on_4xx() do?
test_digestauth_only_on_4xx() is a function in the requests codebase, defined in tests/test_lowlevel.py.
Where is test_digestauth_only_on_4xx() defined?
test_digestauth_only_on_4xx() is defined in tests/test_lowlevel.py at line 238.
What does test_digestauth_only_on_4xx() call?
test_digestauth_only_on_4xx() calls 1 function(s): consume_socket_content.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free