Exemplo n.º 1
0
        public void HttpContextService_GetHost_NoXForwardedHostHeaderSet_ShouldReturnOriginalHost()
        {
            // arrange
            string host = "ducode.org";

            _mockHttpContext.SetHost(host);
            _mockHttpContext.SetIp("11.22.33.44");

            // act
            string result = _service.GetHost();

            // assert
            Assert.AreEqual(host, result);
        }
        public void ClientDataResolver_GetHost_IpIsNotLoopback_ForwardedHeaderSet_ShouldReturnActualHost()
        {
            // Arrange
            const string loopbackIp = "111.111.111.111";

            _mockContext.SetIp(loopbackIp);

            const string forwardedHost = "httplaceholder.com";

            _mockContext.Request.Headers.Add("X-Forwarded-Host", forwardedHost);

            var actualHost = "localhost";

            _mockContext.SetHost(actualHost);

            // Act
            var host = _resolver.GetHost();

            // Assert
            Assert.AreEqual(actualHost, host);
        }