Test LND Seed Backup service and Logs. Use the Confirm View instead of poppup

This commit is contained in:
nicolas.dorier 2019-11-16 14:06:37 +09:00
parent 6828730313
commit 84fe14a1ed
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
7 changed files with 60 additions and 23 deletions

View file

@ -102,7 +102,6 @@ namespace BTCPayServer.Tests
if (!Directory.Exists(chainDirectory))
Directory.CreateDirectory(chainDirectory);
StringBuilder config = new StringBuilder();
config.AppendLine($"{chain.ToLowerInvariant()}=1");
if (InContainer)
@ -120,6 +119,10 @@ namespace BTCPayServer.Tests
config.AppendLine($"btc.lightning={IntegratedLightning.AbsoluteUri}");
config.AppendLine($"torrcfile={TestUtils.GetTestDataFullPath("Tor/torrc")}");
config.AppendLine($"debuglog=debug.log");
var localLndBackupFile = Path.Combine(_Directory, "walletunlock.json");
File.Copy(TestUtils.GetTestDataFullPath("LndSeedBackup/walletunlock.json"), localLndBackupFile, true);
config.AppendLine($"btc.external.lndseedbackup={localLndBackupFile}");
if (!string.IsNullOrEmpty(SSHPassword) && string.IsNullOrEmpty(SSHKeyFile))
config.AppendLine($"sshpassword={SSHPassword}");
if (!string.IsNullOrEmpty(SSHKeyFile))

View file

@ -32,6 +32,27 @@ namespace BTCPayServer.Tests
s.Driver.FindElement(By.Id("ServerSettings")).Click();
s.Driver.AssertNoError();
s.ClickOnAllSideMenus();
s.Driver.FindElement(By.LinkText("Services")).Click();
Logs.Tester.LogInformation("Let's if we can access LND's seed");
Assert.Contains("server/services/lndseedbackup/BTC", s.Driver.PageSource);
s.Driver.Navigate().GoToUrl(s.Link("/server/services/lndseedbackup/BTC"));
s.Driver.FindElement(By.Id("details")).Click();
var seedEl = s.Driver.FindElement(By.Id("SeedTextArea"));
Assert.True(seedEl.Displayed);
Assert.Contains("about over million", seedEl.Text, StringComparison.OrdinalIgnoreCase);
var passEl = s.Driver.FindElement(By.Id("PasswordInput"));
Assert.True(passEl.Displayed);
Assert.Contains(passEl.Text, "hellorockstar", StringComparison.OrdinalIgnoreCase);
s.Driver.FindElement(By.Id("delete")).Click();
s.Driver.FindElement(By.Id("continue")).Click();
seedEl = s.Driver.FindElement(By.Id("SeedTextArea"));
Assert.Contains("Seed removed", seedEl.Text, StringComparison.OrdinalIgnoreCase);
Logs.Tester.LogInformation("Let's check if we can access the logs");
s.Driver.FindElement(By.LinkText("Logs")).Click();
s.Driver.FindElement(By.PartialLinkText(".log")).Click();
Assert.Contains("Starting listening NBXplorer", s.Driver.PageSource);
s.Driver.Quit();
}
}

View file

@ -676,9 +676,21 @@ namespace BTCPayServer.Controllers
}
}
[HttpGet]
[Route("server/services/{serviceName}/{cryptoCode}/removelndseed")]
public IActionResult RemoveLndSeed(string serviceName, string cryptoCode)
{
return View("Confirm", new ConfirmModel()
{
Title = "Delete LND Seed",
Description = "Please make sure you made a backup of the seed and password before deleting the LND backup seed from the server, are you sure to continue?",
Action = "Delete"
});
}
[HttpPost]
[Route("server/services/{serviceName}/{cryptoCode}/removelndseed")]
public async Task<IActionResult> RemoveLndSeed(string serviceName, string cryptoCode)
public async Task<IActionResult> RemoveLndSeedPost(string serviceName, string cryptoCode)
{
var service = GetService(serviceName, cryptoCode);
if (service == null)

View file

@ -55,6 +55,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using BTCPayServer.Security.Bitpay;
using Serilog;
namespace BTCPayServer.Hosting
{
@ -268,9 +269,24 @@ namespace BTCPayServer.Hosting
var rateLimits = new RateLimitService();
rateLimits.SetZone($"zone={ZoneLimits.Login} rate=5r/min burst=3 nodelay");
services.AddSingleton(rateLimits);
services.AddLogging(logBuilder =>
{
var debugLogFile = BTCPayServerOptions.GetDebugLog(configuration);
if (!string.IsNullOrEmpty(debugLogFile))
{
Serilog.Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Is(BTCPayServerOptions.GetDebugLogLevel(configuration))
.WriteTo.File(debugLogFile, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: MAX_DEBUG_LOG_FILE_SIZE, rollOnFileSizeLimit: true, retainedFileCountLimit: 1)
.CreateLogger();
logBuilder.AddSerilog(Serilog.Log.Logger);
}
});
return services;
}
private const long MAX_DEBUG_LOG_FILE_SIZE = 2000000; // If debug log is in use roll it every N MB.
private static void AddBtcPayServerAuthenticationSchemes(this IServiceCollection services,
IConfiguration configuration)
{

View file

@ -222,6 +222,7 @@ namespace BTCPayServer.Hosting
private static void ConfigureCore(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
{
Logs.Configure(loggerFactory);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();

View file

@ -23,8 +23,6 @@ namespace BTCPayServer
{
class Program
{
private const long MAX_DEBUG_LOG_FILE_SIZE = 2000000; // If debug log is in use roll it every N MB.
static void Main(string[] args)
{
ServicePointManager.DefaultConnectionLimit = 100;
@ -57,17 +55,6 @@ namespace BTCPayServer
l.AddFilter("Microsoft.AspNetCore.Antiforgery.Internal", LogLevel.Critical);
l.AddFilter("OpenIddict.Server.OpenIddictServerProvider", LogLevel.Error);
l.AddProvider(new CustomConsoleLogProvider(processor));
// Use Serilog for debug log file.
var debugLogFile = BTCPayServerOptions.GetDebugLog(conf);
if (string.IsNullOrEmpty(debugLogFile) != false) return;
Serilog.Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Is(BTCPayServerOptions.GetDebugLogLevel(conf))
.WriteTo.File(debugLogFile, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: MAX_DEBUG_LOG_FILE_SIZE, rollOnFileSizeLimit: true, retainedFileCountLimit: 1)
.CreateLogger();
l.AddSerilog(Serilog.Log.Logger);
})
.UseStartup<Startup>()
.Build();

View file

@ -28,7 +28,7 @@
<div class="input-group-prepend">
<label for="Seed" class="input-group-text"><span class="input-group-addon fa fa-eye"></span><span class="ml-2">Seed</span></label>
</div>
<textarea asp-for="Seed" onClick="this.select();" class="form-control" readonly rows="@(Model.Removed ? "1" : "3")"></textarea>
<textarea id="SeedTextArea" asp-for="Seed" onClick="this.select();" class="form-control" readonly rows="@(Model.Removed ? "1" : "3")"></textarea>
</div>
</div>
@if (!Model.Removed)
@ -38,12 +38,12 @@
<div class="input-group-prepend">
<label for="WalletPassword" class="input-group-text"><span class="input-group-addon fa fa-lock"></span><span class="ml-2">Password</span></label>
</div>
<input asp-for="WalletPassword" onClick="this.select();" class="form-control" readonly />
<input id="PasswordInput" asp-for="WalletPassword" onClick="this.select();" class="form-control" readonly />
</div>
</div>
<div class="form-group collapse">
<form method="post" asp-action="RemoveLndSeed" asp-route-serviceName="@this.Context.GetRouteValue("serviceName")" asp-route-cryptoCode="@this.Context.GetRouteValue("cryptoCode")">
<button class="btn btn-primary" type="submit" onclick="return confirmSeedDelete();">Remove Seed from server</button>
<form method="get" asp-action="RemoveLndSeed" asp-route-serviceName="@this.Context.GetRouteValue("serviceName")" asp-route-cryptoCode="@this.Context.GetRouteValue("cryptoCode")">
<button id="delete" class="btn btn-primary" type="submit">Remove Seed from server</button>
</form>
</div>
}
@ -53,9 +53,6 @@
@section Scripts {
<script type="text/javascript">
function confirmSeedDelete() {
return confirm('This operation is not undoable. Are you sure you want to proceed with deleting seed from LND container?');
}
$(function () {
$("#details").click(function () {
$(".collapse").removeClass("collapse");