Exemplo n.º 1
0
        public async Task Run(TestContext ctx, HttpServer server, CancellationToken cancellationToken)
        {
            var handler = HelloWorldHandler.GetSimple();

            using (var operation = new TraditionalOperation(server, handler, true))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task RunAuthentication(
            TestContext ctx,
            [WebTestFeatures.SelectProxyKind(IncludeSSL = true)] ProxyKind kind,
            HttpServer server, [AuthenticationType] AuthenticationType authType,
            Handler handler, CancellationToken cancellationToken)
        {
            var           authHandler = new AuthenticationHandler(authType, handler);
            HttpOperation operation;

            if (kind == ProxyKind.Unauthenticated)
            {
                operation = new TraditionalOperation(server, authHandler, true,
                                                     HttpOperationFlags.AbortAfterClientExits,
                                                     HttpStatusCode.ProxyAuthenticationRequired, WebExceptionStatus.ProtocolError);
            }
            else
            {
                operation = new TraditionalOperation(server, authHandler, true);
            }
            try {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            } finally {
                operation.Dispose();
            }
        }
Exemplo n.º 3
0
        public async Task Run(
            TestContext ctx,
            [WebTestFeatures.SelectProxyKind(IncludeSSL = true)] ProxyKind kind,
            HttpServer server, Handler handler, CancellationToken cancellationToken)
        {
            var           oldCount = server.CountRequests;
            HttpOperation operation;

            if (kind == ProxyKind.Unauthenticated)
            {
                operation = new TraditionalOperation(
                    server, handler, true, HttpOperationFlags.AbortAfterClientExits,
                    HttpStatusCode.ProxyAuthenticationRequired, WebExceptionStatus.ProtocolError);
            }
            else
            {
                operation = new TraditionalOperation(
                    server, handler, true);
            }
            try {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);

                var newCount = server.CountRequests;
                ctx.Assert(newCount, Is.GreaterThan(oldCount), "used proxy");
            } finally {
                operation.Dispose();
            }
        }
Exemplo n.º 4
0
        public async Task MartinTest2(TestContext ctx, HttpServer server, CancellationToken cancellationToken)
        {
            var handler     = HelloWorldHandler.GetSimple();
            var authHandler = new AuthenticationHandler(AuthenticationType.NTLM, handler);

            using (var operation = new TraditionalOperation(server, authHandler, true))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 5
0
        public async Task Run(
            TestContext ctx, HttpServer server,
            [AuthenticationType] AuthenticationType authType, Handler handler,
            CancellationToken cancellationToken)
        {
            var authHandler = new AuthenticationHandler(authType, handler);

            using (var operation = new TraditionalOperation(server, authHandler, true))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 6
0
        public async Task Redirect(TestContext ctx, CancellationToken cancellationToken,
                                   HttpServer server, [RedirectStatus] HttpStatusCode code,
                                   Handler handler)
        {
            var description = string.Format("{0}: {1}", code, handler.Value);
            var redirect    = new RedirectHandler(handler, code, description);

            using (var operation = new TraditionalOperation(server, redirect, SendAsync))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 7
0
        public async Task Test31830(TestContext ctx, HttpServer server,
                                    bool writeStreamBuffering, CancellationToken cancellationToken)
        {
            var handler = new PostHandler("Obscure HTTP verb.");

            handler.Method = "EXECUTE";
            handler.AllowWriteStreamBuffering = writeStreamBuffering;
            handler.Flags |= RequestFlags.NoContentLength;
            using (var operation = new TraditionalOperation(server, handler, SendAsync))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 8
0
        public async Task RedirectAsGetNoBuffering(TestContext ctx, HttpServer server, CancellationToken cancellationToken)
        {
            var post = new PostHandler("RedirectAsGetNoBuffering", HttpContent.HelloChunked, TransferMode.Chunked)
            {
                Flags = RequestFlags.RedirectedAsGet,
                AllowWriteStreamBuffering = false
            };
            var handler = new RedirectHandler(post, HttpStatusCode.Redirect);

            using (var operation = new TraditionalOperation(server, handler, SendAsync))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 9
0
        public async Task MartinTest(
            TestContext ctx, HttpServer server, Handler handler,
            CancellationToken cancellationToken)
        {
            var oldCount = server.CountRequests;

            using (var operation = new TraditionalOperation(server, handler, true))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            var newCount = server.CountRequests;

            ctx.Assert(newCount, Is.GreaterThan(oldCount), "used proxy");
        }
Exemplo n.º 10
0
        public async Task MustClearAuthOnRedirect(
            TestContext ctx, HttpServer server,
            CancellationToken cancellationToken)
        {
            var target     = new HelloWorldHandler("Hello World");
            var targetAuth = new AuthenticationHandler(AuthenticationType.ForceNone, target);

            var redirect    = new RedirectHandler(targetAuth, HttpStatusCode.Redirect);
            var authHandler = new AuthenticationHandler(AuthenticationType.Basic, redirect);

            using (var operation = new TraditionalOperation(server, authHandler, true))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 11
0
        public async Task Run(TestContext ctx, HttpServer server,
                              [Fork(5, RandomDelay = 1500)] IFork fork, [Repeat(50)] int repeat,
                              [ForkHandler] Handler handler, CancellationToken cancellationToken)
        {
            var support = DependencyInjector.Get <IPortableSupport> ();

            ctx.LogMessage("FORK START: {0} {1}", fork.ID, support.CurrentThreadId);

            using (var operation = new TraditionalOperation(server, handler, true))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);

            ctx.LogMessage("FORK DONE: {0} {1}", fork.ID, support.CurrentThreadId);
        }
Exemplo n.º 12
0
        public async Task RedirectNoBuffering(TestContext ctx, HttpServer server, CancellationToken cancellationToken)
        {
            var post = new PostHandler("RedirectNoBuffering", HttpContent.HelloChunked, TransferMode.Chunked)
            {
                Flags = RequestFlags.Redirected,
                AllowWriteStreamBuffering = false
            };
            var handler = new RedirectHandler(post, HttpStatusCode.TemporaryRedirect);

            using (var operation = new TraditionalOperation(
                       server, handler, SendAsync, HttpOperationFlags.ClientDoesNotSendRedirect,
                       HttpStatusCode.TemporaryRedirect, WebExceptionStatus.ProtocolError)) {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 13
0
        public async Task Test18750(TestContext ctx, HttpServer server, CancellationToken cancellationToken)
        {
            var post = new PostHandler("First post", new StringContent("var1=value&var2=value2"))
            {
                Flags = RequestFlags.RedirectedAsGet
            };
            var redirect = new RedirectHandler(post, HttpStatusCode.Redirect);

            using (var operation = new WebClientOperation(server, redirect, WebClientOperationType.UploadStringTaskAsync)) {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }

            var secondPost = new PostHandler("Second post", new StringContent("Should send this"));

            using (var operation = new TraditionalOperation(server, secondPost, true)) {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 14
0
        public async Task Redirect(TestContext ctx, HttpServer server,
                                   [RedirectStatus] HttpStatusCode code, PostHandler post,
                                   CancellationToken cancellationToken)
        {
            var support   = DependencyInjector.Get <IPortableSupport> ();
            var isWindows = support.IsMicrosoftRuntime;
            var hasBody   = post.Content != null || ((post.Flags & RequestFlags.ExplicitlySetLength) != 0) || (post.Mode == TransferMode.ContentLength);

            if ((hasBody || !isWindows) && (code == HttpStatusCode.MovedPermanently || code == HttpStatusCode.Found))
            {
                post.Flags = RequestFlags.RedirectedAsGet;
            }
            else
            {
                post.Flags = RequestFlags.Redirected;
            }
            var identifier = string.Format("{0}: {1}", code, post.ID);
            var redirect   = new RedirectHandler(post, code, identifier);

            using (var operation = new TraditionalOperation(server, redirect, SendAsync))
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 15
0
 public async Task TestRecentlyFixed(TestContext ctx, HttpServer server, Handler handler,
                                     CancellationToken cancellationToken)
 {
     using (var operation = new TraditionalOperation(server, handler, SendAsync))
         await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
 }
Exemplo n.º 16
0
 public async Task ForceTls12(TestContext ctx, CancellationToken cancellationToken,
                              HttpServer server, [SimpleWebHandler] Handler handler)
 {
     using (var operation = new TraditionalOperation(server, handler, true))
         await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
 }