Skip to content

Commit bf362e8

Browse files
authored
Guard Kerberos test with RemoteExecutor.IsSupported (#73362)
1 parent ef57797 commit bf362e8

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/libraries/Common/tests/System/Net/Security/Kerberos/KerberosExecutor.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using System.Security.Cryptography;
98
using System.Text;
109
using System.Threading.Tasks;
1110
using Kerberos.NET.Configuration;
1211
using Kerberos.NET.Crypto;
13-
using Kerberos.NET.Entities;
1412
using Kerberos.NET.Server;
1513
using Kerberos.NET.Logging;
1614
using Xunit.Abstractions;
@@ -26,9 +24,12 @@ public class KerberosExecutor : IDisposable
2624
private RemoteInvokeHandle? _invokeHandle;
2725
private string? _krb5Path;
2826
private string? _keytabPath;
27+
private string? _tracePath;
2928
private readonly List<FakeKerberosPrincipal> _servicePrincipals;
29+
private readonly ITestOutputHelper _testOutputHelper;
3030

31-
public static bool IsSupported { get; } = OperatingSystem.IsLinux() || OperatingSystem.IsMacOS();
31+
public static bool IsSupported { get; } =
32+
RemoteExecutor.IsSupported && (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS());
3233

3334
public const string DefaultAdminPassword = "PLACEHOLDERadmin.";
3435

@@ -47,7 +48,6 @@ public KerberosExecutor(ITestOutputHelper testOutputHelper, string realm)
4748
_principalService = new FakePrincipalService(realm);
4849

4950
byte[] krbtgtPassword = new byte[16];
50-
//RandomNumberGenerator.Fill(krbtgtPassword);
5151

5252
var krbtgt = new FakeKerberosPrincipal(PrincipalType.Service, "krbtgt", realm, krbtgtPassword);
5353
_principalService.Add("krbtgt", krbtgt);
@@ -65,14 +65,34 @@ public KerberosExecutor(ITestOutputHelper testOutputHelper, string realm)
6565
_kdcListener = new FakeKdcServer(_options);
6666
_realm = realm;
6767
_servicePrincipals = new List<FakeKerberosPrincipal>();
68+
_testOutputHelper = testOutputHelper;
6869
}
6970

7071
public void Dispose()
7172
{
72-
_invokeHandle?.Dispose();
73-
_kdcListener.Stop();
74-
File.Delete(_krb5Path);
75-
File.Delete(_keytabPath);
73+
try
74+
{
75+
_invokeHandle?.Dispose();
76+
}
77+
catch (Exception)
78+
{
79+
try
80+
{
81+
_testOutputHelper.WriteLine("GSSAPI trace:");
82+
_testOutputHelper.WriteLine(File.ReadAllText(_tracePath));
83+
}
84+
catch (IOException)
85+
{
86+
}
87+
throw;
88+
}
89+
finally
90+
{
91+
_kdcListener.Stop();
92+
File.Delete(_tracePath);
93+
File.Delete(_krb5Path);
94+
File.Delete(_keytabPath);
95+
}
7696
}
7797

7898
public void AddService(string name, string password = DefaultAdminPassword)
@@ -136,8 +156,11 @@ private async Task PrepareInvoke()
136156
writer.Flush();
137157
}
138158

159+
_tracePath = Path.GetTempFileName();
160+
139161
// Set environment variables for GSSAPI
140162
Environment.SetEnvironmentVariable("KRB5_CONFIG", _krb5Path);
141163
Environment.SetEnvironmentVariable("KRB5_KTNAME", _keytabPath);
164+
Environment.SetEnvironmentVariable("KRB5_TRACE", _tracePath);
142165
}
143166
}

0 commit comments

Comments
 (0)