Ejemplo n.º 1
0
        public async Task AddEffectiveAuthorizationAsync_GrantedAndRevokedEventsForUnexistingUserContextAndWithoutTarget_ClosedIntervalIsCreatedInReadModelWithoutEnrichedPersonalInfo()
        {
            //Create a raw event
            var user = new ExternalId()
            {
                Context = "unexistingContext", Id = _userId
            };
            var permission = new Permission()
            {
                Application = "YOUFORCE", Id = "HomeAccess", Description = ""
            };
            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = user
            };

            var eaGrantedEvent = new EffectiveAuthorizationGrantedEvent()
            {
                From = _from, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now
            };
            var eaRevokedEvent = new EffectiveAuthorizationRevokedEvent()
            {
                Until = _until, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now
            };


            _eventIdList.Add(await _repository.WriteRawEventAsync(eaGrantedEvent));
            _eventIdList.Add(await _repository.WriteRawEventAsync(eaRevokedEvent));

            //Data Enrichment
            var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory();

            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationRevokedEvent), new PermissionRevokedHandler());
            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler());
            var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(_repository, eaHandlerFactory);

            var logger    = new MockInMemoryLogger();
            var prService = PersonalInfoEnrichmentServiceHelper.BuildService(logger);
            var readModel = new ReportingInMemoryStorage();

            var dataEnrichmentService = new DataEnrichmentService(eatimelineFactory, prService, readModel);

            await dataEnrichmentService.AddEffectiveAuthorizationAsync(eaRevokedEvent);

            //Assertions
            var expectedUser = new Person(user, null);
            var intervals    = readModel.GetIntervals(effectiveAuthorization).Result;

            Assert.AreEqual(1, intervals.Count);
            Assert.AreEqual(_tenantId, intervals[0].TenantId);
            Assert.AreEqual(user, intervals[0].User.Key);
            Assert.IsNull(intervals[0].User.PersonalInfo);
            Assert.AreEqual(permission, intervals[0].Permission);
            Assert.AreEqual(null, intervals[0].TargetPerson);
            Assert.AreEqual(_from, intervals[0].EffectiveInterval.Start);
            Assert.AreEqual(_until, intervals[0].EffectiveInterval.End);
        }
Ejemplo n.º 2
0
        public async Task AddEffectiveAuthorizationAsync_GrantedEventForExistingUserAndTarget_OpenIntervalIsCreatedInReadModelWithEnrichedPersonalInfo()
        {
            //Create a raw event
            var user = new ExternalId()
            {
                Context = _context, Id = _userId
            };
            var permission = new Permission()
            {
                Application = "YOUFORCE", Id = "HomeAccess", Description = "Home Access"
            };
            var target = new ExternalId()
            {
                Id = _targetId, Context = _context
            };
            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = user, Target = target
            };
            var eaEvent = new EffectiveAuthorizationGrantedEvent()
            {
                From = _from, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now
            };

            //Add event to the memory event store
            _eventIdList.Add(await _repository.WriteRawEventAsync(eaEvent));

            //Data Enrichment
            var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory();

            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler());
            var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(_repository, eaHandlerFactory);

            var logger    = new MockInMemoryLogger();
            var prService = PersonalInfoEnrichmentServiceHelper.BuildService(logger);
            var readModel = new ReportingInMemoryStorage();

            var dataEnrichmentService = new DataEnrichmentService(eatimelineFactory, prService, readModel);

            await dataEnrichmentService.AddEffectiveAuthorizationAsync(eaEvent);

            //Assertions
            var expectedUser   = new Person(user, _userPersonalInfo);
            var expectedTarget = new Person(target, _targetPersonalInfo);
            var intervals      = readModel.GetIntervals(effectiveAuthorization).Result;

            Assert.AreEqual(1, intervals.Count);
            Assert.AreEqual(_tenantId, intervals[0].TenantId);
            Assert.AreEqual(expectedUser, intervals[0].User);
            Assert.AreEqual(permission, intervals[0].Permission);
            Assert.AreEqual(expectedTarget, intervals[0].TargetPerson);
            Assert.AreEqual(_from, intervals[0].EffectiveInterval.Start);
        }