public void Block_brand_website_for_ip_address_ranges_specified_with_dashes() { // *** Arrange *** var ipAddressRangeWithDash = TestDataGenerator.GetRandomIpAddressV4Range(IpAddressRangeSeparators.Dash); const string redirectionUrl = "google.com"; if (Brand == null) { //Assert.Fail throws the exception for NUnit framework, so execution of the test stops Assert.Fail("Brand not found"); } var brandIpRegulation = new AddBrandIpRegulationData { IpAddress = ipAddressRangeWithDash, BrandId = Brand.Id, // Ip address is blocked with redirection to specified Url BlockingType = IpRegulationConstants.BlockingTypes.Redirection, RedirectionUrl = redirectionUrl }; _brandService.CreateIpRegulation(brandIpRegulation); // Expand ip address range into list of ip addresses, e.g. 192.168.5.10/12 is expanded into [192.168.5.10, 192.168.5.11] var expandedIpAddressRange = IpRegulationRangeHelper.ExpandIpAddressRange(ipAddressRangeWithDash).ToList(); // *** Act *** var ipAddressRangeVerificationResults = expandedIpAddressRange.Select(address => _brandService.VerifyIpAddress(address, Brand.Id)).ToList(); // *** Assert *** var isIpAddressRangeBlocked = ipAddressRangeVerificationResults .Aggregate(false, (current, result) => current || !result.Allowed); var isIpRegulationBlockingTypeSetToRedirection = ipAddressRangeVerificationResults .Aggregate(true, (current, result) => current && result.BlockingType == IpRegulationConstants.BlockingTypes.Redirection); var isIpRegulationRedirectionUrlSetToDefinedUrl = ipAddressRangeVerificationResults .Aggregate(true, (current, result) => current && result.RedirectionUrl == redirectionUrl); Assert.True(isIpAddressRangeBlocked); Assert.True(isIpRegulationBlockingTypeSetToRedirection); Assert.True(isIpRegulationRedirectionUrlSetToDefinedUrl); }
public void Allow_access_to_admin_website_for_ip_address_ranges_specified_with_dashes() { // *** Arrange *** var ipAddressRangeWithDash = TestDataGenerator.GetRandomIpAddressV4Range(IpAddressRangeSeparators.Dash); var adminIpRegulation = new AddBackendIpRegulationData { IpAddress = ipAddressRangeWithDash }; _backendService.CreateIpRegulation(adminIpRegulation); // Expand ip address range into list of ip addresses, e.g. 192.168.5.10/12 is expanded into [192.168.5.10, 192.168.5.11] var expandedIpAddressRange = IpRegulationRangeHelper.ExpandIpAddressRange(ipAddressRangeWithDash).ToList(); // *** Act *** var isIpAddressRangeAllowed = expandedIpAddressRange.Select(address => _backendService.VerifyIpAddress(address)) .Aggregate(true, (current, result) => current && result); // *** Assert *** Assert.True(isIpAddressRangeAllowed); }
public void Can_expand_ip_address_range() { // *** Arrange *** const string testAddressRangeLastSegment = "192.168.5.10-20"; const string testAddressRangeAllSegmnents = "160-170.100-120.5-10.10-20"; const string testAddressWithoutRange = "192.168.5.10"; // *** Act *** var expandedRangeInLastSegment = IpRegulationRangeHelper.ExpandIpAddressRange(testAddressRangeLastSegment).ToList(); var expandedRangeInAllSegments = IpRegulationRangeHelper.ExpandIpAddressRange(testAddressRangeAllSegmnents).ToList(); var expandedAddressWithoutRange = IpRegulationRangeHelper.ExpandIpAddressRange(testAddressWithoutRange).ToList(); // *** Assert *** Assert.True(expandedRangeInLastSegment.Count == 11); Assert.True(expandedRangeInLastSegment.First() == "192.168.5.10"); Assert.True(expandedRangeInLastSegment.Last() == "192.168.5.20"); Assert.True(expandedRangeInAllSegments.Count == 15246); Assert.True(expandedRangeInAllSegments.First() == "160.100.5.10"); Assert.True(expandedRangeInAllSegments.Last() == "170.120.10.20"); Assert.True(expandedAddressWithoutRange.Count == 1); Assert.True(expandedAddressWithoutRange.First() == testAddressWithoutRange); }