public void ForwardedForHeaderContainsMultipleEntriesRenderFirstValue() { // Arrange var(renderer, httpContext) = CreateWithHttpContext(); #if !ASP_NET_CORE httpContext.Request.ServerVariables.Returns(new NameValueCollection { { "REMOTE_ADDR", "192.0.0.0" } }); httpContext.Request.Headers.Returns( new NameValueCollection { { ForwardedForHeader, "127.0.0.1, 192.168.1.1" } }); #else var headers = new HeaderDict(); headers.Add(ForwardedForHeader, new StringValues("127.0.0.1, 192.168.1.1")); httpContext.Request.Headers.Returns(callinfo => headers); #endif renderer.CheckForwardedForHeader = true; // Act string result = renderer.Render(new LogEventInfo()); // Assert Assert.Equal("127.0.0.1", result); }
public void ForwardedForHeaderContainsMultipleEntriesRenderFirstValue() { var httpContext = Substitute.For <HttpContextBase>(); #if !ASP_NET_CORE httpContext.Request.ServerVariables.Returns(new NameValueCollection { { "REMOTE_ADDR", "192.0.0.0" } }); httpContext.Request.Headers.Returns( new NameValueCollection { { ForwardedForHeader, "127.0.0.1, 192.168.1.1" } }); #else var headers = new HeaderDict(); headers.Add(ForwardedForHeader, new StringValues("127.0.0.1, 192.168.1.1")); httpContext.Request.Headers.Returns(callinfo => headers); #endif var renderer = new AspNetRequestIpLayoutRenderer { CheckForwardedForHeader = true }; renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext); string result = renderer.Render(new LogEventInfo()); Assert.Equal("127.0.0.1", result); }
public void SetValue(string dataCode, string value) { if (HeaderDict.ContainsKey(dataCode)) { HeaderDict[dataCode] = value; } else { HeaderDict.Add(dataCode, value); } }
public void ReferrerPresentRenderNonEmptyString() { var httpContext = Substitute.For <HttpContextBase>(); #if !NETSTANDARD_1plus httpContext.Request.UrlReferrer.Returns(new Uri("http://www.google.com/")); #else var headers = new HeaderDict(); headers.Add("Referer", new StringValues("http://www.google.com/")); httpContext.Request.Headers.Returns((callinfo) => headers); #endif var renderer = new AspNetRequestReferrerRenderer(); renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext); string result = renderer.Render(new LogEventInfo()); Assert.Equal(result, "http://www.google.com/"); }
public void ReferrerPresentRenderNonEmptyString() { // Arrange var(renderer, httpContext) = CreateWithHttpContext(); #if !ASP_NET_CORE httpContext.Request.UrlReferrer.Returns(new Uri("http://www.google.com/")); #else var headers = new HeaderDict(); headers.Add("Referer", new StringValues("http://www.google.com/")); httpContext.Request.Headers.Returns(callinfo => headers); #endif // Act var result = renderer.Render(new LogEventInfo()); // Assert Assert.Equal("http://www.google.com/", result); }
public void NotNullUserAgentRendersEmptyString() { var httpContext = Substitute.For <HttpContextBase>(); #if !NETSTANDARD_1plus httpContext.Request.UserAgent.Returns("TEST"); #else var headers = new HeaderDict(); headers.Add("User-Agent", new StringValues("TEST")); httpContext.Request.Headers.Returns((callinfo) => headers); #endif var renderer = new AspNetRequestUserAgent(); renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext); string result = renderer.Render(new LogEventInfo()); Assert.Equal(result, "TEST"); }