Beispiel #1
0
        public async Task AddEffectiveAuthorizationAsync_Event_Stored_With_Invalid_Authorization_No_Permission_Throws_NullReferenceException()
        {
            //Arrange
            var eaEventsStorate = new RawEventInMemoryStorage();

            var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory();

            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler());

            var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(eaEventsStorate, eaHandlerFactory);

            var prService = new PersonalInfoEnrichmentService(new MockPersonalLocalStorage(), new MockPersonalInfoExternalServiceFactory(), new MockInMemoryLogger());
            var rpStorage = new ReportingInMemoryStorage();

            var permission = new Permission()
            {
                Application = _defaultApplication, Id = _defaultPermissionId, Description = _defaultDescription
            };
            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission
            };
            var eaEvent = new EffectiveAuthorizationGrantedEvent()
            {
                From = new DateTime(2018, 1, 1), EffectiveAuthorization = effectiveAuthorization
            };

            await eaEventsStorate.WriteRawEventAsync(eaEvent); //event needs to be previously writteng to storage.

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

            //Act & Assert
            await Assert.ThrowsExceptionAsync <NullReferenceException>(() => dataEnrichmentService.AddEffectiveAuthorizationAsync(eaEvent));
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public async Task AddEffectiveAuthorizationAsync_Event_Stored_With_Valid_Authorization_Without_Target_Stores_Correct_Information()
        {
            //Arrange
            var eaEventsStorate = new RawEventInMemoryStorage();

            var eaHandlerFactory = new EffectiveAuthorizationHandlerFactory();

            eaHandlerFactory.RegisterHandler(typeof(EffectiveAuthorizationGrantedEvent), new PermissionGrantedHandler());

            var eatimelineFactory = new EffectiveAuthorizationTimelineFactory(eaEventsStorate, eaHandlerFactory);

            var prService = new PersonalInfoEnrichmentService(new MockPersonalLocalStorage(), new MockPersonalInfoExternalServiceFactory(), new MockInMemoryLogger());

            var rpStorage = new ReportingInMemoryStorage();
            var owner     = new ExternalId()
            {
                Id = _defaultId, Context = _defaultContext
            };
            var permission = new Permission()
            {
                Application = _defaultApplication, Id = _defaultPermissionId, Description = _defaultDescription
            };
            var effectiveAuthorization = new EffectiveAuthorization()
            {
                TenantId = _tenantId, Permission = permission, User = owner
            };
            var eaEvent = new EffectiveAuthorizationGrantedEvent()
            {
                From = new DateTime(2018, 1, 1), EffectiveAuthorization = effectiveAuthorization
            };

            await eaEventsStorate.WriteRawEventAsync(eaEvent); //event needs to be previously writteng to storage.

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

            //Act
            await dataEnrichmentService.AddEffectiveAuthorizationAsync(eaEvent);

            var intervals = await rpStorage.GetIntervals(effectiveAuthorization);

            //Assert
            Assert.AreEqual(1, intervals.Count);
            Assert.AreEqual(_tenantId, intervals[0].TenantId);
            Assert.AreEqual(owner, intervals[0].User.Key);
            Assert.AreEqual(permission, intervals[0].Permission);
            Assert.AreEqual(null, intervals[0].TargetPerson);
        }