File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed
src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation
test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ internal static class OtlpMtlsHttpClientFactory
1818 /// <param name="mtlsOptions">The mTLS configuration options.</param>
1919 /// <param name="configureClient">Optional action to configure the client.</param>
2020 /// <returns>An HttpClient configured for mTLS.</returns>
21+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="mtlsOptions"/> is null.</exception>
22+ /// <exception cref="InvalidOperationException">Thrown when mTLS is not enabled.</exception>
2123 public static HttpClient CreateMtlsHttpClient (
2224 OtlpMtlsOptions mtlsOptions ,
2325 Action < HttpClient > ? configureClient = null )
@@ -26,9 +28,9 @@ public static HttpClient CreateMtlsHttpClient(
2628
2729 if ( ! mtlsOptions . IsEnabled )
2830 {
29- var client = new HttpClient ( ) ;
30- configureClient ? . Invoke ( client ) ;
31- return client ;
31+ throw new InvalidOperationException (
32+ "mTLS options must include a client or CA certificate path."
33+ ) ;
3234 }
3335
3436 HttpClientHandler ? handler = null ;
Original file line number Diff line number Diff line change @@ -13,14 +13,12 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests;
1313public class OtlpMtlsHttpClientFactoryTests
1414{
1515 [ Fact ]
16- public void CreateHttpClient_ReturnsHttpClient_WhenMtlsIsDisabled ( )
16+ public void CreateHttpClient_ThrowsInvalidOperationException_WhenMtlsIsDisabled ( )
1717 {
1818 var options = new OtlpMtlsOptions ( ) ; // Disabled by default
1919
20- using var httpClient = OpenTelemetryProtocol . Implementation . OtlpMtlsHttpClientFactory . CreateMtlsHttpClient ( options ) ;
21-
22- Assert . NotNull ( httpClient ) ;
23- Assert . IsType < HttpClient > ( httpClient ) ;
20+ Assert . Throws < InvalidOperationException > ( ( ) =>
21+ OpenTelemetryProtocol . Implementation . OtlpMtlsHttpClientFactory . CreateMtlsHttpClient ( options ) ) ;
2422 }
2523
2624 [ Fact ]
You can’t perform that action at this time.
0 commit comments