23b6feae6b
The server MSI's wizard is now Welcome > Folders > Database > Certificate > Server Address > Ready, after StifleR's flow: - Folders: install, data, log and backup folders with Browse (defaults follow a changed install folder), Enable Windows Long Paths while they are off. - Database: SQLite, PostgreSQL (host, port, database, SSL mode, user, password) or SQL Server (server\instance, port, database, Windows or SQL login, Encrypt, Trust Server Certificate), Create If Missing, and Test Connection with the server's own error; Next needs a passing test or Continue Without a Successful Test. - Server Address: HTTPS port and an HTTP redirect port, Listen On all or one of this computer's addresses, NATS and object store ports, public URL, firewall rules; a port in use names the program holding it. Every choice is a public property (DATAFOLDER LOGFOLDER BACKUPFOLDER ENABLELONGPATHS DBPROVIDER DBSERVER DBPORT DBNAME DBAUTH DBUSER DBPASSWORD DBSSLMODE DBENCRYPT DBTRUSTCERT DBCREATE DBSKIPTEST HTTPREDIRECTPORT OBJECTSTOREPORT PUBLICSERVERURL FIREWALL), checked the same way for /qn before anything changes. The custom actions test PostgreSQL with their own protocol client (SCRAM-SHA-256, MD5, SSL) and SQL Server with System.Data.SqlClient, create the database when the account may (and give the service's Windows login db_owner), write appsettings.json in place, keep the password DPAPI-protected and out of the log, restrict the file and new folders to SYSTEM and Administrators, create long folders through \\?\, and keep netsh firewall rules for the ports in effect. Upgrades find the install folder again, keep the configuration and change the database only when the command line gives another; the choices but the password are remembered for a reinstall. The banner and Welcome/Finish artwork are drawn from the product icon by Generate-Icons.ps1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
4.6 KiB
C#
121 lines
4.6 KiB
C#
using System.Net;
|
|
using System.Net.Sockets;
|
|
using ExecuteR.Installer.CustomActions;
|
|
using Xunit;
|
|
|
|
namespace Shared.Tests;
|
|
|
|
/// <summary>The server MSI's long paths, port checks and password protection, against this computer (Windows).</summary>
|
|
public sealed class InstallerSystemTests : IDisposable
|
|
{
|
|
private readonly string temp = Path.Combine(Path.GetTempPath(), $"installer-{Guid.NewGuid():N}");
|
|
|
|
public void Dispose()
|
|
{
|
|
if (LongPath.DirectoryExists(temp))
|
|
{
|
|
Directory.Delete(LongPath.Extended(temp), recursive: true);
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(@"C:\Data", @"\\?\C:\Data")]
|
|
[InlineData(@"C:\Data\", @"\\?\C:\Data")]
|
|
[InlineData(@"C:/Data/sub", @"\\?\C:\Data\sub")]
|
|
[InlineData(@"\\server\share\x", @"\\?\UNC\server\share\x")]
|
|
[InlineData(@"\\?\C:\Data", @"\\?\C:\Data")]
|
|
public void TheExtendedFormOfAPath(string path, string extended)
|
|
{
|
|
Assert.Equal(extended, LongPath.Extended(path));
|
|
Assert.Equal(path.StartsWith(@"\\?\", StringComparison.Ordinal) ? path.Substring(4) : LongPath.WithoutTrailingSlash(path.Replace('/', '\\')), LongPath.Plain(extended));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(@"D:\ExecuteR", @"D:\ExecuteR\")]
|
|
[InlineData(@" ""D:\ExecuteR\\"" ", @"D:\ExecuteR\")]
|
|
[InlineData(@"D:/ExecuteR/", @"D:/ExecuteR\")]
|
|
[InlineData("", "")]
|
|
public void FoldersEndInABackslash(string path, string expected)
|
|
{
|
|
Assert.Equal(expected, LongPath.WithTrailingSlash(path));
|
|
}
|
|
|
|
[Fact]
|
|
public void CreatesAFolderBeyondMaxPath()
|
|
{
|
|
var deep = temp;
|
|
while (deep.Length < 400)
|
|
{
|
|
deep = Path.Combine(deep, "a folder name of some length");
|
|
}
|
|
|
|
Assert.True(LongPath.IsLong(deep));
|
|
Assert.True(LongPath.CreateDirectory(deep));
|
|
Assert.True(LongPath.DirectoryExists(deep));
|
|
Assert.False(LongPath.CreateDirectory(deep + @"\"));
|
|
// .NET opens it too: what the server does with its data folder.
|
|
File.WriteAllText(Path.Combine(deep, "probe.txt"), "ok");
|
|
Assert.Equal("ok", File.ReadAllText(Path.Combine(deep, "probe.txt")));
|
|
}
|
|
|
|
[Fact]
|
|
public void TheInstallFolderLeavesRoomForTheLongestFile()
|
|
{
|
|
Assert.Equal(259 - 63, LongPath.InstallFolderLimit(63));
|
|
}
|
|
|
|
[Fact]
|
|
public void WindowsLongPathsCanBeRead()
|
|
{
|
|
var on = LongPath.WindowsLongPathsEnabled();
|
|
|
|
Assert.Equal(on, LongPath.WindowsLongPathsEnabled());
|
|
}
|
|
|
|
[Fact]
|
|
public void FindsAListenerAndNamesItsProgram()
|
|
{
|
|
using var listener = new TcpListener(IPAddress.Loopback, 0);
|
|
listener.Start();
|
|
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
|
|
|
|
var listeners = PortCheck.Listeners();
|
|
var ours = Assert.Single(listeners, entry => entry.Port == port && entry.Address.Equals(IPAddress.Loopback));
|
|
Assert.Equal(Environment.ProcessId, ours.ProcessId);
|
|
|
|
var requests = new List<PortRequest> { new("HTTPS", "HTTPPORT", port.ToString(System.Globalization.CultureInfo.InvariantCulture), "0.0.0.0") };
|
|
var problem = Assert.Single(PortCheck.BusyProblems(requests, listeners, PortCheck.ProcessName));
|
|
Assert.Contains($"Port {port} (HTTPS) is in use by", problem);
|
|
Assert.Contains($"PID {Environment.ProcessId}", problem);
|
|
|
|
Assert.Empty(PortCheck.BusyProblems(requests, listeners, PortCheck.ProcessName, pid => pid == Environment.ProcessId));
|
|
var elsewhere = new List<PortRequest> { new("HTTPS", "HTTPPORT", port.ToString(System.Globalization.CultureInfo.InvariantCulture), "10.255.255.1") };
|
|
Assert.Empty(PortCheck.BusyProblems(elsewhere, listeners, PortCheck.ProcessName));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("0.0.0.0", "127.0.0.1", true)]
|
|
[InlineData("127.0.0.1", "0.0.0.0", true)]
|
|
[InlineData("127.0.0.1", "10.0.0.1", false)]
|
|
[InlineData("10.0.0.1", "10.0.0.1", true)]
|
|
[InlineData("::", "10.0.0.1", true)]
|
|
[InlineData("0.0.0.0", "::", false)]
|
|
[InlineData("::1", "::", true)]
|
|
public void WhichBindsCollide(string ours, string theirs, bool overlaps)
|
|
{
|
|
Assert.Equal(overlaps, PortCheck.Overlaps(IPAddress.Parse(ours), IPAddress.Parse(theirs)));
|
|
}
|
|
|
|
[Fact]
|
|
public void ThePasswordIsStoredForThisComputerOnly()
|
|
{
|
|
var stored = ProtectedSecret.Protect("pa;ss\"word");
|
|
|
|
Assert.StartsWith(ProtectedSecret.Prefix, stored);
|
|
Assert.DoesNotContain("pa;ss", stored);
|
|
Assert.Equal("pa;ss\"word", ProtectedSecret.Unprotect(stored));
|
|
Assert.NotEqual(stored, ProtectedSecret.Protect("pa;ss\"word"));
|
|
Assert.Equal("plain", ProtectedSecret.Unprotect("plain"));
|
|
}
|
|
}
|