Пример #1
0
        public void Should_CreatePipeline_Without_CompressionHandler()
        {
            using (AuthenticationHandler authenticationHandler = (AuthenticationHandler)GraphClientFactory.CreatePipeline(handlers))
                using (RetryHandler retryHandler = (RetryHandler)authenticationHandler.InnerHandler)
                    using (RedirectHandler redirectHandler = (RedirectHandler)retryHandler.InnerHandler)
#if iOS
                        using (NSUrlSessionHandler innerMost = (NSUrlSessionHandler)redirectHandler.InnerHandler)
#elif macOS
                        using (Foundation.NSUrlSessionHandler innerMost = (Foundation.NSUrlSessionHandler)redirectHandler.InnerHandler)
#endif
                        {
                            Assert.NotNull(authenticationHandler);
                            Assert.NotNull(retryHandler);
                            Assert.NotNull(redirectHandler);
                            Assert.NotNull(innerMost);
                            Assert.IsType <AuthenticationHandler>(authenticationHandler);
                            Assert.IsType <RetryHandler>(retryHandler);
                            Assert.IsType <RedirectHandler>(redirectHandler);
#if iOS
                            Assert.IsType <NSUrlSessionHandler>(innerMost);
#elif macOS
                            Assert.IsType <Foundation.NSUrlSessionHandler>(innerMost);
#endif
                        }
        }
 public GraphClientFactoryTests()
 {
     this.testHttpMessageHandler = new MockRedirectHandler();
     handlers    = new DelegatingHandler[3];
     handlers[0] = new RetryHandler();
     handlers[1] = new RedirectHandler();
     handlers[2] = new AuthenticationHandler(authenticationProvider.Object);
 }
Пример #3
0
 public void RedirectHandler_Constructor()
 {
     using (RedirectHandler redirect = new RedirectHandler())
     {
         Assert.Null(redirect.InnerHandler);
         Assert.IsType(typeof(RedirectHandler), redirect);
     }
 }
 public void RedirectHandler_Constructor()
 {
     using (RedirectHandler redirect = new RedirectHandler())
     {
         Assert.IsNull(redirect.InnerHandler, "HttpMessageHandler initialized.");
         Assert.IsInstanceOfType(redirect, typeof(RedirectHandler), "Unexpected redirect handler set.");
     }
 }
Пример #5
0
 public IEnumerable<Handler> BrokenRedirect()
 {
     var post = new PostHandler () {
         Description = "Chunked post", Body = "Hello Chunked World!", Mode = TransferMode.Chunked, Flags = RequestFlags.Redirected
     };
     var redirect = new RedirectHandler (post, HttpStatusCode.TemporaryRedirect) { Description = post.Description };
     yield return redirect;
 }
Пример #6
0
        public 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);

            return(TestRunner.RunTraditional(ctx, server, redirect, cancellationToken, SendAsync));
        }
        static HttpMessageInvoker CreateInvoker(HttpResponseMessage httpResponseMessage1, HttpResponseMessage httpResponseMessage2 = null)
        {
            var redirectHandler = new RedirectHandler
            {
                InnerHandler = new MockRedirectHandler(httpResponseMessage1, httpResponseMessage2)
            };
            var invoker = new HttpMessageInvoker(redirectHandler);

            return(invoker);
        }
 public void RedirectHandler_Constructor()
 {
     using (RedirectHandler redirect = new RedirectHandler())
     {
         Assert.Null(redirect.InnerHandler);
         Assert.NotNull(redirect.RedirectOption);
         Assert.Equal(5, redirect.RedirectOption.MaxRedirect); // default MaxRedirects is 5
         Assert.IsType <RedirectHandler>(redirect);
     }
 }
Пример #9
0
        public void MustClearAuthOnRedirect()
        {
            var target     = new HelloWorldHandler();
            var targetAuth = new AuthenticationHandler(AuthenticationType.ForceNone, target);

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

            Run(authHandler);
        }
Пример #10
0
        public static Task RunHttpClient(
            TestContext ctx, CancellationToken cancellationToken, HttpServer server,
            HttpClientHandler handler, RedirectHandler redirect = null,
            HttpStatusCode expectedStatus    = HttpStatusCode.OK,
            WebExceptionStatus expectedError = WebExceptionStatus.Success)
        {
            var runner = new HttpClientTestRunner(server, handler, redirect);

            return(runner.Run(ctx, cancellationToken, expectedStatus, expectedError));
        }
        public void RedirectHandler_HttpMessageHandlerConstructor()
        {
            var _response1         = new HttpResponseMessage(HttpStatusCode.Found);
            var httpMessageHandler = new MockRedirectHander(_response1);
            var redirectHandler    = new RedirectHandler(httpMessageHandler);

            Assert.IsNotNull(redirectHandler.InnerHandler, "HttpMessageHandler not initialized.");
            Assert.AreEqual(redirectHandler.InnerHandler, httpMessageHandler, "Unexpected message handler set.");
            Assert.IsInstanceOfType(redirectHandler, typeof(RedirectHandler), "Unexpected redirect handler set.");
        }
Пример #12
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);
        }
Пример #13
0
        public 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);

            return(TestRunner.RunTraditional(ctx, server, handler, cancellationToken, SendAsync));
        }
        public RedirectHandlerTest()
        {
            var request = new Request {
                Method  = "GET",
                Path    = "/redirect",
                Version = "HTTP/1.1"
            };
            var handler = new RedirectHandler();

            _response = handler.Handle(request);
        }
Пример #15
0
        public 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);

            return(TestRunner.RunTraditional(ctx, server, authHandler, cancellationToken, SendAsync));
        }
 public void RedirectHandler_RedirectOptionConstructor()
 {
     using (RedirectHandler redirect = new RedirectHandler(new RedirectHandlerOption {
         MaxRedirect = 2
     }))
     {
         Assert.Null(redirect.InnerHandler);
         Assert.NotNull(redirect.RedirectOption);
         Assert.Equal(2, redirect.RedirectOption.MaxRedirect);
         Assert.IsType <RedirectHandler>(redirect);
     }
 }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
0
        public void RedirectNoBuffering()
        {
            var post = new PostHandler {
                Description = "Chunked post",
                Body        = "Hello chunked world",
                Mode        = TransferMode.Chunked,
                Flags       = RequestFlags.Redirected,
                AllowWriteStreamBuffering = false
            };
            var redirect = new RedirectHandler(post, HttpStatusCode.TemporaryRedirect);

            Run(redirect, HttpStatusCode.TemporaryRedirect, true);
        }
Пример #20
0
        public Task RedirectNoBuffering(
            TestContext ctx, [HttpServer] 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);

            return(TestRunner.RunTraditional(
                       ctx, server, handler, cancellationToken, false,
                       HttpStatusCode.TemporaryRedirect, WebExceptionStatus.ProtocolError));
        }
Пример #21
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);
            }
        }
Пример #22
0
        public void HandleRedirectResultWithNullResulte()
        {
            // Setup
            var mvc     = new MvcEngine();
            var handler = new RedirectHandler(_mockNavigator.Object);
            var values  = new RouteDictionary();
            var result  = new RedirectResult
            {
                ControllerName = "Test",
                ActionName     = "Index",
                Values         = new RouteDictionary(),
            };

            // Execute
            handler.Handle(a_mvc: mvc, a_controllerName: "AnotherTest", a_result: null);
        }
Пример #23
0
 public void CreatePipelineWithHttpMessageHandlerInput()
 {
     using (RetryHandler retryHandler = (RetryHandler)GraphClientFactory.CreatePipeline(this.testHttpMessageHandler, handlers))
         using (RedirectHandler redirectHandler = (RedirectHandler)retryHandler.InnerHandler)
             using (AuthenticationHandler authenticationHandler = (AuthenticationHandler)redirectHandler.InnerHandler)
                 using (MockRedirectHandler innerMost = (MockRedirectHandler)authenticationHandler.InnerHandler)
                 {
                     Assert.NotNull(retryHandler);
                     Assert.NotNull(redirectHandler);
                     Assert.NotNull(authenticationHandler);
                     Assert.NotNull(innerMost);
                     Assert.IsType(typeof(RetryHandler), retryHandler);
                     Assert.IsType(typeof(RedirectHandler), redirectHandler);
                     Assert.IsType(typeof(AuthenticationHandler), authenticationHandler);
                     Assert.IsType(typeof(MockRedirectHandler), innerMost);
                 }
 }
 public void CreatePipelineWithHttpMessageHandlerInput()
 {
     using (RetryHandler retryHandler = (RetryHandler)GraphClientFactory.CreatePipeline(handlers, this.testHttpMessageHandler))
         using (RedirectHandler redirectHandler = (RedirectHandler)retryHandler.InnerHandler)
             using (AuthenticationHandler authenticationHandler = (AuthenticationHandler)redirectHandler.InnerHandler)
                 using (MockRedirectHandler innerMost = (MockRedirectHandler)authenticationHandler.InnerHandler)
                 {
                     Assert.IsNotNull(retryHandler, "Create a middleware pipeline failed.");
                     Assert.IsNotNull(redirectHandler, "Create a middleware pipeline failed.");
                     Assert.IsNotNull(authenticationHandler, "Create a middleware pipeline failed.");
                     Assert.IsNotNull(innerMost, "Create inner most HttpMessageHandler failed.");
                     Assert.IsInstanceOfType(retryHandler, typeof(RetryHandler), "Pass pipeline failed in first level.");
                     Assert.IsInstanceOfType(redirectHandler, typeof(RedirectHandler), "Pass pipeline failed in seconde level.");
                     Assert.IsInstanceOfType(authenticationHandler, typeof(AuthenticationHandler), "Pass pipeline failed in third level.");
                     Assert.IsInstanceOfType(innerMost, typeof(MockRedirectHandler), "Inner most HttpMessageHandler class error.");
                 }
 }
Пример #25
0
        public void HandleRedirectResultWithNullMvcEngine()
        {
            // Setup
            var handler = new RedirectHandler(_mockNavigator.Object);
            var values  = new RouteDictionary();
            var result  = new RedirectResult
            {
                ControllerName = "Test",
                ActionName     = "Index",
                Values         = new RouteDictionary(),
            };

            // Execute
            handler.Handle(a_mvc: null, a_controllerName: "AnotherTest", a_result: result);

            // Assert
            _mockNavigator.Verify(i => i.Navigate("Test", "Index", values), Times.Once);
        }
Пример #26
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);
            }
        }
        /// <summary>
        /// Configures Web API routes.
        /// </summary>
        /// <param name="configuration"></param>
        public static void Configure(HttpConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration.MapHttpAttributeRoutes();

            using (var handler = new RedirectHandler(m => m.RequestUri.ToString(), "swagger"))
            {
                configuration.Routes.MapHttpRoute(
                    name: "swagger_root",
                    routeTemplate: "",
                    defaults: null,
                    constraints: null,
                    handler: handler);
            }
        }
Пример #28
0
        public void HandleRedirectResultWithNoControllerName()
        {
            // Setup
            var mvc = new MvcEngine();
            var handler = new RedirectHandler(_mockNavigator.Object);
            var values = new RouteDictionary();
            var result = new RedirectResult
            {
                ControllerName = null,
                ActionName = "Index",
                Values = new RouteDictionary(),
            };

            // Execute
            handler.Handle(mvc, "AnotherTest", result);

            // Assert
            _mockNavigator.Verify(i => i.Navigate("AnotherTest", "Index", values), Times.Once);
        }
Пример #29
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);

            var uri = redirect.RegisterRequest(server);

            using (var wc = new WebClient()) {
                var res = await wc.UploadStringTaskAsync(uri, post.Content.AsString());

                ctx.LogDebug(2, "Test18750: {0}", res);
            }

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

            await TestRunner.RunTraditional(ctx, server, secondPost, cancellationToken, SendAsync);
        }
Пример #30
0
 public void Should_CreatePipeline_Without_HttpMessageHandlerInput()
 {
     using (AuthenticationHandler authenticationHandler = (AuthenticationHandler)GraphClientFactory.CreatePipeline(handlers))
         using (CompressionHandler compressionHandler = (CompressionHandler)authenticationHandler.InnerHandler)
             using (RetryHandler retryHandler = (RetryHandler)compressionHandler.InnerHandler)
                 using (RedirectHandler redirectHandler = (RedirectHandler)retryHandler.InnerHandler)
                     using (HttpMessageHandler innerMost = redirectHandler.InnerHandler)
                     {
                         Assert.NotNull(authenticationHandler);
                         Assert.NotNull(compressionHandler);
                         Assert.NotNull(retryHandler);
                         Assert.NotNull(redirectHandler);
                         Assert.NotNull(innerMost);
                         Assert.IsType <AuthenticationHandler>(authenticationHandler);
                         Assert.IsType <CompressionHandler>(compressionHandler);
                         Assert.IsType <RetryHandler>(retryHandler);
                         Assert.IsType <RedirectHandler>(redirectHandler);
                         Assert.True(innerMost is HttpMessageHandler);
                     }
 }
Пример #31
0
 public void CreatePipelineWithHttpMessageHandlerInput()
 {
     using (AuthenticationHandler authenticationHandler = (AuthenticationHandler)GraphClientFactory.CreatePipeline(handlers, this.testHttpMessageHandler))
         using (CompressionHandler compressionHandler = (CompressionHandler)authenticationHandler.InnerHandler)
             using (RetryHandler retryHandler = (RetryHandler)compressionHandler.InnerHandler)
                 using (RedirectHandler redirectHandler = (RedirectHandler)retryHandler.InnerHandler)
                     using (MockRedirectHandler innerMost = (MockRedirectHandler)redirectHandler.InnerHandler)
                     {
                         Assert.NotNull(authenticationHandler);
                         Assert.NotNull(compressionHandler);
                         Assert.NotNull(retryHandler);
                         Assert.NotNull(redirectHandler);
                         Assert.NotNull(innerMost);
                         Assert.IsType <AuthenticationHandler>(authenticationHandler);
                         Assert.IsType <CompressionHandler>(compressionHandler);
                         Assert.IsType <RetryHandler>(retryHandler);
                         Assert.IsType <RedirectHandler>(redirectHandler);
                         Assert.IsType <MockRedirectHandler>(innerMost);
                     }
 }
Пример #32
0
        public 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);

            return(TestRunner.RunTraditional(ctx, server, redirect, cancellationToken, SendAsync));
        }
Пример #33
0
        public void HandleRedirectResultWithNullControllerName()
        {
            // Setup
            var mvc = new MvcEngine();
            var handler = new RedirectHandler(_mockNavigator.Object);
            var values = new RouteDictionary();
            var result = new RedirectResult
            {
                ControllerName = "Test",
                ActionName = "Index",
                Values = new RouteDictionary(),
            };

            // Execute
            handler.Handle(a_mvc: mvc, a_controllerName:null, a_result:result);
        }
Пример #34
0
 public void WhenTheRequestIsMade()
 {
     _handler = new RedirectHandler();
     _handler.ProcessRequest(mockContext.Object, oldUrl, newUrl);
 }
Пример #35
0
        /// <summary>
        /// Read a stream and forwards all data to the indicated
        /// delegate.
        /// </summary>
        /// <param name="target">The receiving callback.</param>
        /// <param name="source">The input data <see cref="Stream"/>.</param>
        private static void RedirectStream( RedirectHandler target, Stream source )
        {
            // Buffer
            byte[] aBuf = new byte[100000];

            // Stop on any error
            try
            {
                // As long as necessary
                for (int nBytes = 0; (nBytes = source.Read( aBuf, 0, aBuf.Length )) > 0; )
                    if (null != target)
                        target( aBuf, nBytes );
            }
            catch
            {
                // Just ignore - partner may have died
            }

            // Send end code
            if (null != target)
                target( aBuf, 0 );
        }