コード例 #1
0
        public BrandIpRegulation UpdateIpRegulation(EditBrandIpRegulationData data)
        {
            var regulation = Repository.BrandIpRegulations.SingleOrDefault(ip => ip.Id == data.Id);
            var brand      = Repository.Brands.Single(x => x.Id == data.BrandId);

            if (regulation == null)
            {
                throw new RegoException("User does not exist");
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                regulation.LicenseeId     = data.LicenseeId;
                regulation.BrandId        = data.BrandId;
                regulation.IpAddress      = data.IpAddress;
                regulation.Description    = data.Description;
                regulation.BlockingType   = data.BlockingType;
                regulation.RedirectionUrl = data.RedirectionUrl;

                regulation.UpdatedBy   = Repository.Admins.SingleOrDefault(u => u.Id == ActorInfoProvider.Actor.Id);
                regulation.UpdatedDate = DateTimeOffset.Now.ToBrandOffset(brand.TimeZoneId);

                Repository.SaveChanges();

                _eventBus.Publish(new BrandIpRegulationUpdated(regulation)
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimeZoneId),
                });
                scope.Complete();
            }

            return(regulation);
        }
コード例 #2
0
        public void Can_update_brand_ip_regulation()
        {
            /*** Arrange ***/
            var ipAddress = TestDataGenerator.GetRandomIpAddress();

            const string redirectionUrl = "google.com";

            var brandIpRegulation = new AddBrandIpRegulationData
            {
                IpAddress  = ipAddress,
                BrandId    = Brand.Id,
                LicenseeId = Brand.LicenseeId,
                // Ip address is blocked with redirection to specified Url
                BlockingType   = IpRegulationConstants.BlockingTypes.Redirection,
                RedirectionUrl = redirectionUrl
            };

            _brandService.CreateIpRegulation(brandIpRegulation);

            var regulation      = _brandService.GetIpRegulations().SingleOrDefault(ip => ip.IpAddress == ipAddress);
            var editIpAddress   = TestDataGenerator.GetRandomIpAddress();
            var editDescription = TestDataGenerator.GetRandomString(20);

            var editData = new EditBrandIpRegulationData
            {
                Id           = regulation.Id,
                LicenseeId   = Brand.LicenseeId,
                BrandId      = Brand.Id,
                IpAddress    = editIpAddress,
                Description  = editDescription,
                BlockingType = IpRegulationConstants.BlockingTypes.LoginRegistration
            };

            /*** Act ***/
            _brandService.UpdateIpRegulation(editData);

            /*** Assert ***/
            var updatedRegulation = _brandService.GetIpRegulations().SingleOrDefault(ip => ip.IpAddress == editIpAddress);

            Assert.IsNotNull(updatedRegulation);
            Assert.AreEqual(updatedRegulation.IpAddress, editIpAddress);
            Assert.AreEqual(updatedRegulation.Description, editDescription);
            Assert.AreEqual(updatedRegulation.BlockingType, IpRegulationConstants.BlockingTypes.LoginRegistration);
        }
コード例 #3
0
        public void Cannot_update_brand_ip_regulation_without_permissions()
        {
            /*** Arrange ***/
            // Create role and user that has permission to update IP regulation
            var sufficientPermissions = new List <PermissionData>
            {
                SecurityTestHelper.GetPermission(Permissions.Update, Modules.BrandIpRegulationManager)
            };
            var roleWithPermission = SecurityTestHelper.CreateRole(permissions: sufficientPermissions);
            var userWithPermission = SecurityTestHelper.CreateAdmin(roleId: roleWithPermission.Id);

            // Create role and user that has permission only to view IP regulations not to update ones
            var insufficientPermissions = new List <PermissionData>
            {
                SecurityTestHelper.GetPermission(Permissions.View, Modules.BrandIpRegulationManager)
            };
            var roleWithoutPermission = SecurityTestHelper.CreateRole(permissions: insufficientPermissions);
            var userWithoutPermission = SecurityTestHelper.CreateAdmin(roleId: roleWithoutPermission.Id);

            var ipAddress = TestDataGenerator.GetRandomIpAddress();

            const string redirectionUrl = "google.com";

            var brandIpRegulation = new AddBrandIpRegulationData
            {
                IpAddress = ipAddress,
                BrandId   = Brand.Id,
                // Ip address is blocked with redirection to specified Url
                BlockingType   = IpRegulationConstants.BlockingTypes.Redirection,
                RedirectionUrl = redirectionUrl
            };

            _brandService.CreateIpRegulation(brandIpRegulation);

            var regulation      = _brandService.GetIpRegulations().SingleOrDefault(ip => ip.IpAddress == ipAddress);
            var editIpAddress   = TestDataGenerator.GetRandomIpAddress();
            var editDescription = TestDataGenerator.GetRandomString(20);

            var editData = new EditBrandIpRegulationData
            {
                Id           = regulation.Id,
                BrandId      = Brand.Id,
                IpAddress    = editIpAddress,
                Description  = editDescription,
                BlockingType = IpRegulationConstants.BlockingTypes.LoginRegistration
            };

            /*** Act ***/
            // Signin user that has sufficient permissions to update brand IP regulation
            SecurityTestHelper.SignInAdmin(userWithPermission);
            // Check that method UpdateIpRegulation doesn't throw InsufficientPermissionsException
            Assert.DoesNotThrow(
                () => _brandService.UpdateIpRegulation(editData));


            // Signin user that has insufficient permissions to update brand IP regulation
            SecurityTestHelper.SignInAdmin(userWithoutPermission);
            // Check that method UpdateIpRegulation throws InsufficientPermissionsException
            Assert.Throws <InsufficientPermissionsException>(
                () => _brandService.UpdateIpRegulation(editData));
        }