Add torrc files in tests

This commit is contained in:
nicolas.dorier
2019-11-08 16:10:49 +09:00
parent 13c8372329
commit 9d3026f676
17 changed files with 79 additions and 2 deletions

View File

@@ -45,4 +45,8 @@
<ProjectReference Include="..\BTCPayServer\BTCPayServer.csproj" /> <ProjectReference Include="..\BTCPayServer\BTCPayServer.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="TestData\Tor\" />
</ItemGroup>
</Project> </Project>

View File

@@ -118,6 +118,7 @@ namespace BTCPayServer.Tests
config.AppendLine($"ltc.explorer.url={LTCNBXplorerUri.AbsoluteUri}"); config.AppendLine($"ltc.explorer.url={LTCNBXplorerUri.AbsoluteUri}");
config.AppendLine($"ltc.explorer.cookiefile=0"); config.AppendLine($"ltc.explorer.cookiefile=0");
config.AppendLine($"btc.lightning={IntegratedLightning.AbsoluteUri}"); config.AppendLine($"btc.lightning={IntegratedLightning.AbsoluteUri}");
config.AppendLine($"torrcfile={TestUtils.GetTestDataFullPath("Tor/torrc")}");
config.AppendLine($"debuglog=debug.log"); config.AppendLine($"debuglog=debug.log");
if (!string.IsNullOrEmpty(SSHPassword) && string.IsNullOrEmpty(SSHKeyFile)) if (!string.IsNullOrEmpty(SSHPassword) && string.IsNullOrEmpty(SSHKeyFile))
config.AppendLine($"sshpassword={SSHPassword}"); config.AppendLine($"sshpassword={SSHPassword}");

View File

@@ -47,6 +47,8 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id("Logout")).Click(); s.Driver.FindElement(By.Id("Logout")).Click();
s.Driver.AssertNoError(); s.Driver.AssertNoError();
Assert.Contains("Account/Login", s.Driver.Url); Assert.Contains("Account/Login", s.Driver.Url);
// Should show the Tor address
Assert.Contains("wsaxew3qa5ljfuenfebmaf3m5ykgatct3p6zjrqwoouj3foererde3id.onion", s.Driver.PageSource);
s.Driver.Navigate().GoToUrl(s.Link("/invoices")); s.Driver.Navigate().GoToUrl(s.Link("/invoices"));
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url); Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);

View File

@@ -0,0 +1 @@
rhrk7ncuqfcbkt7deaysn7st32hrf2tzztoumkj2vp3cqzy2d2arvdad.onion

View File

@@ -0,0 +1 @@
r32tqfpchpiptrfltyd4ku7q3ir4yidyfe4em63iz2g5wjcauyvyj4id.onion

View File

@@ -0,0 +1 @@
wsaxew3qa5ljfuenfebmaf3m5ykgatct3p6zjrqwoouj3foererde3id.onion

View File

@@ -0,0 +1 @@
wzaq2ek6a5g6jyhr7giqsz2gbr6qdtcuwywcyvfplvrk7ugup3virvad.onion

View File

@@ -0,0 +1 @@
jzebv74oaugje6aeykzcypzxs6pvt27wdmrcpe4pkjfprxgem2vyi7qd.onion

View File

@@ -0,0 +1 @@
aeyn6mou5himgmog4tlnbjlgx5bwtwsqttd7sn7hay6lksvlfwmtkqyd.onion

View File

@@ -0,0 +1 @@
uewlcjmuuwcgs43lpcc7d64k2pf4xs7yyer7ztsq6cblyjxue3bc35qd.onion

View File

@@ -0,0 +1 @@
4iz3q7dp5xn5isqxsslrvbjrltqoqqocq25zmjgzvvxm5yp57jj4buid.onion

View File

@@ -0,0 +1 @@
ii3kqeayarsxr2jqkmr2l5np2f4vn6lznk55upd3udfbfskbjdzoq4yd.onion

View File

@@ -0,0 +1,24 @@
# For the hidden service BTC-P2P
HiddenServiceDir hidden_services/BTC-P2P
# Redirecting to btcpayserver_bitcoind
HiddenServicePort 8333 172.19.0.2:39388
# For the hidden service BTC-RPC
HiddenServiceDir hidden_services/BTC-RPC
# Redirecting to btcpayserver_bitcoind
HiddenServicePort 8332 172.19.0.2:43782
# For the hidden service BTCPayServer
HiddenServiceDir hidden_services/BTCPayServer
# Redirecting to nginx
HiddenServicePort 80 172.19.0.13:80
# For the hidden service BTCTransmuter
HiddenServiceDir hidden_services/BTCTransmuter
# Redirecting to nginx
HiddenServicePort 80 172.19.0.13:80
# For the hidden service WooCommerce
HiddenServiceDir hidden_services/WooCommerce
# Redirecting to generated_woocommerce_1
HiddenServicePort 80 172.19.0.15:80
# For the hidden service c-lightning
HiddenServiceDir hidden_services/c-lightning
# Redirecting to btcpayserver_clightning_bitcoin
HiddenServicePort 9735 172.19.0.10:9735

View File

@@ -30,6 +30,18 @@ namespace BTCPayServer.Tests
} }
return directory; return directory;
} }
public static string GetTestDataFullPath(string relativeFilePath)
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetFiles("*.csproj").Any())
{
directory = directory.Parent;
}
return Path.Combine(directory.FullName, "TestData", relativeFilePath);
}
public static FormFile GetFormFile(string filename, string content) public static FormFile GetFormFile(string filename, string content)
{ {
File.WriteAllText(filename, content); File.WriteAllText(filename, content);

View File

@@ -532,6 +532,22 @@ namespace BTCPayServer.Tests
} }
} }
[Fact]
[Trait("Fast", "Fast")]
public async Task CanEnumerateTorServices()
{
var tor = new TorServices(new BTCPayNetworkProvider(NetworkType.Regtest), new BTCPayServerOptions()
{
TorrcFile = TestUtils.GetTestDataFullPath("Tor/torrc")
});
await tor.Refresh();
Assert.Single(tor.Services.Where(t => t.ServiceType == TorServiceType.BTCPayServer));
Assert.Single(tor.Services.Where(t => t.ServiceType == TorServiceType.P2P));
Assert.Single(tor.Services.Where(t => t.ServiceType == TorServiceType.RPC));
Assert.True(tor.Services.Where(t => t.ServiceType == TorServiceType.Other).Count() > 1);
}
[Fact(Timeout = 60 * 2 * 1000)] [Fact(Timeout = 60 * 2 * 1000)]
[Trait("Integration", "Integration")] [Trait("Integration", "Integration")]
public async Task CanSetLightningServer() public async Task CanSetLightningServer()

View File

@@ -16,7 +16,9 @@ using System.Collections;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using System.Threading; using System.Threading;
using Serilog; using Serilog;
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("BTCPayServer.Tests")]
namespace BTCPayServer namespace BTCPayServer
{ {
class Program class Program

View File

@@ -41,8 +41,8 @@ namespace BTCPayServer.Services
Services = Array.Empty<TorService>(); Services = Array.Empty<TorService>();
return; return;
} }
var torrcDir = Path.GetDirectoryName(_Options.TorrcFile);
var services = torrc.ServiceDirectories.SelectMany(d => d.ServicePorts.Select(p => (Directory: new DirectoryInfo(d.DirectoryPath), VirtualPort: p.VirtualPort))) var services = torrc.ServiceDirectories.SelectMany(d => d.ServicePorts.Select(p => (Directory: GetDirectory(d, torrcDir), VirtualPort: p.VirtualPort)))
.Select(d => (ServiceName: d.Directory.Name, .Select(d => (ServiceName: d.Directory.Name,
ReadingLines: System.IO.File.ReadAllLinesAsync(Path.Combine(d.Directory.FullName, "hostname")), ReadingLines: System.IO.File.ReadAllLinesAsync(Path.Combine(d.Directory.FullName, "hostname")),
VirtualPort: d.VirtualPort)) VirtualPort: d.VirtualPort))
@@ -80,6 +80,13 @@ namespace BTCPayServer.Services
Services = result.ToArray(); Services = result.ToArray();
} }
private static DirectoryInfo GetDirectory(HiddenServiceDir hs, string relativeTo)
{
if (Path.IsPathRooted(hs.DirectoryPath))
return new DirectoryInfo(hs.DirectoryPath);
return new DirectoryInfo(Path.Combine(relativeTo, hs.DirectoryPath));
}
private bool TryParseP2PService(string name, out BTCPayNetworkBase network, out TorServiceType serviceType) private bool TryParseP2PService(string name, out BTCPayNetworkBase network, out TorServiceType serviceType)
{ {
network = null; network = null;