public async Task RawEventStorageRepository_GetRawEventsAsync_ExistingRevokedEvent_Returns_EffectiveAuthorizationRevokedEvent_With_Right_EffectiveAuthorization() { //Arrange: create event data to be stored var owner = new ExternalId() { Context = _ownerContext, Id = _ownerId }; var permission = new HAS.Core.Domain.Permission() { Application = _applicationName, Id = _Identifier, Description = _Identifier }; var effectiveAuthorization = new EffectiveAuthorization() { TenantId = _tenantId, Permission = permission, User = owner }; var eaEvent = new EffectiveAuthorizationRevokedEvent() { Until = _until, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now }; //Act: Attempt to write event to repository _eventIdList.Add(await _repository.WriteRawEventAsync(eaEvent)); //Act: Attempt to get nonexisting event var rawEventList = await _repository.GetRawEventsAsync(effectiveAuthorization); var revokedRawEventList = rawEventList.Where(e => e.GetType() == typeof(EffectiveAuthorizationRevokedEvent)); //Assert: check that there is a returned Id with some data Assert.IsNotNull(rawEventList); Assert.IsTrue(rawEventList.Count > 0); Assert.IsNotNull(revokedRawEventList); Assert.AreEqual(rawEventList[0].EffectiveAuthorization, effectiveAuthorization); }
public void MapEvent_DTO_EffectiveAuthorizationRevoked_Returns_Domain_EffectiveAuthorizationRevoked_With_Valid_Values() { //Arrange var dtoEffectiveAuthorizationRevokedEvent = new EffectiveAuthorizationRevokedEvent(); dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization = new EffectiveAuthorization(string1, new ExternalId(string2, string3), new Permission(string4, string5, string6), new ExternalId(string7, string8)); dtoEffectiveAuthorizationRevokedEvent.UntilDateTime = referenceDateTime; //Act var domainEffectiveAuthorizationRevokedEvent = DomainAdapter.MapEvent(dtoEffectiveAuthorizationRevokedEvent); //Assert Assert.IsNotNull(domainEffectiveAuthorizationRevokedEvent); Assert.IsNotNull(domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.UntilDateTime, domainEffectiveAuthorizationRevokedEvent.Until); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.TenantId, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.TenantId); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Permission.Application, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Permission.Application); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Permission.Description, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Permission.Description); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Permission.Id, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Permission.Id); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Target.Context, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Target.Context); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Target.Id, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.Target.Id); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.User.Context, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.User.Context); Assert.AreEqual(dtoEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.User.Id, domainEffectiveAuthorizationRevokedEvent.EffectiveAuthorization.User.Id); }
public async Task RawEventStorageRepository_WriteRawEventAsync_OnSuccessfulWritingRevokedEvent_Returns_Event_Id() { //Arrange: create event data to be stored var owner = new ExternalId() { Context = _ownerContext, Id = _ownerId }; var permission = new HAS.Core.Domain.Permission() { Application = _applicationName, Id = _Identifier, Description = _Identifier }; var effectiveAuthorization = new EffectiveAuthorization() { TenantId = _tenantId, Permission = permission, User = owner }; var eaEvent = new EffectiveAuthorizationRevokedEvent() { Until = _until, EffectiveAuthorization = effectiveAuthorization, DateCreated = DateTime.Now }; //Act: Attempt to write event to repository _eventIdList.Add(await _repository.WriteRawEventAsync(eaEvent)); //Assert: check that there is a returned Id with some data Assert.IsNotNull(_eventIdList[0]); Assert.IsTrue(_eventIdList[0].Length > 0); }
public static Core.Domain.EffectiveAuthorizationRevokedEvent MapEvent(EffectiveAuthorizationRevokedEvent dtoEvent) { return(new Core.Domain.EffectiveAuthorizationRevokedEvent() { EffectiveAuthorization = MapEffectiveAuthorization(dtoEvent.EffectiveAuthorization), DateCreated = DateTime.UtcNow, Until = dtoEvent.UntilDateTime.Value }); }
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); }
public async Task <IActionResult> LogEffectiveAutorizationRevokedEvent([FromBody] EffectiveAuthorizationRevokedEvent eAEvent) { var innerEvent = DomainAdapter.MapEvent(eAEvent); var id = await _effectiveAuthorizationLogging.AddAuthLogAsync(innerEvent); eAEvent.SetId(id); return(Created("EffectiveAuthorizationRevoked", eAEvent)); }
public async Task <IEventPushResponse> PushEffectiveAuthorizationRevokedAsync(EffectiveAuthorization authorization, DateTime effectiveDate) { ValidateContent(authorization); var eventToPush = new EffectiveAuthorizationRevokedEvent() { UntilDateTime = effectiveDate, EffectiveAuthorization = authorization }; return(await _eventPusher.PushRevokedAsync(eventToPush)); }
public IEventPushResponse PushEffectiveAuthorizationRevoked(EffectiveAuthorization authorization, DateTime effectiveDate) { ValidateContent(authorization); var eventToPush = new EffectiveAuthorizationRevokedEvent() { UntilDateTime = effectiveDate, EffectiveAuthorization = authorization }; return(_eventPusher.PushRevoked(eventToPush)); }
public async Task TestHappyFlow() { // Configure system and DI var serviceCollection = new ServiceCollection(); var appStartup = new MockAppStartupFactory("hybrid").GetAppStartup(); appStartup.ConfigureServices(serviceCollection, null); var provider = serviceCollection.BuildServiceProvider(); appStartup.ConfigureStartup(provider); var effAuthzLogginService = provider.GetService <IEffectiveAuthorizationLogging>(); var grantTime1 = DateTime.UtcNow - TimeSpan.FromDays(4); var revokeTime1 = DateTime.UtcNow - TimeSpan.FromDays(3); var grantTime2 = DateTime.UtcNow - TimeSpan.FromDays(1); var revokeTime2 = DateTime.UtcNow; var effectiveAuthorization = new EffectiveAuthorization { User = new ExternalId { Context = "Youforce", Id = "IC000001" }, Target = new ExternalId { Context = "Youforce", Id = "IC000002" }, TenantId = "tenant1", Permission = new Permission { Application = "A1", Id = "p1" } }; var effAuthzGrantedEvent = new EffectiveAuthorizationGrantedEvent { EffectiveAuthorization = effectiveAuthorization, From = grantTime1 }; var effAuthzRevokedEvent = new EffectiveAuthorizationRevokedEvent { EffectiveAuthorization = effectiveAuthorization, Until = revokeTime1 }; await effAuthzLogginService.AddAuthLogAsync(effAuthzGrantedEvent); await effAuthzLogginService.AddAuthLogAsync(effAuthzRevokedEvent); var effAuthzGrantedEvent2 = new EffectiveAuthorizationGrantedEvent { EffectiveAuthorization = effectiveAuthorization, From = grantTime2 }; var effAuthzRevokedEvent2 = new EffectiveAuthorizationRevokedEvent { EffectiveAuthorization = effectiveAuthorization, Until = revokeTime2 }; await effAuthzLogginService.AddAuthLogAsync(effAuthzGrantedEvent2); await effAuthzLogginService.AddAuthLogAsync(effAuthzRevokedEvent2); // Retrieve data var reportStore = provider.GetService <IReportingStorage>(); var eventStorage = provider.GetService <IReadRawEventStorage>(); var intervals = await reportStore.GetIntervals(effectiveAuthorization); var events = await eventStorage.GetRawEventsAsync(effectiveAuthorization); Assert.AreEqual(4, events.Count); Assert.AreEqual(2, intervals.Count); // Assert on interval correctnes var interval = intervals.Single(i => i.EffectiveInterval.Start == grantTime1); Assert.AreEqual(revokeTime1, interval.EffectiveInterval.End); interval = intervals.Single(i => i.EffectiveInterval.Start == grantTime2); Assert.AreEqual(revokeTime2, interval.EffectiveInterval.End); }