Example #1
0
def test_basic_authorization() -> None:
    headers = CIMultiDict()
    headers['Authorization'] = "Basic {}".format(b64encode(b'identity:secret').decode('ascii'))
    request = BaseRequestWebsocket('GET', 'http', '/', headers)
    auth = request.authorization
    assert auth.username == 'identity'
    assert auth.password == 'secret'
Example #2
0
def test_url_structure(
    method: str,
    scheme: str,
    host: str,
    path: str,
    query_string: bytes,
    expected_path: str,
    expected_full_path: str,
    expected_url: str,
    expected_base_url: str,
    expected_url_root: str,
    expected_host_url: str,
) -> None:
    base_request_websocket = BaseRequestWebsocket(
        method,
        scheme,
        path,
        query_string,
        CIMultiDict({'host': host}),
        "",
        "1.1",
    )

    assert base_request_websocket.path == expected_path
    assert base_request_websocket.query_string == query_string
    assert base_request_websocket.full_path == expected_full_path
    assert base_request_websocket.url == expected_url
    assert base_request_websocket.base_url == expected_base_url
    assert base_request_websocket.url_root == expected_url_root
    assert base_request_websocket.host_url == expected_host_url
    assert base_request_websocket.host == host
    assert base_request_websocket.method == method
    assert base_request_websocket.scheme == scheme
    assert base_request_websocket.is_secure == scheme.endswith('s')
Example #3
0
def test_query_string() -> None:
    base_request_websocket = BaseRequestWebsocket(
        "GET", "http", "/", b"a=b&a=c&f", CIMultiDict({"host": "localhost"}),
        "", "1.1")
    assert base_request_websocket.query_string == b"a=b&a=c&f"
    assert base_request_websocket.args.getlist("a") == ["b", "c"]
    assert base_request_websocket.args["f"] == ""
Example #4
0
def test_basic_authorization() -> None:
    headers = CIMultiDict()
    headers["Authorization"] = "Basic {}".format(
        b64encode(b"identity:secret").decode("ascii"))
    request = BaseRequestWebsocket("GET", "http", "/", b"", headers, "", "1.1")
    auth = request.authorization
    assert auth.username == "identity"
    assert auth.password == "secret"
Example #5
0
def test_query_string() -> None:
    base_request_websocket = BaseRequestWebsocket(
        'GET',
        'http',
        '/',
        b'a=b&a=c&f',
        CIMultiDict({'host': 'localhost'}),
    )
    assert base_request_websocket.query_string == b'a=b&a=c&f'
    assert base_request_websocket.args.getlist('a') == ['b', 'c']
    assert base_request_websocket.args['f'] == ''
Example #6
0
def test_digest_authorization() -> None:
    headers = CIMultiDict()
    headers['Authorization'] = ('Digest '
                                'username="******", '
                                'realm="*****@*****.**", '
                                'nonce="abcd1234", '
                                'uri="/path", '
                                'response="abcd1235", '
                                'opaque="abcd1236"')
    request = BaseRequestWebsocket('GET', 'http', '/', b'', headers, "", "1.1")
    auth = request.authorization
    assert auth.username == 'identity'
    assert auth.realm == '*****@*****.**'
    assert auth.nonce == 'abcd1234'
    assert auth.uri == '/path'
    assert auth.response == 'abcd1235'
    assert auth.opaque == 'abcd1236'
Example #7
0
def test_digest_authorization() -> None:
    headers = CIMultiDict()
    headers["Authorization"] = ("Digest "
                                'username="******", '
                                'realm="*****@*****.**", '
                                'nonce="abcd1234", '
                                'uri="/path", '
                                'response="abcd1235", '
                                'opaque="abcd1236"')
    request = BaseRequestWebsocket("GET", "http", "/", b"", headers, "", "1.1")
    auth = request.authorization
    assert auth.username == "identity"
    assert auth.realm == "*****@*****.**"
    assert auth.nonce == "abcd1234"
    assert auth.uri == "/path"
    assert auth.response == "abcd1235"
    assert auth.opaque == "abcd1236"