Skip to content

Commit

Permalink
NOnion.Tests: ignore non-200 status codes
Browse files Browse the repository at this point in the history
Purpose of our HS browsing tests is to make sure we
can connect to the server and just receieving a
status code means we are connected so there's no
need to make sure the status code is 200, this
is especially true because TorHttpClient doesn't
handle redirects which causes Unsuccessful-
HttpRequestException when there's a redirect.
  • Loading branch information
aarani committed Aug 2, 2023
1 parent 7662941 commit 2e9fcf9
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions NOnion.Tests/HiddenServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,23 @@ public async Task BrowseFacebookOverHS()

var client = await TorServiceClient.ConnectAsync(directory, "facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion");
var httpClient = new TorHttpClient(client.GetStream(), "facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion");
await httpClient.GetAsStringAsync("/", false);

try
{
await httpClient.GetAsStringAsync("/", false);
}
catch (UnsuccessfulHttpRequestException)
{
// Ignore non-200 Http response status codes
// The fact that we are receieving an http response means we are connected
}
}

[Test]
[Retry(TestsRetryCount)]
public void CanBrowseFacebookOverHS()
{
Assert.ThrowsAsync(typeof(UnsuccessfulHttpRequestException), BrowseFacebookOverHS);
Assert.DoesNotThrowAsync(BrowseFacebookOverHS);
}

public async Task BrowseFacebookOverHSWithTLS()
Expand All @@ -122,8 +131,17 @@ public async Task BrowseFacebookOverHSWithTLS()
await sslStream.AuthenticateAsClientAsync(string.Empty, null, SslProtocols.Tls12, false);

var httpClientOverSslStream = new TorHttpClient(sslStream, "www.facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion");
var facebookResponse = await httpClientOverSslStream.GetAsStringAsync("/", false);
Assert.That(facebookResponse.Contains("<html"), "Response from facebook was invalid.");

try
{
var facebookResponse = await httpClientOverSslStream.GetAsStringAsync("/", false);
Assert.That(facebookResponse.Contains("<html"), "Response from facebook was invalid.");
}
catch (UnsuccessfulHttpRequestException)
{
// Ignore non-200 Http response status codes
// The fact that we are receieving an http response means we are connected
}
}

[Test]
Expand Down

0 comments on commit 2e9fcf9

Please sign in to comment.