public async Task WillUseDefaultNetworkCredentialsWhenServerRequiresAuthentication_CommandsUsage() { var server = CreateServer(8079, fileSystemName: "WillUseDefaultCredentials", enableAuthentication: true); // enable authentication using (var client = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "WillUseDefaultCredentials")) { await client.Admin.CreateFileSystemAsync(new FileSystemDocument() { Id = "Raven/FileSystem/" + client.FileSystemName, Settings = { {Constants.FileSystem.DataDirectory, Path.Combine("FileSystems", client.FileSystemName)} } }); await client.UploadAsync("a", new MemoryStream(new byte[] { 1, 2 })); await client.UploadAsync("b", new MemoryStream(new byte[] { 2, 1, 0 })); var ms = new MemoryStream(); (await client.DownloadAsync("a")).CopyTo(ms); var array = ms.ToArray(); Assert.Equal(1, array[0]); Assert.Equal(2, array[1]); ms = new MemoryStream(); (await client.DownloadAsync("b")).CopyTo(ms); array = ms.ToArray(); Assert.Equal(2, array[0]); Assert.Equal(1, array[1]); Assert.Equal(0, array[2]); } }
public async Task WillUseDefaultNetworkCredentialsWhenServerRequiresAuthentication_CommandsUsage() { var server = CreateServer(8079, fileSystemName: "WillUseDefaultCredentials", enableAuthentication: true); // enable authentication using (var client = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "WillUseDefaultCredentials")) { await client.Admin.CreateFileSystemAsync(new FileSystemDocument() { Id = "Raven/FileSystem/" + client.FileSystemName, Settings = { { Constants.FileSystem.DataDirectory, Path.Combine("FileSystems", client.FileSystemName) } } }); await client.UploadAsync("a", new MemoryStream(new byte[] { 1, 2 })); await client.UploadAsync("b", new MemoryStream(new byte[] { 2, 1, 0 })); var ms = new MemoryStream(); (await client.DownloadAsync("a")).CopyTo(ms); var array = ms.ToArray(); Assert.Equal(1, array[0]); Assert.Equal(2, array[1]); ms = new MemoryStream(); (await client.DownloadAsync("b")).CopyTo(ms); array = ms.ToArray(); Assert.Equal(2, array[0]); Assert.Equal(1, array[1]); Assert.Equal(0, array[2]); } }
public async Task AdminClientWorkWithWinAuthEnabled() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(enableAuthentication: true, credentials: new NetworkCredential(FactIfWindowsAuthenticationIsAvailable.Admin.UserName, FactIfWindowsAuthenticationIsAvailable.Admin.Password, FactIfWindowsAuthenticationIsAvailable.Admin.Domain)); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(MultiDatabase.CreateFileSystemDocument("testName"), "testName"); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName", new NetworkCredential(FactIfWindowsAuthenticationIsAvailable.Admin.UserName, FactIfWindowsAuthenticationIsAvailable.Admin.Password, FactIfWindowsAuthenticationIsAvailable.Admin.Domain))) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } var names = await adminClient.GetNamesAsync(); Assert.Contains("testName", names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == "testName")); await adminClient.DeleteFileSystemAsync("testName"); names = await adminClient.GetNamesAsync(); Assert.DoesNotContain("testName", names); }
public async Task ShouldThrowWhenWindowsDocumentDoesNotContainFileSystem() { // in this test be careful if the specified credentials belong to admin user or not // to make this test pass you need to specify the credentials of a user who isn't an admin on this machine var client = NewAsyncClient(enableAuthentication: true, credentials: new NetworkCredential(FactIfWindowsAuthenticationIsAvailable.User.UserName, FactIfWindowsAuthenticationIsAvailable.User.Password, FactIfWindowsAuthenticationIsAvailable.User.Domain)); var server = GetServer(); await client.UploadAsync("abc.bin", new MemoryStream(1)); using (var anotherClient = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_WindowsDocumentDoesNotContainsThisFS", conventions: client.Conventions, credentials: new OperationCredentials(null, new NetworkCredential(FactIfWindowsAuthenticationIsAvailable.User.UserName, FactIfWindowsAuthenticationIsAvailable.User.Password, FactIfWindowsAuthenticationIsAvailable.User.Domain)))) { await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database ErrorResponseException errorResponse = null; try { await anotherClient.UploadAsync("def.bin", new MemoryStream(1)); // should throw because a file system ShouldThrow_WindowsDocumentDoesNotContainsThisFS isn't added to ApiKeyDefinition } catch (ErrorResponseException ex) { errorResponse = ex; } Assert.NotNull(errorResponse); Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode); } }
public async Task ShouldThrowWhenWindowsDocumentDoesNotContainFileSystem() { // in this test be careful if the specified credentials belong to admin user or not var client = NewAsyncClient(enableAuthentication: true, credentials: new NetworkCredential(username, password, domain)); var server = GetServer(); await client.UploadAsync("abc.bin", new RandomStream(3)); using (var anotherClient = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_WindowsDocumentDoesnContainsThisFS", credentials: new NetworkCredential(username, password, domain))) { await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database ErrorResponseException errorResponse = null; try { await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition } catch (InvalidOperationException ex) { errorResponse = ex.InnerException as ErrorResponseException; } Assert.NotNull(errorResponse); Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode); } }
public async Task AdminClientWorkWithWinAuthEnabled() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(enableAuthentication: true, credentials: new NetworkCredential(username, password, domain)); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(new FileSystemDocument { Id = "Raven/FileSystem/" + "testName", Settings = { { "Raven/FileSystem/DataDir", Path.Combine("~", Path.Combine("FileSystems", "testName")) } } }, "testName"); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName", new NetworkCredential(username, password, domain))) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } var names = await adminClient.GetNamesAsync(); Assert.Contains("testName", names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == "testName")); await adminClient.DeleteFileSystemAsync("testName"); names = await adminClient.GetNamesAsync(); Assert.DoesNotContain("testName", names); }
public async Task AdminClientWorkWithOAuthEnabled() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(enableAuthentication: true, apiKey: apiKey); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(new FileSystemDocument { Id = "Raven/FileSystem/" + "testName", Settings = { { Constants.FileSystem.DataDirectory, Path.Combine("~", Path.Combine("FileSystems", "testName")) } } }, "testName"); var names = await adminClient.GetNamesAsync(); Assert.Equal(2, names.Length); Assert.Contains("AdminClientWorkWithOAuthEnabled", names); var stats = await adminClient.GetStatisticsAsync(); Assert.Equal(0, stats.Length); // 0 because our fs aren't active using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName")) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } await adminClient.DeleteFileSystemAsync("testName", true); }
public async Task ShouldThrowWhenUsedApiKeyDefinitionDoesNotContainFileSystem() { var client = NewAsyncClient(enableAuthentication: true, apiKey: apiKey); var server = GetServer(); await client.UploadAsync("abc.bin", new RandomStream(3)); using (var anotherClient = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_ApiKeyDoesnContainsThisFS", apiKey: apiKey)) { await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database ErrorResponseException errorResponse = null; try { await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition } catch (ErrorResponseException ex) { errorResponse = ex; } Assert.NotNull(errorResponse); Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode); } }
public async Task CanCreateAndDeleteFileSystem() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(); var adminClient = client.Admin; const string newFileSystemName = "testName_CanDeleteFileSystem"; await adminClient.CreateOrUpdateFileSystemAsync(new FileSystemDocument { Id = "Raven/FileSystem/" + newFileSystemName, Settings = { { Constants.FileSystem.DataDirectory, Path.Combine("~", Path.Combine("FileSystems", newFileSystemName)) } } }, newFileSystemName); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, newFileSystemName)) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } var names = await adminClient.GetNamesAsync(); Assert.Contains(newFileSystemName, names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == newFileSystemName)); await adminClient.DeleteFileSystemAsync(newFileSystemName); names = await adminClient.GetNamesAsync(); Assert.DoesNotContain(newFileSystemName, names); }
public async Task Can_get_stats_for_all_active_file_systems() { var client = NewAsyncClient(); var server = GetServer(); using (var anotherClient = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "test")) { await anotherClient.EnsureFileSystemExistsAsync(); await client.UploadAsync("test1", new RandomStream(10)); // will make it active await anotherClient.UploadAsync("test1", new RandomStream(10)); // will make it active await client.UploadAsync("test2", new RandomStream(10)); var stats = await anotherClient.Admin.GetStatisticsAsync(); var stats1 = stats.FirstOrDefault(x => x.Name == client.FileSystemName); Assert.NotNull(stats1); var stats2 = stats.FirstOrDefault(x => x.Name == anotherClient.FileSystemName); Assert.NotNull(stats2); Assert.Equal(2, stats1.Metrics.Requests.Count); Assert.Equal(1, stats2.Metrics.Requests.Count); Assert.Equal(0, stats1.ActiveSyncs.Count); Assert.Equal(0, stats1.PendingSyncs.Count); Assert.Equal(0, stats2.ActiveSyncs.Count); Assert.Equal(0, stats2.PendingSyncs.Count); } }
public async Task CanCreateFileSystemWithDefaultValues() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(); var adminClient = client.Admin; const string newFileSystemName = "testName_CanCreateFileSystemWithDefaultValues"; await adminClient.CreateOrUpdateFileSystemAsync(new FileSystemDocument(), newFileSystemName); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, newFileSystemName)) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } var names = await adminClient.GetNamesAsync(); Assert.Contains(newFileSystemName, names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == newFileSystemName)); }
public async Task AdminClientWorkWithOAuthEnabled() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(enableAuthentication: true, apiKey: apiKey); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(MultiDatabase.CreateFileSystemDocument("testName")); var names = await adminClient.GetNamesAsync(); Assert.Equal(2, names.Length); Assert.Contains("AdminClientWorkWithOAuthEnabled", names); var stats = await adminClient.GetStatisticsAsync(); Assert.Equal(0, stats.Length); // 0 because our fs aren't active using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName")) { var buffer = Enumerable.Range(1, 1).Select(x => (byte)(x % byte.MaxValue)).ToArray(); await createdFsClient.UploadAsync("fooFoo", new MemoryStream(buffer)); } await adminClient.DeleteFileSystemAsync("testName", true); }
public async Task AdminClientWorkWithWinAuthEnabled() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(enableAuthentication: true, credentials: new NetworkCredential(FactIfWindowsAuthenticationIsAvailable.Admin.UserName, FactIfWindowsAuthenticationIsAvailable.Admin.Password, FactIfWindowsAuthenticationIsAvailable.Admin.Domain)); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(MultiDatabase.CreateFileSystemDocument("testName"), "testName"); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName", conventions: client.Conventions, credentials: new OperationCredentials(null, new NetworkCredential(FactIfWindowsAuthenticationIsAvailable.Admin.UserName, FactIfWindowsAuthenticationIsAvailable.Admin.Password, FactIfWindowsAuthenticationIsAvailable.Admin.Domain)))) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] {1})); } var names = await adminClient.GetNamesAsync(); Assert.Contains("testName", names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == "testName")); await adminClient.DeleteFileSystemAsync("testName"); names = await adminClient.GetNamesAsync(); Assert.DoesNotContain("testName", names); }
public async Task AdminClientWorkWithWinAuthEnabled() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(enableAuthentication: true, credentials: new NetworkCredential(username, password, domain)); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(new FileSystemDocument { Id = "Raven/FileSystem/" + "testName", Settings = { {"Raven/FileSystem/DataDir", Path.Combine("~", Path.Combine("FileSystems", "testName"))} } }, "testName"); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName", new NetworkCredential(username, password, domain))) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] {1})); } var names = await adminClient.GetNamesAsync(); Assert.Contains("testName", names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == "testName")); await adminClient.DeleteFileSystemAsync("testName"); names = await adminClient.GetNamesAsync(); Assert.DoesNotContain("testName", names); }
public async Task CanCreateAndDeleteFileSystem() { var client = (IAsyncFilesCommandsImpl)NewAsyncClient(); var adminClient = client.Admin; const string newFileSystemName = "testName_CanDeleteFileSystem"; await adminClient.CreateOrUpdateFileSystemAsync(new FileSystemDocument { Id = "Raven/FileSystem/" + newFileSystemName, Settings = { {Constants.FileSystem.DataDirectory, Path.Combine("~", Path.Combine("FileSystems", newFileSystemName))} } }, newFileSystemName); using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, newFileSystemName)) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } var names = await adminClient.GetNamesAsync(); Assert.Contains(newFileSystemName, names); var stats = await adminClient.GetStatisticsAsync(); Assert.NotNull(stats.FirstOrDefault(x => x.Name == newFileSystemName)); await adminClient.DeleteFileSystemAsync(newFileSystemName); names = await adminClient.GetNamesAsync(); Assert.DoesNotContain(newFileSystemName, names); }
public async Task ShouldThrowWhenUsedApiKeyDefinitionDoesNotContainFileSystem() { var client = NewAsyncClient(enableAuthentication: true, apiKey: apiKey); var server = GetServer(); await client.UploadAsync("abc.bin", new RandomStream(3)); using (var anotherClient = new AsyncFilesServerClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_ApiKeyDoesnContainsThisFS", apiKey: apiKey)) { await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database ErrorResponseException errorResponse = null; try { await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition } catch (InvalidOperationException ex) { errorResponse = ex.InnerException as ErrorResponseException; } Assert.NotNull(errorResponse); Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode); } }
public async Task AdminClientWorkWithOAuthEnabled() { var client = (IAsyncFilesCommandsImpl) NewAsyncClient(enableAuthentication: true, apiKey: apiKey); var adminClient = client.Admin; await adminClient.CreateFileSystemAsync(new FileSystemDocument { Id = "Raven/FileSystem/" + "testName", Settings = { { Constants.FileSystem.DataDirectory, Path.Combine("~", Path.Combine("FileSystems", "testName"))} } }, "testName"); var names = await adminClient.GetNamesAsync(); Assert.Equal(1, names.Length); // will not return 'testName' file system name because used apiKey doesn't have access to a such file system Assert.Equal("AdminClientWorkWithOAuthEnabled", names[0]); var stats = await adminClient.GetStatisticsAsync(); Assert.Equal(0, stats.Length); // 0 because our fs aren't active using (var createdFsClient = new AsyncFilesServerClient(client.ServerUrl, "testName")) { await createdFsClient.UploadAsync("foo", new MemoryStream(new byte[] { 1 })); } await adminClient.DeleteFileSystemAsync("testName", true); }