public void ClientIpResolver_GetClientIp_NoXForwardedForHeaderSent_ShouldReturnActualIp() { // arrange string ip = "127.0.0.1"; _mockHttpContext.SetIp(ip); // act string result = _service.GetClientIp(); // assert Assert.AreEqual(ip, result); }
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_GetClientIp_IpIsLoopback_ForwardedHeaderSet_ShouldReturnForwardedIp() { // Arrange const string loopbackIp = "127.0.0.1"; const string forwardedIp = "123.123.123.123"; _mockContext.SetIp(loopbackIp); _mockContext.Request.Headers.Add("X-Forwarded-For", $"{forwardedIp}, 127.0.0.1"); // Act var ip = _resolver.GetClientIp(); // Assert Assert.AreEqual(forwardedIp, ip); }