public VerifyIpResponse VerifyIp(VerifyIpRequest request) { var brand = _brands.Brands.SingleOrDefault(b => b.Code == request.BrandName); if (brand == null) { throw new RegoValidationException(ErrorMessagesEnum.InvalidBrandCode.ToString()); } Core.Security.Data.IpRegulations.VerifyIpResult result; try { result = _regulations.VerifyIpAddress(request.IpAddress, brand.Id); } catch (FormatException) { throw new RegoValidationException(ErrorMessagesEnum.InvalidIpAddress.ToString()); } var verifyIpResult = Mapper.Map <VerifyIpResult>(result); return(new VerifyIpResponse(verifyIpResult)); }
public void Can_verify_ip_address_range_lower_and_upper_bounds_for_brand_website() { // *** Arrange *** const string ipAddressRange = "192.168.5.10-20"; var brandIpRegulation = new AddBrandIpRegulationData { IpAddress = ipAddressRange, BrandId = Brand.Id }; _brandService.CreateIpRegulation(brandIpRegulation); // *** Act *** var isLowerBoundBlocked = !_brandService.VerifyIpAddress("192.168.5.10").Allowed; var isUpperBoundBlocked = !_brandService.VerifyIpAddress("192.168.5.20").Allowed; // *** Assert *** Assert.True(isLowerBoundBlocked); Assert.True(isUpperBoundBlocked); }