Skip to content

Commit

Permalink
Test Fix | CertificateTests are only designed to run against localhos…
Browse files Browse the repository at this point in the history
…t SQL installs (#2219)
  • Loading branch information
David-Engel authored Nov 16, 2023
1 parent d30d9d1 commit 4f73355
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CertificateTest : IDisposable
// SlashInstance is used to override IPV4 and IPV6 defined about so it includes an instance name
private static string SlashInstanceName = "";

public string ForceEncryptionRegistryPath
private static string ForceEncryptionRegistryPath
{
get
{
Expand All @@ -61,10 +61,16 @@ public string ForceEncryptionRegistryPath

public CertificateTest()
{
string[] tokensByBackSlash = DataTestUtility.TCPConnectionString.Split('\\');
if (tokensByBackSlash.Length > 1)
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);
Assert.True(DataTestUtility.ParseDataSource(builder.DataSource, out string hostname, out _, out string instanceName));
if (!LocalHost.Equals(hostname, StringComparison.OrdinalIgnoreCase))
{
InstanceName = tokensByBackSlash[1].Split(';')[0];
return;
}

if (!string.IsNullOrEmpty(instanceName))
{
InstanceName = instanceName;
InstanceNamePrefix = "MSSQL$";
SlashInstanceName = $"\\{InstanceName}";
}
Expand All @@ -75,7 +81,18 @@ public CertificateTest()
_thumbprint = Environment.GetEnvironmentVariable(ThumbPrintEnvName, EnvironmentVariableTarget.Machine);
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))]
private static bool IsLocalHost()
{
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);
Assert.True(DataTestUtility.ParseDataSource(builder.DataSource, out string hostname, out _, out _));
return LocalHost.Equals(hostname, StringComparison.OrdinalIgnoreCase);
}

private static bool AreConnStringsSetup() => DataTestUtility.AreConnStringsSetup();
private static bool IsNotAzureServer() => DataTestUtility.IsNotAzureServer();
private static bool UseManagedSNIOnWindows() => DataTestUtility.UseManagedSNIOnWindows;

[ConditionalFact(nameof(AreConnStringsSetup), nameof(IsNotAzureServer), nameof(IsLocalHost))]
[PlatformSpecific(TestPlatforms.Windows)]
public void OpenningConnectionWithGoodCertificateTest()
{
Expand Down Expand Up @@ -104,7 +121,7 @@ public void OpenningConnectionWithGoodCertificateTest()

// Provided hostname in certificate are:
// localhost, FQDN, Loopback IPv4: 127.0.0.1, IPv6: ::1
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureServer))]
[ConditionalFact(nameof(AreConnStringsSetup), nameof(IsNotAzureServer), nameof(IsLocalHost))]
[PlatformSpecific(TestPlatforms.Windows)]
public void OpeningConnectionWitHNICTest()
{
Expand Down Expand Up @@ -148,7 +165,7 @@ public void OpeningConnectionWitHNICTest()
}

[ActiveIssue("26934")]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.UseManagedSNIOnWindows), nameof(DataTestUtility.IsNotAzureServer))]
[ConditionalFact(nameof(AreConnStringsSetup), nameof(UseManagedSNIOnWindows), nameof(IsNotAzureServer), nameof(IsLocalHost))]
[PlatformSpecific(TestPlatforms.Windows)]
public void RemoteCertificateNameMismatchErrorTest()
{
Expand Down

0 comments on commit 4f73355

Please sign in to comment.