Ejemplo n.º 1
0
async def test_base_content():
    stream = ContentStream()
    sync_content = b"".join([part for part in stream])
    async_content = b"".join([part async for part in stream])

    assert stream.can_replay()
    assert stream.get_headers() == {}
    assert sync_content == b""
    assert async_content == b""
Ejemplo n.º 2
0
    def challenge_send(
        self,
        method: bytes,
        headers: typing.List[typing.Tuple[bytes, bytes]],
    ) -> typing.Tuple[bytes, int, bytes, typing.List[typing.Tuple[
            bytes, bytes]], ContentStream]:
        self._response_count += 1
        nonce = (
            hashlib.sha256(os.urandom(8)).hexdigest()
            if self._regenerate_nonce else
            "ee96edced2a0b43e4869e96ebe27563f369c1205a049d06419bb51d8aeddf3d3")
        challenge_data = {
            "nonce":
            nonce,
            "qop":
            self.qop,
            "opaque":
            ("ee6378f3ee14ebfd2fff54b70a91a7c9390518047f242ab2271380db0e14bda1"
             ),
            "algorithm":
            self.algorithm,
            "stale":
            "FALSE",
        }
        challenge_str = ", ".join('{}="{}"'.format(key, value)
                                  for key, value in challenge_data.items()
                                  if value)

        headers = [(
            b"www-authenticate",
            b'Digest realm="*****@*****.**", ' +
            challenge_str.encode("ascii"),
        )]
        return b"HTTP/1.1", 401, b"", headers, ContentStream()