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>
105 lines
4.5 KiB
C#
105 lines
4.5 KiB
C#
using Backend.Data;
|
|
using ExecuteR.Installer.CustomActions;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Npgsql;
|
|
using Xunit;
|
|
|
|
namespace Backend.Tests;
|
|
|
|
/// <summary>
|
|
/// What the server MSI writes for the database, read back the way the server reads it: the connection strings by the server's own
|
|
/// providers and the DPAPI-protected password by DatabasePassword (the SQL Server test against LocalDB is in tests/Shared.Tests).
|
|
/// </summary>
|
|
public sealed class InstallerDatabaseTests
|
|
{
|
|
[Fact]
|
|
public void TheServerReadsThePasswordTheInstallerProtected()
|
|
{
|
|
var stored = ProtectedSecret.Protect("pa;ss=wo\"rd");
|
|
|
|
Assert.Equal("pa;ss=wo\"rd", DatabasePassword.Reveal(stored));
|
|
Assert.Equal("back", ProtectedSecret.Unprotect(DatabasePassword.Protect("back")));
|
|
Assert.Equal(ProtectedSecret.Prefix, DatabasePassword.Prefix);
|
|
}
|
|
|
|
[Fact]
|
|
public void TheConnectionStringGetsThePasswordAtStart()
|
|
{
|
|
var database = new DatabaseSettings
|
|
{
|
|
Provider = DatabaseSettings.PostgreSql,
|
|
Server = "db.example.com",
|
|
Port = "5433",
|
|
Name = "Exec;uteR",
|
|
User = "executer",
|
|
Password = "pa;ss=wo\"rd",
|
|
SslMode = "VerifyFull",
|
|
};
|
|
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["DATABASE_PROVIDER"] = database.ConfigurationProvider,
|
|
["DATABASE_CONNECTION_STRING"] = database.ServerConnectionString(),
|
|
["DATABASE_PASSWORD"] = ProtectedSecret.Protect(database.Password),
|
|
}).Build();
|
|
|
|
var options = DatabaseOptions.FromConfiguration(configuration);
|
|
|
|
var parsed = new NpgsqlConnectionStringBuilder(options.ConnectionString);
|
|
Assert.Equal(DatabaseProvider.Postgres, options.Provider);
|
|
Assert.Equal("db.example.com", parsed.Host);
|
|
Assert.Equal(5433, parsed.Port);
|
|
Assert.Equal("Exec;uteR", parsed.Database);
|
|
Assert.Equal("executer", parsed.Username);
|
|
Assert.Equal("pa;ss=wo\"rd", parsed.Password);
|
|
Assert.Equal(SslMode.VerifyFull, parsed.SslMode);
|
|
Assert.Null(new NpgsqlConnectionStringBuilder(database.ServerConnectionString()).Password);
|
|
}
|
|
|
|
[Fact]
|
|
public void APlainPasswordAndNoneWork()
|
|
{
|
|
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["DATABASE_PROVIDER"] = "sqlserver",
|
|
["DATABASE_CONNECTION_STRING"] = "Data Source=sql01;Initial Catalog=ExecuteR;User ID=u;Password=old",
|
|
["DATABASE_PASSWORD"] = "",
|
|
}).Build();
|
|
|
|
Assert.Equal("old", new SqlConnectionStringBuilder(DatabaseOptions.FromConfiguration(configuration).ConnectionString).Password);
|
|
|
|
configuration["DATABASE_PASSWORD"] = "new";
|
|
Assert.Equal("new", new SqlConnectionStringBuilder(DatabaseOptions.FromConfiguration(configuration).ConnectionString).Password);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(DatabaseSettings.WindowsAuthentication, true, false, @"sql01\PROD", "")]
|
|
[InlineData(DatabaseSettings.SqlAuthentication, false, true, "sql01", "14330")]
|
|
public void TheSqlServerStringIsMicrosoftDataSqlClients(string authentication, bool encrypt, bool trust, string server, string port)
|
|
{
|
|
var database = new DatabaseSettings
|
|
{
|
|
Provider = DatabaseSettings.SqlServer,
|
|
Server = server,
|
|
Port = port,
|
|
Name = "ExecuteR",
|
|
Authentication = authentication,
|
|
User = "executer",
|
|
Password = "pw",
|
|
Encrypt = encrypt,
|
|
TrustServerCertificate = trust,
|
|
};
|
|
|
|
var parsed = new SqlConnectionStringBuilder(database.ServerConnectionString());
|
|
|
|
Assert.Equal(port.Length > 0 ? $"{server},{port}" : server, parsed.DataSource);
|
|
Assert.Equal("ExecuteR", parsed.InitialCatalog);
|
|
Assert.Equal(authentication == DatabaseSettings.WindowsAuthentication, parsed.IntegratedSecurity);
|
|
Assert.Equal(encrypt ? SqlConnectionEncryptOption.Mandatory : SqlConnectionEncryptOption.Optional, parsed.Encrypt);
|
|
Assert.Equal(trust, parsed.TrustServerCertificate);
|
|
Assert.Equal("", parsed.Password);
|
|
Assert.Equal("ExecuteR Server", parsed.ApplicationName);
|
|
Assert.Equal(authentication == DatabaseSettings.WindowsAuthentication ? "" : "pw", new SqlConnectionStringBuilder(database.SqlServerTestConnectionString("master")).Password);
|
|
}
|
|
}
|