public async Task TorSharpToolFetch_AllResultsAreWorking(TorSharpOSPlatform osPlatform, TorSharpArchitecture architecture) { using (var te = TestEnvironment.Initialize(_output)) { // Arrange var settings = te.BuildSettings(); settings.OSPlatform = osPlatform; settings.Architecture = architecture; settings.ToolDownloadStrategy = ToolDownloadStrategy.All; using (var httpClientHandler = new HttpClientHandler()) using (var loggingHandler = new LoggingHandler(_output) { InnerHandler = httpClientHandler }) using (var httpClient = new HttpClient(loggingHandler)) using (var proxy = new TorSharpProxy(settings)) { _output.WriteLine(settings); var fetcher = _httpFixture.GetTorSharpToolFetcher(settings, httpClient); // Act var updates = await fetcher.CheckForUpdatesAsync(); // Assert Assert.NotNull(updates); _output.WriteLine("Privoxy URL: " + updates.Privoxy.LatestDownload.Url.AbsoluteUri); _output.WriteLine("Tor URL: " + updates.Tor.LatestDownload.Url.AbsoluteUri); } } }
private async Task ExecuteEndToEndTestAsync(TorSharpSettings settings) { // Arrange using (var httpClient = new HttpClient()) using (var proxy = new TorSharpProxy(settings)) { _output.WriteLine(settings); // Act var fetcher = _httpFixture.GetTorSharpToolFetcher(settings, httpClient); await fetcher.FetchAsync(); _output.WriteLine("The tools have been fetched"); await proxy.ConfigureAndStartAsync(); _output.WriteLine("The proxy has been started"); // get the first identity var ipA = await GetCurrentIpAddressAsync(proxy, settings); await proxy.GetNewIdentityAsync(); _output.WriteLine("Get new identity succeeded"); var ipB = await GetCurrentIpAddressAsync(proxy, settings); // Assert Assert.Equal(AddressFamily.InterNetwork, ipA.AddressFamily); Assert.Equal(AddressFamily.InterNetwork, ipB.AddressFamily); var zippedDir = new DirectoryInfo(settings.ZippedToolsDirectory); Assert.True(zippedDir.Exists, "The zipped tools directory should exist."); Assert.Empty(zippedDir.EnumerateDirectories()); Assert.Equal(2, zippedDir.EnumerateFiles().Count()); var extractedDir = new DirectoryInfo(settings.ExtractedToolsDirectory); Assert.True(extractedDir.Exists, "The extracted tools directory should exist."); Assert.Equal(2, extractedDir.EnumerateDirectories().Count()); Assert.Empty(extractedDir.EnumerateFiles()); } }
public async Task TrafficReadAndWritten() { using (var te = TestEnvironment.Initialize(_output)) { // Arrange var settings = te.BuildSettings(); settings.ToolRunnerType = ToolRunnerType.Simple; using (var httpClient = new HttpClient()) using (var proxy = new TorSharpProxy(settings)) { _output.WriteLine(settings); var fetcher = _httpFixture.GetTorSharpToolFetcher(settings, httpClient); await fetcher.FetchAsync(); _output.WriteLine("The tools have been fetched"); await proxy.ConfigureAndStartAsync(); _output.WriteLine("The proxy has been started"); await GetCurrentIpAddressAsync(proxy, settings); _output.WriteLine("The first request has succeeded"); // Act using (var controlClient = await proxy.GetControlClientAsync()) { var readBefore = await controlClient.GetTrafficReadAsync(); _output.WriteLine($"Read before: {readBefore}"); var writtenBefore = await controlClient.GetTrafficWrittenAsync(); _output.WriteLine($"Written before: {writtenBefore}"); // Upload and download some bytes var bytes = 10000; await SendProxiedRequestAsync( proxy, settings, $"uploading and downloading {bytes} bytes", async proxiedHttpClient => { using (var content = new ByteArrayContent(new byte[bytes])) using (var response = await proxiedHttpClient.PostAsync("https://httpbin.org/anything", content)) { } return(true); }); var readAfter = await controlClient.GetTrafficReadAsync(); _output.WriteLine($"Read after: {readBefore}"); var writtenAfter = await controlClient.GetTrafficWrittenAsync(); _output.WriteLine($"Written after: {writtenBefore}"); // Assert Assert.True(readBefore + bytes <= readAfter, $"At least {bytes} more bytes should have been read."); Assert.True(writtenBefore + bytes <= writtenAfter, $"At least {bytes} more bytes should have been written."); } } } }