diff --git a/BTCPayServer.Tests/BTCPayServer.Tests.csproj b/BTCPayServer.Tests/BTCPayServer.Tests.csproj
index 468bd9bdd..332c9b9c7 100644
--- a/BTCPayServer.Tests/BTCPayServer.Tests.csproj
+++ b/BTCPayServer.Tests/BTCPayServer.Tests.csproj
@@ -45,4 +45,8 @@
+
+
+
+
diff --git a/BTCPayServer.Tests/BTCPayServerTester.cs b/BTCPayServer.Tests/BTCPayServerTester.cs
index 9babf373b..3f8e89b80 100644
--- a/BTCPayServer.Tests/BTCPayServerTester.cs
+++ b/BTCPayServer.Tests/BTCPayServerTester.cs
@@ -118,6 +118,7 @@ namespace BTCPayServer.Tests
config.AppendLine($"ltc.explorer.url={LTCNBXplorerUri.AbsoluteUri}");
config.AppendLine($"ltc.explorer.cookiefile=0");
config.AppendLine($"btc.lightning={IntegratedLightning.AbsoluteUri}");
+ config.AppendLine($"torrcfile={TestUtils.GetTestDataFullPath("Tor/torrc")}");
config.AppendLine($"debuglog=debug.log");
if (!string.IsNullOrEmpty(SSHPassword) && string.IsNullOrEmpty(SSHKeyFile))
config.AppendLine($"sshpassword={SSHPassword}");
diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs
index a109dff42..aff40d692 100644
--- a/BTCPayServer.Tests/SeleniumTests.cs
+++ b/BTCPayServer.Tests/SeleniumTests.cs
@@ -47,6 +47,8 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id("Logout")).Click();
s.Driver.AssertNoError();
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"));
Assert.Contains("ReturnUrl=%2Finvoices", s.Driver.Url);
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/BTC-P2P/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTC-P2P/hostname
new file mode 100644
index 000000000..ba384cd26
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTC-P2P/hostname
@@ -0,0 +1 @@
+rhrk7ncuqfcbkt7deaysn7st32hrf2tzztoumkj2vp3cqzy2d2arvdad.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/BTC-RPC/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTC-RPC/hostname
new file mode 100644
index 000000000..a88b3927c
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTC-RPC/hostname
@@ -0,0 +1 @@
+r32tqfpchpiptrfltyd4ku7q3ir4yidyfe4em63iz2g5wjcauyvyj4id.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/BTCPayServer/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTCPayServer/hostname
new file mode 100644
index 000000000..a00a7670a
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTCPayServer/hostname
@@ -0,0 +1 @@
+wsaxew3qa5ljfuenfebmaf3m5ykgatct3p6zjrqwoouj3foererde3id.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/BTCTransmuter/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTCTransmuter/hostname
new file mode 100644
index 000000000..9ca3d92d0
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/BTCTransmuter/hostname
@@ -0,0 +1 @@
+wzaq2ek6a5g6jyhr7giqsz2gbr6qdtcuwywcyvfplvrk7ugup3virvad.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/BitcoinP2P/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/BitcoinP2P/hostname
new file mode 100644
index 000000000..b26c8004e
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/BitcoinP2P/hostname
@@ -0,0 +1 @@
+jzebv74oaugje6aeykzcypzxs6pvt27wdmrcpe4pkjfprxgem2vyi7qd.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/WooCommerce/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/WooCommerce/hostname
new file mode 100644
index 000000000..61503625c
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/WooCommerce/hostname
@@ -0,0 +1 @@
+aeyn6mou5himgmog4tlnbjlgx5bwtwsqttd7sn7hay6lksvlfwmtkqyd.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/c-lightning/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/c-lightning/hostname
new file mode 100644
index 000000000..14c1600ac
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/c-lightning/hostname
@@ -0,0 +1 @@
+uewlcjmuuwcgs43lpcc7d64k2pf4xs7yyer7ztsq6cblyjxue3bc35qd.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/clightning/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/clightning/hostname
new file mode 100644
index 000000000..9ac49db59
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/clightning/hostname
@@ -0,0 +1 @@
+4iz3q7dp5xn5isqxsslrvbjrltqoqqocq25zmjgzvvxm5yp57jj4buid.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/hidden_services/lnd/hostname b/BTCPayServer.Tests/TestData/Tor/hidden_services/lnd/hostname
new file mode 100644
index 000000000..baf3ebac1
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/hidden_services/lnd/hostname
@@ -0,0 +1 @@
+ii3kqeayarsxr2jqkmr2l5np2f4vn6lznk55upd3udfbfskbjdzoq4yd.onion
diff --git a/BTCPayServer.Tests/TestData/Tor/torrc b/BTCPayServer.Tests/TestData/Tor/torrc
new file mode 100644
index 000000000..a9b9716e9
--- /dev/null
+++ b/BTCPayServer.Tests/TestData/Tor/torrc
@@ -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
diff --git a/BTCPayServer.Tests/TestUtils.cs b/BTCPayServer.Tests/TestUtils.cs
index 561585cca..7a2be7612 100644
--- a/BTCPayServer.Tests/TestUtils.cs
+++ b/BTCPayServer.Tests/TestUtils.cs
@@ -30,6 +30,18 @@ namespace BTCPayServer.Tests
}
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)
{
File.WriteAllText(filename, content);
diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs
index a001d311f..3d1589f0e 100644
--- a/BTCPayServer.Tests/UnitTest1.cs
+++ b/BTCPayServer.Tests/UnitTest1.cs
@@ -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)]
[Trait("Integration", "Integration")]
public async Task CanSetLightningServer()
diff --git a/BTCPayServer/Program.cs b/BTCPayServer/Program.cs
index 27219daa7..ef107d42b 100644
--- a/BTCPayServer/Program.cs
+++ b/BTCPayServer/Program.cs
@@ -16,7 +16,9 @@ using System.Collections;
using Microsoft.AspNetCore.Hosting.Server.Features;
using System.Threading;
using Serilog;
+using System.Runtime.CompilerServices;
+[assembly:InternalsVisibleTo("BTCPayServer.Tests")]
namespace BTCPayServer
{
class Program
diff --git a/BTCPayServer/Services/TorServices.cs b/BTCPayServer/Services/TorServices.cs
index 3296aef62..ece4a5b37 100644
--- a/BTCPayServer/Services/TorServices.cs
+++ b/BTCPayServer/Services/TorServices.cs
@@ -41,8 +41,8 @@ namespace BTCPayServer.Services
Services = Array.Empty();
return;
}
-
- var services = torrc.ServiceDirectories.SelectMany(d => d.ServicePorts.Select(p => (Directory: new DirectoryInfo(d.DirectoryPath), VirtualPort: p.VirtualPort)))
+ var torrcDir = Path.GetDirectoryName(_Options.TorrcFile);
+ var services = torrc.ServiceDirectories.SelectMany(d => d.ServicePorts.Select(p => (Directory: GetDirectory(d, torrcDir), VirtualPort: p.VirtualPort)))
.Select(d => (ServiceName: d.Directory.Name,
ReadingLines: System.IO.File.ReadAllLinesAsync(Path.Combine(d.Directory.FullName, "hostname")),
VirtualPort: d.VirtualPort))
@@ -80,6 +80,13 @@ namespace BTCPayServer.Services
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)
{
network = null;