5
5
using System . Collections . Generic ;
6
6
using System . IO ;
7
7
using System . Linq ;
8
- using System . Security . Cryptography ;
9
8
using System . Text ;
10
9
using System . Threading . Tasks ;
11
10
using Kerberos . NET . Configuration ;
12
11
using Kerberos . NET . Crypto ;
13
- using Kerberos . NET . Entities ;
14
12
using Kerberos . NET . Server ;
15
13
using Kerberos . NET . Logging ;
16
14
using Xunit . Abstractions ;
@@ -26,9 +24,12 @@ public class KerberosExecutor : IDisposable
26
24
private RemoteInvokeHandle ? _invokeHandle ;
27
25
private string ? _krb5Path ;
28
26
private string ? _keytabPath ;
27
+ private string ? _tracePath ;
29
28
private readonly List < FakeKerberosPrincipal > _servicePrincipals ;
29
+ private readonly ITestOutputHelper _testOutputHelper ;
30
30
31
- public static bool IsSupported { get ; } = OperatingSystem . IsLinux ( ) || OperatingSystem . IsMacOS ( ) ;
31
+ public static bool IsSupported { get ; } =
32
+ RemoteExecutor . IsSupported && ( OperatingSystem . IsLinux ( ) || OperatingSystem . IsMacOS ( ) ) ;
32
33
33
34
public const string DefaultAdminPassword = "PLACEHOLDERadmin." ;
34
35
@@ -47,7 +48,6 @@ public KerberosExecutor(ITestOutputHelper testOutputHelper, string realm)
47
48
_principalService = new FakePrincipalService ( realm ) ;
48
49
49
50
byte [ ] krbtgtPassword = new byte [ 16 ] ;
50
- //RandomNumberGenerator.Fill(krbtgtPassword);
51
51
52
52
var krbtgt = new FakeKerberosPrincipal ( PrincipalType . Service , "krbtgt" , realm , krbtgtPassword ) ;
53
53
_principalService . Add ( "krbtgt" , krbtgt ) ;
@@ -65,14 +65,34 @@ public KerberosExecutor(ITestOutputHelper testOutputHelper, string realm)
65
65
_kdcListener = new FakeKdcServer ( _options ) ;
66
66
_realm = realm ;
67
67
_servicePrincipals = new List < FakeKerberosPrincipal > ( ) ;
68
+ _testOutputHelper = testOutputHelper ;
68
69
}
69
70
70
71
public void Dispose ( )
71
72
{
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
+ }
76
96
}
77
97
78
98
public void AddService ( string name , string password = DefaultAdminPassword )
@@ -136,8 +156,11 @@ private async Task PrepareInvoke()
136
156
writer . Flush ( ) ;
137
157
}
138
158
159
+ _tracePath = Path . GetTempFileName ( ) ;
160
+
139
161
// Set environment variables for GSSAPI
140
162
Environment . SetEnvironmentVariable ( "KRB5_CONFIG" , _krb5Path ) ;
141
163
Environment . SetEnvironmentVariable ( "KRB5_KTNAME" , _keytabPath ) ;
164
+ Environment . SetEnvironmentVariable ( "KRB5_TRACE" , _tracePath ) ;
142
165
}
143
166
}
0 commit comments