RepositorySetup.LoginFor/IsLocal duplicated Core's ServiceAccounts, which the web uses for the GRANT script. Setup now uses ServiceAccounts too, so the login the installer grants and the one the web shows cannot drift apart. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
50 lines
2 KiB
C#
50 lines
2 KiB
C#
using SQLInsight.Agent.Setup;
|
|
using SQLInsight.Core.Configuration;
|
|
|
|
namespace SQLInsight.Agent.Tests;
|
|
|
|
public sealed class RepositorySetupTests
|
|
{
|
|
[Theory]
|
|
[InlineData(".")]
|
|
[InlineData(@".\SQLEXPRESS")]
|
|
[InlineData("(local)")]
|
|
[InlineData("localhost,1433")]
|
|
[InlineData(@"tcp:localhost\SQLEXPRESS")]
|
|
[InlineData("SQLMON01")]
|
|
[InlineData(@"sqlmon01\SQLEXPRESS")]
|
|
[InlineData("sqlmon01.kunde.local,1433")]
|
|
public void Recognises_this_computer(string server) => Assert.True(ServiceAccounts.IsLocal(server, "SQLMON01"));
|
|
|
|
[Theory]
|
|
[InlineData("sql02")]
|
|
[InlineData(@"sql02\PROD")]
|
|
[InlineData("sqlmon011")]
|
|
[InlineData("tcp:10.0.0.5,1433")]
|
|
public void Recognises_other_computers(string server) => Assert.False(ServiceAccounts.IsLocal(server, "SQLMON01"));
|
|
|
|
[Fact]
|
|
public void Virtual_account_keeps_its_name_on_the_same_computer() =>
|
|
Assert.Equal(@"NT SERVICE\SQLInsight Agent", ServiceAccounts.LoginFor(@"NT SERVICE\SQLInsight Agent", @".\SQLEXPRESS", "SQLMON01", "KUNDE"));
|
|
|
|
[Theory]
|
|
[InlineData(@"NT SERVICE\SQLInsight Agent")]
|
|
[InlineData(@"NT AUTHORITY\NETWORK SERVICE")]
|
|
[InlineData("LocalSystem")]
|
|
public void Machine_accounts_arrive_as_the_computer_account_on_another_server(string account) =>
|
|
Assert.Equal(@"KUNDE\SQLMON01$", ServiceAccounts.LoginFor(account, "sql02", "SQLMON01", "KUNDE"));
|
|
|
|
[Fact]
|
|
public void Domain_accounts_and_gmsas_are_the_same_everywhere() =>
|
|
Assert.Equal(@"KUNDE\svc-sqlinsight$", ServiceAccounts.LoginFor(@"KUNDE\svc-sqlinsight$", "sql02", "SQLMON01", "KUNDE"));
|
|
|
|
[Fact]
|
|
public void Grant_script_takes_the_login_as_a_parameter()
|
|
{
|
|
var script = RepositorySetup.GrantScript();
|
|
|
|
Assert.Contains("SET @LoginName = @login;", script, StringComparison.Ordinal);
|
|
Assert.DoesNotContain("SET @LoginName = N'", script, StringComparison.Ordinal);
|
|
Assert.Contains("VIEW ANY DEFINITION", script, StringComparison.Ordinal);
|
|
}
|
|
}
|