public async Task Upload_Editor_NotFoundIfClientNotFound() { var json = "{}"; var testContext = TestHttpContextBuilder.CreateForPath($"/Editor/{notFoundClientId}/{nameof(SampleConfig)}") .WithClaims(configuratorClaim, clientConfiguratorClaim) .WithPost() .WithStringBody(json) .TestContext; await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildNotFoundStatusResponse(testContext)); }
public async Task Post_ClientResource_UploadsResources() { var resourceName = "File.txt"; var file = new MemoryStream(); var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{resourceName}") .WithPost() .WithClaims(configuratorClaim, clientConfiguratorClaim) .WithFile(file, resourceName) .TestContext; await target.Handle(testContext, option); resourceStore.Verify(r => r.UpdateResource(It.Is <UpdateResourceRequest>(a => a.Identity.Client.Equals(expectedClient) && a.Name == resourceName && file == a.Content))); httpResponseFactory.Verify(f => f.BuildNoContentResponse(testContext)); }
public async Task Delete_Returns403_IfNoConfiguratorClaim() { var resourceName = "File.txt"; var file = new MemoryStream(); var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{resourceName}") .WithPost() .WithClaims(clientConfiguratorClaim) .WithFile(file, resourceName) .TestContext; await target.Handle(testContext, option); resourceStore.Verify(r => r.UpdateResource(It.IsAny <UpdateResourceRequest>()), Times.Never); httpResponseFactory.Verify(f => f.BuildStatusResponse(testContext, 403)); }
public async Task CallsResponseFactoryWithConfig_WhenUserHasReadClaim() { var claimValue = "ClientOne"; clients[0].ReadClaim = claimValue; var readClaim = GetReadClaim(claimValue); var context = TestHttpContextBuilder.CreateForPath($"/{clients[0].ClientId}/{nameof(SimpleConfig)}") .WithClaims(readClaim) .TestContext; await target.Handle(context, options); responseFactory.Verify(r => r.BuildJsonResponse(context, It.IsAny <object>()), Times.AtLeastOnce()); }
public async Task Get_Group_ReturnsNotFoundIfGroupNotFound() { var group = new ConfigurationClientGroup { GroupId = groupId }; configurationClientService.Setup(s => s.GetClientGroupOrDefault(groupId)) .ReturnsAsync(() => null); var context = TestHttpContextBuilder.CreateForPath($"/{groupId}") .WithClaims(readClaim).TestContext; await target.Handle(context, options); factory.Verify(f => f.BuildNotFoundStatusResponse(context)); }
public async Task Delete_ReturnsForbiddenIFNoConfiguratorClaim() { var id = "3E37AC18-A00F-47A5-B84E-C29E0823F6D8"; var context = TestHttpContextBuilder.CreateForPath($"/{id}") .WithDelete() .WithClaims() .TestContext; var commandResult = CommandResult.Success(); await target.Handle(context, options); commandBus.Verify(cb => cb.SubmitAsync(It.IsAny <DeleteSnapshotCommand>()), Times.Never); httpResponseFactory.Verify(f => f.BuildStatusResponse(context, 403)); }
public async Task Get_Returns403_IfNoClaim() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{nameof(SampleConfigSet)}/{nameof(SampleConfig)}.json") .WithClaims() .TestContext; var configSet = new SampleConfigSet { SampleConfig = new Config <SampleConfig>(new SampleConfig { LlamaCapacity = 23 }) }; await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildStatusResponse(testContext, 403)); }
public async Task Upload_Config_NotFoundIfClientNotFound() { var json = "{}"; var testContext = TestHttpContextBuilder.CreateForPath($"/Configuration/{notFoundClientId}/{nameof(SampleConfig)}") .WithClaims(configuratorClaim, clientConfiguratorClaim) .WithPost() .WithStringBody(json) .TestContext; await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildNotFoundStatusResponse(testContext)); commandBus.Verify(cb => cb.SubmitAsync(It.IsAny <UpdateConfigurationFromJsonUploadCommand>()), Times.Never); }
public async Task Upload_Returns403_IfNoClaimWithoutClientConfiguratorClaim() { var json = "{}"; var testContext = TestHttpContextBuilder.CreateForPath($"/ConfigurationSet/{clientId}/{nameof(SampleConfigSet)}") .WithClaims(configuratorClaim) .WithPost() .WithStringBody(json) .TestContext; var commandResult = CommandResult.Success(); await target.Handle(testContext, option); commandBus.Verify(cb => cb.SubmitAsync(It.IsAny <UpdateConfigurationSetFromJsonUploadCommand>()), Times.Never); responseFactory.Verify(f => f.BuildStatusResponse(testContext, 403)); }
public async Task Upload_ConfigSet_RaiseUploadSetCommand() { var json = "{}"; var testContext = TestHttpContextBuilder.CreateForPath($"/ConfigurationSet/{clientId}/{nameof(SampleConfigSet)}") .WithClaims(configuratorClaim, clientConfiguratorClaim) .WithPost() .WithStringBody(json) .TestContext; var commandResult = CommandResult.Success(); commandBus.Setup(cb => cb.SubmitAsync(It.Is <UpdateConfigurationSetFromJsonUploadCommand>(c => c.ConfigurationSetType == typeof(SampleConfigSet) && c.JsonUpload == json && c.Identity.Client.Equals(expectedClient)))) .ReturnsAsync(() => commandResult); await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildResponseFromCommandResult(testContext, commandResult)); }
public async Task Get_ReturnsConfigurationEditModelForClient() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{typeof(SampleConfig).Name}").WithClaims(readClaim).TestContext; var configInstance = new ConfigInstance <SampleConfig>(new SampleConfig(), new ConfigurationIdentity(expectedClient, new Version(1, 0))); configInstanceRouter.Setup(r => r.GetConfigInstanceOrDefault(expectedClient, typeof(SampleConfig).Name)) .ReturnsAsync(() => configInstance); var mappedModel = new object(); configurationEditModelMapper.Setup(m => m.MapToEditConfig(configInstance, (configCollection.GetConfigDefinition(typeof(SampleConfig))))) .Returns(() => mappedModel); await target.Handle(testContext, options); responseFactory.Verify(v => v.BuildJsonResponse(testContext, mappedModel)); }
public async Task Post_Returns403IfNoConfiguratorClaimOnClient() { expectedClient.ConfiguratorClaim = "Denied"; var stringValue = "Hello"; var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{typeof(SampleConfig).Name}") .WithClaims(readClaim) .WithPost() .WithStringBody(stringValue) .TestContext; await target.Handle(testContext, options); commandBus.Verify(c => c.SubmitAsync(It.IsAny <UpdateConfigurationFromEditorCommand>()), Times.Never); responseFactory.Verify(v => v.BuildStatusResponse(testContext, 403)); }
public async Task Post_Returns401IfUserNotAuthenticated() { var group = new ConfigurationClientGroup { GroupId = groupId }; var commandResult = CommandResult.Success(); var context = TestHttpContextBuilder.CreateForPath("/") .WithPost() .WithJsonBody(group) .TestContext; await target.Handle(context, options); commandBus.Verify(f => f.SubmitAsync(It.IsAny <CreateUpdateClientGroupCommand>()), Times.Never); factory.Verify(f => f.BuildStatusResponse(context, 401)); }
public async Task Post_CallsCommandBus() { var group = new ConfigurationClientGroup { GroupId = groupId }; var context = TestHttpContextBuilder.CreateForPath("/") .WithClaims(writeClaim) .WithPost() .WithJsonBody(group) .TestContext; await target.Handle(context, options); commandBus.Verify(f => f.SubmitAsync(It.Is <CreateUpdateClientGroupCommand>(c => c.ClientGroup.GroupId == group.GroupId))); }
public async Task Get_ClientArchiveResource_ReturnsNotFoundIfNotFound() { var resourceName = "File.txt"; var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{resourceName}") .WithClaims(readClaim, new Claim(options.ClientConfiguratorClaimType, configuratorClaim)) .TestContext; var expectedResource = new ResourceEntry { HasEntry = false }; resourceStore.Setup(r => r.GetArchiveResource(resourceName, It.Is <ConfigurationIdentity>(s => s.Client.Equals(expectedClient)))) .ReturnsAsync(() => expectedResource); await target.Handle(testContext, options); httpResponseFactory.Verify(f => f.BuildNotFoundStatusResponse(testContext)); }
public async Task Delete_RaisesCommand() { var id = "3E37AC18-A00F-47A5-B84E-C29E0823F6D8"; var context = TestHttpContextBuilder.CreateForPath($"/{id}") .WithDelete() .WithClaims(configuratorClaim) .TestContext; var commandResult = CommandResult.Success(); commandBus.Setup(cb => cb.SubmitAsync <DeleteSnapshotCommand>(It.Is <DeleteSnapshotCommand>(s => s.SnapshotId == id))) .ReturnsAsync(commandResult); await target.Handle(context, options); httpResponseFactory.Verify(f => f.BuildResponseFromCommandResult(context, commandResult)); }
public async Task CallsResponseFactoryWithConfig() { var context = TestHttpContextBuilder.CreateForPath($"/{clients[0].ClientId}/{nameof(SimpleConfig)}") .WithClaims() .TestContext; var config = new ConfigInstance <SimpleConfig>(new SimpleConfig { IntProperty = 43 }, new ConfigurationIdentity(clients[0], new Version(1, 0))); configurationService.Setup(r => r.GetAsync(typeof(SimpleConfig), It.Is <ConfigurationIdentity>(arg => arg.Client.ClientId == clients[0].ClientId))).ReturnsAsync(config); responseFactory.Setup(r => r.BuildJsonResponse(context, config.Configuration)) .Returns(Task.FromResult(true)); await target.Handle(context, options); responseFactory.Verify(r => r.BuildJsonResponse(context, config.Configuration), Times.AtLeastOnce()); }
public async Task Post_ReturnsCommandResultFromBus() { var stringValue = "Hello"; var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{typeof(SampleConfig).Name}") .WithClaims(readClaim) .WithPost() .WithStringBody(stringValue) .TestContext; var commandResult = CommandResult.Success(); commandBus.Setup(c => c.SubmitAsync(It.Is <UpdateConfigurationFromEditorCommand>(command => command.Identity.Client.Equals(expectedClient) && command.ConfigurationType == typeof(SampleConfig) && command.ConfigurationAsJson == stringValue))) .ReturnsAsync(() => commandResult); await target.Handle(testContext, options); responseFactory.Verify(v => v.BuildResponseFromCommandResult(testContext, commandResult)); }
public async Task Upload_Editor_ReturnsMappedConfig() { var json = "{}"; var testContext = TestHttpContextBuilder.CreateForPath($"/Editor/{clientId}/{nameof(SampleConfig)}") .WithClaims(configuratorClaim, clientConfiguratorClaim) .WithPost() .WithStringBody(json) .TestContext; var result = new Object(); uploadToEditorMapper.Setup(mapper => mapper.MapUploadToEditModel(json, It.Is <ConfigurationIdentity>(c => c.Client.Equals(expectedClient)), configCollection.GetConfigDefinition <SampleConfig>())) .Returns(result); await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildJsonResponse(testContext, result)); }
public async Task Get_ClientArchiveResource_ReturnsNotFoundIfNotFound() { var archivedConfig = "SampleConfig_123454.json"; var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{archivedConfig}") .WithClaims(readClaim) .TestContext; var expectedResource = new ConfigArchiveEntry { HasEntry = false }; configArchive.Setup(r => r.GetArchiveConfig(archivedConfig, It.Is <ConfigurationIdentity>(s => s.Client.Equals(expectedClient)))) .ReturnsAsync(() => expectedResource); await target.Handle(testContext, options); httpResponseFactory.Verify(f => f.BuildNotFoundStatusResponse(testContext)); }
public async Task Post_ReturnsForbiddenIFNoConfiguratorClaim() { var command = new CreateSnapshotCommand { Name = "1.0.0", ClientId = "3E37AC18-A00F-47A5-B84E-C29E0823F6D8" }; var context = TestHttpContextBuilder.CreateForPath($"/") .WithPost() .WithJsonBody <CreateSnapshotCommand>(command) .WithClaims() .TestContext; var commandResult = CommandResult.Success(); await target.Handle(context, options); commandBus.Verify(cb => cb.SubmitAsync <CreateSnapshotCommand>(It.IsAny <CreateSnapshotCommand>()), Times.Never); httpResponseFactory.Verify(f => f.BuildStatusResponse(context, 403)); }
public async Task Get_ClientResource_ReturnsNotFoundIfNotFound() { var resourceName = "File.txt"; var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{resourceName}") .WithClaims(clientReadClaim) .TestContext; var expectedResource = new ResourceEntry { HasEntry = false }; resourceStore.Setup(r => r.GetResource(resourceName, ItMatchesClient(expectedClient))) .ReturnsAsync(() => expectedResource); await target.Handle(testContext, option); httpResponseFactory.Verify(f => f.BuildNotFoundStatusResponse(testContext)); }
public async Task Get_ClientId_Returns403_IfFoundButNoClaim() { var client = new ConfigurationClient { ClientId = clientId, ConfiguratorClaim = "RequiredClaim", }; configurationClientService.Setup(cs => cs.GetClientOrDefault(clientId)) .ReturnsAsync(() => client); var context = TestHttpContextBuilder.CreateForPath($"/{clientId}") .WithClaims(readClaim).TestContext; await target.Handle(context, options); factory.Verify(f => f.BuildStatusResponse(context, 403)); }
public async Task Get_ClientSummary_GetsClientSummary() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}") .WithClaims(clientConfiguratorClaim) .TestContext; var expectedResources = new List <ResourceEntryInfo> { new ResourceEntryInfo { Name = "File.txt" } }; resourceStore.Setup(r => r.GetResourceCatalogue(ItMatchesClient(expectedClient))) .ReturnsAsync(() => expectedResources); await target.Handle(testContext, option); httpResponseFactory.Verify(f => f.BuildJsonResponse(testContext, expectedResources)); }
public async Task Get_GetsAllGroups() { var groups = new List <ConfigurationClientGroup> { new ConfigurationClientGroup { GroupId = groupId } }; configurationClientService.Setup(s => s.GetGroups()) .ReturnsAsync(() => groups); var context = TestHttpContextBuilder.CreateForPath("/") .WithClaims(readClaim).TestContext; await target.Handle(context, options); factory.Verify(f => f.BuildJsonResponse(context, groups)); }
public async Task Get_ClientArchiveSummary_GetsClientSummary_WithAdmin() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}") .WithClaims(writeClaim) .TestContext; var expectedResources = new List <ResourceEntryInfo> { new ResourceEntryInfo { Name = "File.txt" } }; resourceStore.Setup(r => r.GetArchiveResourceCatalogue(It.Is <ConfigurationIdentity>(s => s.Client.Equals(expectedClient)))) .ReturnsAsync(() => expectedResources); await target.Handle(testContext, options); httpResponseFactory.Verify(f => f.BuildJsonResponse(testContext, expectedResources)); }
public async Task Get_GetsConfigAsJsonFile() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{nameof(SampleConfigSet)}/{nameof(SampleConfig)}.json") .WithClaims(readClaim) .TestContext; var configSet = new SampleConfigSet { SampleConfig = new Config <SampleConfig>(new SampleConfig { LlamaCapacity = 23 }) }; configurationSetService.Setup(s => s.GetConfigurationSet(typeof(SampleConfigSet), It.Is <ConfigurationIdentity>(i => i.Client.Equals(expectedClient)))) .ReturnsAsync(() => configSet); await target.Handle(testContext, option); responseFactory.Verify(f => f.BuildJsonFileResponse(testContext, configSet.SampleConfig.Value, $"{nameof(SampleConfig)}.json")); }
public async Task Get_Returns403_IfNoClaim() { var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}") .WithClaims() .TestContext; var expectedResources = new List <ConfigArchiveEntryInfo> { new ConfigArchiveEntryInfo { Name = "SampleConfig_123454.json" } }; configArchive.Setup(r => r.GetArchiveConfigCatalogue(It.Is <ConfigurationIdentity>(s => s.Client.Equals(expectedClient)))) .ReturnsAsync(() => expectedResources); await target.Handle(testContext, options); httpResponseFactory.Verify(f => f.BuildStatusResponse(testContext, 403)); }
public async Task CorrectlyMapsClientClaim() { var context = TestHttpContextBuilder.CreateForPath($"/{clientId}") .WithClaims(writeClientAdminClaim) .TestContext; UserClientPermissions permission = null; factory.Setup(f => f.BuildJsonResponse(context, It.IsAny <UserClientPermissions>())) .Returns((HttpContext c, UserClientPermissions p) => { permission = p; return(Task.FromResult(true)); }); await target.Handle(context, options); Assert.NotNull(permission); Assert.False(permission.HasClientConfiguratorClaim); }
public async Task Get_ClientArchiveResource_GetsClientResource() { var archivedConfig = "SampleConfig_123454.json"; var testContext = TestHttpContextBuilder.CreateForPath($"/{clientId}/{archivedConfig}") .WithClaims(readClaim) .TestContext; var expectedResource = new ConfigArchiveEntry { HasEntry = true, Content = "JsonString", Name = archivedConfig }; configArchive.Setup(r => r.GetArchiveConfig(archivedConfig, It.Is <ConfigurationIdentity>(s => s.Client.Equals(expectedClient)))) .ReturnsAsync(() => expectedResource); await target.Handle(testContext, options); httpResponseFactory.Verify(f => f.BuildJsonFileResponse(testContext, expectedResource.Content, expectedResource.Name)); }