def test_untrusted_Origins_are_not_allowed_with_OriginCheck_Trusted(agent):
    # When using WebSocketOriginCheck Trusted, even a same-origin request isn't
    # good enough if the origin is not on the whitelist.
    response = yield make_request(agent, path='/origin-whitelist',
                                  origin=make_root())
    assert response.code == 403
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 2
0
def invalid_version_response(agent, request):
    """
    A fixture that performs a bad handshake with a prohibited WebSocket version.
    """
    response = pytest.blockon(make_request(agent, version=request.param))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
def invalid_version_response(agent, request):
    """
    A fixture that performs a bad handshake with a prohibited WebSocket version.
    """
    response = pytest.blockon(make_request(agent, version=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 4
0
def test_untrusted_Origins_are_not_allowed_with_OriginCheck_Trusted(agent):
    # When using WebSocketOriginCheck Trusted, even a same-origin request isn't
    # good enough if the origin is not on the whitelist.
    response = yield make_request(agent,
                                  path='/origin-whitelist',
                                  origin=make_root())
    assert response.code == 403
    client.readBody(response).cancel()  # immediately close the connection
Exemplo n.º 5
0
def bad_protocol_response(agent, request):
    """
    A fixture that performs a bad handshake with an invalid
    Sec-WebSocket-Protocol header.
    """
    response = pytest.blockon(make_request(agent, protocol=request.param))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
def bad_protocol_response(agent, request):
    """
    A fixture that performs a bad handshake with an invalid
    Sec-WebSocket-Protocol header.
    """
    response = pytest.blockon(make_request(agent, protocol=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 7
0
def trusted_origin_response(agent, request):
    """
    A fixture that performs a handshake using one of the explicitly trusted test
    Origins.
    """
    response = pytest.blockon(
        make_request(agent, path='/origin-whitelist', origin=request.param))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
def increment_response(agent, request):
    """
    A fixture that connects to the dumb-increment plugin with the given
    subprotocol list.
    """
    response = pytest.blockon(make_request(agent, path='/dumb-increment',
                                           protocol=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection
def trusted_origin_response(agent, request):
    """
    A fixture that performs a handshake using one of the explicitly trusted test
    Origins.
    """
    response = pytest.blockon(make_request(agent, path='/origin-whitelist',
                                                  origin=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 10
0
def good_origin_response(agent, request):
    """
    A fixture that performs a handshake with an Origin that matches the server.
    """
    host = make_authority(host=request.param[0])
    origin = make_root(host=request.param[0])
    version = request.param[1]

    response = pytest.blockon(
        make_request(agent, origin=origin, host=host, version=version))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
Exemplo n.º 11
0
def test_cpu_load_does_not_spike_when_idle(agent):
    """
    A regression test for issue #9 (railed CPU when a WebSocket connection is
    open but idle).
    """
    response = yield make_request(agent)

    try:
        # Now that the connection is open, see if any CPUs are in trouble.
        assert not any_cpus_railed()
    finally:
        client.readBody(response).cancel() # close the connection
def good_origin_response(agent, request):
    """
    A fixture that performs a handshake with an Origin that matches the server.
    """
    host = make_authority(host=request.param[0])
    origin = make_root(host=request.param[0])
    version = request.param[1]

    response = pytest.blockon(make_request(agent, origin=origin, host=host,
                                           version=version))
    yield response
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 13
0
def test_cpu_load_does_not_spike_when_idle(agent):
    """
    A regression test for issue #9 (railed CPU when a WebSocket connection is
    open but idle).
    """
    response = yield make_request(agent)

    try:
        # Now that the connection is open, see if any CPUs are in trouble.
        assert not any_cpus_railed()
    finally:
        client.readBody(response).cancel()  # close the connection
def bad_origin_response(agent, request):
    """
    A fixture that performs a good handshake, but with an Origin that does not
    match the server.
    """
    origin = request.param[0]
    host = request.param[1]
    version = request.param[2]

    response = pytest.blockon(make_request(agent, origin=origin, host=host,
                                           version=version))
    yield response
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 15
0
def bad_origin_response(agent, request):
    """
    A fixture that performs a good handshake, but with an Origin that does not
    match the server.
    """
    origin = request.param[0]
    host = request.param[1]
    version = request.param[2]

    response = pytest.blockon(
        make_request(agent, origin=origin, host=host, version=version))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
def test_HTTP_10_handshakes_are_refused(agent_10):
    response = yield make_request(agent_10)
    assert 400 <= response.code < 500
Exemplo n.º 17
0
def bad_key_response(agent, request):
    """A fixture that performs a bad handshake with an invalid key."""
    response = pytest.blockon(make_request(agent, key=request.param))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
Exemplo n.º 18
0
def success_response(agent, request):
    """A fixture that performs a correct handshake with the given version."""
    response = pytest.blockon(make_request(agent, version=request.param))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
def test_no_subprotocol_is_negotiated_by_default(agent):
    response = yield make_request(agent, protocol="my_protocol")
    assert_successful_upgrade(response)

    protocol = response.headers.getRawHeaders("Sec-WebSocket-Protocol")
    assert protocol is None
def bad_method_response(agent, request):
    """A fixture that performs a bad handshake with a disallowed HTTP method."""
    response = pytest.blockon(make_request(agent, method=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 21
0
def test_mismatched_Origins_are_allowed_with_OriginCheck_Off(agent):
    response = yield make_request(agent, path='/no-origin-check',
                                  origin='http://not-my-origin.com')
    assert_successful_upgrade(response)
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 22
0
def test_Location_without_plugin_returns_500(agent):
    response = yield make_request(agent, path='/bad-config')
    assert response.code == 500
    client.readBody(response).cancel() # immediately close the connection
Exemplo n.º 23
0
def test_HTTP_10_handshakes_are_refused(agent_10):
    response = yield make_request(agent_10)
    assert 400 <= response.code < 500
Exemplo n.º 24
0
def test_Location_without_plugin_returns_500(agent):
    response = yield make_request(agent, path='/bad-config')
    assert response.code == 500
    client.readBody(response).cancel()  # immediately close the connection
Exemplo n.º 25
0
def bad_method_response(agent, request):
    """A fixture that performs a bad handshake with a disallowed HTTP method."""
    response = pytest.blockon(make_request(agent, method=request.param))
    yield response
    client.readBody(response).cancel()  # immediately close the connection
Exemplo n.º 26
0
def test_mismatched_Origins_are_allowed_with_OriginCheck_Off(agent):
    response = yield make_request(agent,
                                  path='/no-origin-check',
                                  origin='http://not-my-origin.com')
    assert_successful_upgrade(response)
    client.readBody(response).cancel()  # immediately close the connection
def success_response(agent, request):
    """A fixture that performs a correct handshake with the given version."""
    response = pytest.blockon(make_request(agent, version=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection
def bad_key_response(agent, request):
    """A fixture that performs a bad handshake with an invalid key."""
    response = pytest.blockon(make_request(agent, key=request.param))
    yield response
    client.readBody(response).cancel() # immediately close the connection