Example #1
0
        public static IpAddressRequest GetCurrentIpAddress(bool?recordBadIp = null)
        {
            var request = RequestUtility.GetRequest();

            return(new IpAddressRequest()
            {
                IpAddress = RequestUtility.GetClientIpAddress(request),
                CreatedUtcDateTime = DateTime.UtcNow,
                IsBadRequest = recordBadIp.GetValueOrDefault()
            });
        }
Example #2
0
        public void MultipleValidPublicXForwardedFor_Returns_LastXForwardedFor()
        {
            // Arrange
            _httpRequest.UserHostAddress.Returns(GoogleIpAddress);
            _httpRequest.ServerVariables[XForwardedFor] = (GoogleIpAddress + "," + MicrosoftIpAddress);

            // Act
            var ip = RequestUtility.GetClientIpAddress(_httpRequest);

            // Assert
            Assert.Equal(ip, MicrosoftIpAddress);
        }
Example #3
0
        public void MalformedXForwardedFor_Returns_DefaultIpAddress()
        {
            // Arrange
            _httpRequest.UserHostAddress.Returns(GoogleIpAddress);
            _httpRequest.ServerVariables[XForwardedFor] = (MalformedIpAddress);

            // Act
            var ip = RequestUtility.GetClientIpAddress(_httpRequest);

            // Assert
            Assert.Equal(ip, DefaultIpAddress);
        }
Example #4
0
        public void PublicIpAndNullXForwardedFor_Returns_CorrectIp()
        {
            // Arrange
            _httpRequest.UserHostAddress.Returns(GoogleIpAddress);
            _httpRequest.ServerVariables[XForwardedFor] = string.Empty;

            // Act
            var ip = RequestUtility.GetClientIpAddress(_httpRequest);

            // Assert
            Assert.Equal(ip, GoogleIpAddress);
        }
Example #5
0
        public void SinglePrivateXForwardedFor_Returns_UserHostAddress()
        {
            // Arrange
            _httpRequest.UserHostAddress.Returns(GoogleIpAddress);
            _httpRequest.ServerVariables[XForwardedFor] = (Private24Bit);

            // Act
            var ip = RequestUtility.GetClientIpAddress(_httpRequest);

            // Assert
            Assert.Equal(ip, GoogleIpAddress);
        }
        public IpAddressBlockerRuleVerificationAttribute()
        {
            string ip      = RequestUtility.GetClientIpAddress(new HttpRequestWrapper(HttpContext.Current.Request));
            var    request = new IpAddressRequest
            {
                IpAddress          = ip,
                CreatedUtcDateTime = DateTime.UtcNow,
                IsBadRequest       = false
            };

            RuleSetRunner.Instance.VerifyRule(request);
        }
Example #7
0
        public void MultiplePublicXForwardedForWithPrivateLast_Returns_LastPublic()
        {
            // Arrange
            _httpRequest.UserHostAddress.Returns(GoogleIpAddress);
            const string privateIpList = Private24Bit + "," + Private20Bit + "," + MicrosoftIpAddress + "," + PrivateLinkLocal;

            _httpRequest.ServerVariables[XForwardedFor] = (privateIpList);

            // Act
            var ip = RequestUtility.GetClientIpAddress(_httpRequest);

            // Assert
            Assert.Equal(ip, MicrosoftIpAddress);
        }