@@ -43,91 +43,91 @@ public class OtlpMtlsCertificateManagerTests
43
43
[ Xunit . Fact ]
44
44
public void LoadClientCertificate_ThrowsFileNotFoundException_WhenCertificateFileDoesNotExist ( )
45
45
{
46
- var exception = Xunit . Assert . Throws < System . IO . FileNotFoundException > ( ( ) =>
47
- OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadClientCertificate (
46
+ var exception = Xunit . Assert . Throws < FileNotFoundException > ( ( ) =>
47
+ OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadClientCertificate (
48
48
"/nonexistent/client.crt" ,
49
49
"/nonexistent/client.key" ) ) ;
50
50
51
- Xunit . Assert . Contains ( "Certificate file not found" , exception . Message , System . StringComparison . OrdinalIgnoreCase ) ;
52
- Xunit . Assert . Contains ( "/nonexistent/client.crt" , exception . Message , System . StringComparison . OrdinalIgnoreCase ) ;
51
+ Xunit . Assert . Contains ( "Certificate file not found" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
52
+ Xunit . Assert . Contains ( "/nonexistent/client.crt" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
53
53
}
54
54
55
55
[ Xunit . Fact ]
56
56
public void LoadClientCertificate_ThrowsFileNotFoundException_WhenPrivateKeyFileDoesNotExist ( )
57
57
{
58
- var tempCertFile = System . IO . Path . GetTempFileName ( ) ;
59
- System . IO . File . WriteAllText ( tempCertFile , TestCertPem ) ;
58
+ var tempCertFile = Path . GetTempFileName ( ) ;
59
+ File . WriteAllText ( tempCertFile , TestCertPem ) ;
60
60
61
61
try
62
62
{
63
- var exception = Xunit . Assert . Throws < System . IO . FileNotFoundException > ( ( ) =>
64
- OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadClientCertificate (
63
+ var exception = Xunit . Assert . Throws < FileNotFoundException > ( ( ) =>
64
+ OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadClientCertificate (
65
65
tempCertFile ,
66
66
"/nonexistent/client.key" ) ) ;
67
67
68
- Xunit . Assert . Contains ( "Private key file not found" , exception . Message , System . StringComparison . OrdinalIgnoreCase ) ;
69
- Xunit . Assert . Contains ( "/nonexistent/client.key" , exception . Message , System . StringComparison . OrdinalIgnoreCase ) ;
68
+ Xunit . Assert . Contains ( "Private key file not found" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
69
+ Xunit . Assert . Contains ( "/nonexistent/client.key" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
70
70
}
71
71
finally
72
72
{
73
- System . IO . File . Delete ( tempCertFile ) ;
73
+ File . Delete ( tempCertFile ) ;
74
74
}
75
75
}
76
76
77
77
[ Xunit . Fact ]
78
78
public void LoadCaCertificate_ThrowsFileNotFoundException_WhenTrustStoreFileDoesNotExist ( )
79
79
{
80
- var exception = Xunit . Assert . Throws < System . IO . FileNotFoundException > ( ( ) =>
81
- OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadCaCertificate ( "/nonexistent/ca.crt" ) ) ;
80
+ var exception = Xunit . Assert . Throws < FileNotFoundException > ( ( ) =>
81
+ OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadCaCertificate ( "/nonexistent/ca.crt" ) ) ;
82
82
83
- Xunit . Assert . Contains ( "CA certificate file not found" , exception . Message , System . StringComparison . OrdinalIgnoreCase ) ;
84
- Xunit . Assert . Contains ( "/nonexistent/ca.crt" , exception . Message , System . StringComparison . OrdinalIgnoreCase ) ;
83
+ Xunit . Assert . Contains ( "CA certificate file not found" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
84
+ Xunit . Assert . Contains ( "/nonexistent/ca.crt" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
85
85
}
86
86
87
87
[ Xunit . Fact ]
88
88
public void LoadClientCertificate_ThrowsInvalidOperationException_WhenCertificateFileIsEmpty ( )
89
89
{
90
- var tempCertFile = System . IO . Path . GetTempFileName ( ) ;
91
- var tempKeyFile = System . IO . Path . GetTempFileName ( ) ;
92
- System . IO . File . WriteAllText ( tempCertFile , string . Empty ) ;
93
- System . IO . File . WriteAllText ( tempKeyFile , string . Empty ) ;
90
+ var tempCertFile = Path . GetTempFileName ( ) ;
91
+ var tempKeyFile = Path . GetTempFileName ( ) ;
92
+ File . WriteAllText ( tempCertFile , string . Empty ) ;
93
+ File . WriteAllText ( tempKeyFile , string . Empty ) ;
94
94
95
95
try
96
96
{
97
- var exception = Xunit . Assert . Throws < System . InvalidOperationException > ( ( ) =>
98
- OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadClientCertificate ( tempCertFile , tempKeyFile ) ) ;
97
+ var exception = Xunit . Assert . Throws < InvalidOperationException > ( ( ) =>
98
+ OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadClientCertificate ( tempCertFile , tempKeyFile ) ) ;
99
99
100
100
Xunit . Assert . Contains (
101
101
"Failed to load client certificate" ,
102
102
exception . Message ,
103
- System . StringComparison . OrdinalIgnoreCase ) ;
103
+ StringComparison . OrdinalIgnoreCase ) ;
104
104
}
105
105
finally
106
106
{
107
- System . IO . File . Delete ( tempCertFile ) ;
108
- System . IO . File . Delete ( tempKeyFile ) ;
107
+ File . Delete ( tempCertFile ) ;
108
+ File . Delete ( tempKeyFile ) ;
109
109
}
110
110
}
111
111
112
112
[ Xunit . Fact ]
113
113
public void LoadCaCertificate_ThrowsInvalidOperationException_WhenTrustStoreFileIsEmpty ( )
114
114
{
115
- var tempTrustStoreFile = System . IO . Path . GetTempFileName ( ) ;
116
- System . IO . File . WriteAllText ( tempTrustStoreFile , string . Empty ) ;
115
+ var tempTrustStoreFile = Path . GetTempFileName ( ) ;
116
+ File . WriteAllText ( tempTrustStoreFile , string . Empty ) ;
117
117
118
118
try
119
119
{
120
- var exception = Xunit . Assert . Throws < System . InvalidOperationException > ( ( ) =>
121
- OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadCaCertificate ( tempTrustStoreFile ) ) ;
120
+ var exception = Xunit . Assert . Throws < InvalidOperationException > ( ( ) =>
121
+ OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . LoadCaCertificate ( tempTrustStoreFile ) ) ;
122
122
123
123
Xunit . Assert . Contains (
124
124
"Failed to load CA certificate" ,
125
125
exception . Message ,
126
- System . StringComparison . OrdinalIgnoreCase ) ;
126
+ StringComparison . OrdinalIgnoreCase ) ;
127
127
}
128
128
finally
129
129
{
130
- System . IO . File . Delete ( tempTrustStoreFile ) ;
130
+ File . Delete ( tempTrustStoreFile ) ;
131
131
}
132
132
}
133
133
@@ -138,7 +138,7 @@ public void ValidateCertificateChain_DoesNotThrow_WithValidCertificate()
138
138
using var cert = CreateSelfSignedCertificate ( ) ;
139
139
140
140
// Should not throw for self-signed certificate with proper validation
141
- var result = OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . ValidateCertificateChain ( cert , "test certificate" ) ;
141
+ var result = OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . ValidateCertificateChain ( cert , "test certificate" ) ;
142
142
143
143
// For self-signed certificates, validation may fail, but method should not throw
144
144
Xunit . Assert . True ( result || ! result ) ; // Just check that it returns a boolean
@@ -150,13 +150,13 @@ public void ValidateCertificateChain_ThrowsInvalidOperationException_WhenCertifi
150
150
// Create an expired certificate for testing
151
151
using var cert = CreateExpiredCertificate ( ) ;
152
152
153
- var exception = Xunit . Assert . Throws < System . InvalidOperationException > ( ( ) =>
154
- OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . ValidateCertificateChain ( cert , "expired certificate" ) ) ;
153
+ var exception = Xunit . Assert . Throws < InvalidOperationException > ( ( ) =>
154
+ OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . ValidateCertificateChain ( cert , "expired certificate" ) ) ;
155
155
156
156
Xunit . Assert . Contains (
157
157
"Certificate chain validation failed" ,
158
158
exception . Message ,
159
- System . StringComparison . OrdinalIgnoreCase ) ;
159
+ StringComparison . OrdinalIgnoreCase ) ;
160
160
}
161
161
162
162
[ Xunit . Fact ]
@@ -166,7 +166,7 @@ public void ValidateCertificateChain_ReturnsResult_WithValidCertificate()
166
166
using var cert = CreateSelfSignedCertificate ( ) ;
167
167
168
168
// Should return a boolean result
169
- var result = OpenTelemetry . Exporter . OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . ValidateCertificateChain ( cert , "test certificate" ) ;
169
+ var result = OpenTelemetryProtocol . Implementation . OtlpMtlsCertificateManager . ValidateCertificateChain ( cert , "test certificate" ) ;
170
170
171
171
// The result can be true or false, but the method should not throw
172
172
Xunit . Assert . True ( result || ! result ) ;
@@ -182,8 +182,8 @@ private static System.Security.Cryptography.X509Certificates.X509Certificate2 Cr
182
182
System . Security . Cryptography . RSASignaturePadding . Pkcs1 ) ;
183
183
184
184
var cert = req . CreateSelfSigned (
185
- System . DateTimeOffset . UtcNow . AddDays ( - 1 ) ,
186
- System . DateTimeOffset . UtcNow . AddDays ( 30 ) ) ;
185
+ DateTimeOffset . UtcNow . AddDays ( - 1 ) ,
186
+ DateTimeOffset . UtcNow . AddDays ( 30 ) ) ;
187
187
return cert ;
188
188
}
189
189
@@ -198,8 +198,8 @@ private static System.Security.Cryptography.X509Certificates.X509Certificate2 Cr
198
198
199
199
// Create a certificate that expired yesterday
200
200
var cert = req . CreateSelfSigned (
201
- System . DateTimeOffset . UtcNow . AddDays ( - 30 ) ,
202
- System . DateTimeOffset . UtcNow . AddDays ( - 1 ) ) ;
201
+ DateTimeOffset . UtcNow . AddDays ( - 30 ) ,
202
+ DateTimeOffset . UtcNow . AddDays ( - 1 ) ) ;
203
203
return cert ;
204
204
}
205
205
}
0 commit comments