Ejemplo n.º 1
0
        async Task <bool> IHttpServerDelegate.CheckCreateConnection(
            TestContext ctx, HttpConnection connection, Task initTask,
            CancellationToken cancellationToken)
        {
            try {
                await initTask.ConfigureAwait(false);
            } catch (OperationCanceledException) {
                throw;
            } catch (Exception error) {
                if (Parameters.ClientAbortsHandshake)
                {
                    ctx.LogDebug(5, "HttpTestRunner - CreateConnection got expected exception");
                    return(false);
                }
                ctx.LogDebug(5, "HttpTestRunner - CreateConnection ex: {0}", error);
                throw;
            }

            /*
             * There seems to be some kind of a race condition here.
             *
             * When the client aborts the handshake due the a certificate validation failure,
             * then we either receive an exception during the TLS handshake or the connection
             * will be closed when the handshake is completed.
             *
             */
            bool haveReq;

            try {
                haveReq = await connection.HasRequest(cancellationToken).ConfigureAwait(false);

                ctx.LogDebug(5, "HttpTestRunner - CreateConnection #1: {0}", haveReq);
            } catch {
                if (Parameters.ClientAbortsHandshake)
                {
                    return(false);
                }
                throw;
            }
            if (Parameters.ClientAbortsHandshake)
            {
                ctx.Assert(haveReq, Is.False, "expected client to abort handshake");
                return(false);
            }
            ctx.Assert(haveReq, Is.True, "expected non-empty request");
            return(true);
        }