예제 #1
0
def run_connection_test(get_peer, scenarios, test_func=None):
    """
    For each scenarios, s2n will attempt to perform a handshake with another TLS process
    and then run the given test.

    Args:
        get_peer: a function that returns a TLS process for s2n to communicate with.
            For an example of how to use this argument, see s2n_test_openssl.py.
        scenarios: a list of handshake configurations
        test_func: a function that takes a server and client process, performs some
            additional testing, and then returns a Result

    Returns:
        A Result object indicating success or failure. If the given test returns
        false or either the connection or the test throw an AssertionError, the Result
        will indicate failure.

    """
    def __test(scenario):
        client = None
        server = None
        try:
            server, client = connect(get_peer, scenario)
            if test_func:
                return test_func(server, client)
            else:
                return Result()
        except AssertionError as error:
            return Result(error)
        finally:
            cleanup_processes(server, client)

    return run_scenarios(__test, scenarios)
예제 #2
0
def run_connection_test(get_peer, scenarios, test_func=basic_write_test):
    """
    For each scenarios, s2n will attempt to perform a handshake with another TLS process
    and then run the given test.

    Args:
        get_peer: a function that returns a TLS process for s2n to communicate with.
            For an example of how to use this argument, see s2n_test_openssl.py.
        scenarios: a list of handshake configurations
        test_func: a function that takes a server and client process, performs some
            additional testing, and then returns a Result

    Returns:
        A Result object indicating success or failure. If the given test returns
        false or either the connection or the test throw an AssertionError, the Result
        will indicate failure.

    """
    def __test(scenario):
        client = None
        server = None
        result = Result("Unknown Error")
        try:
            server, client = connect(get_peer, scenario)
            result = test_func(server, client) if test_func else Result()

            if result.is_success() and client.poll() is not None:
                result = Result("Client process crashed")
            if result.is_success() and server.poll() is not None:
                result = Result("Server process crashed")

        except AssertionError as error:
            result = Result(error)
        finally:
            cleanup_processes(server, client)
            if client:
                result.client_error = get_error(client)
            if server:
                result.server_error = get_error(server)
            return result

    return run_scenarios(__test, scenarios)