File tree Expand file tree Collapse file tree
common/src/test/java/io/opentelemetry/exporter/internal
sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,4 +94,30 @@ void setSslContext_AlreadyExists_Throws() throws Exception {
9494 .isInstanceOf (IllegalStateException .class )
9595 .hasMessageContaining ("sslContext or trustManager has been previously configured" );
9696 }
97+
98+ @ Test
99+ void getEffectiveTrustManager_returnsConfiguredTrustManager ()
100+ throws CertificateEncodingException {
101+ helper .setTrustManagerFromCerts (serverTls .certificate ().getEncoded ());
102+
103+ assertThat (helper .getEffectiveTrustManager ()).isSameAs (helper .getTrustManager ());
104+ }
105+
106+ @ Test
107+ void getEffectiveTrustManager_returnsDefaultTrustManager () {
108+ assertThat (helper .getEffectiveTrustManager ()).isNotNull ();
109+ }
110+
111+ @ Test
112+ void getEffectiveTrustManager_returnsNullWhenSslContextConfigured () throws Exception {
113+ helper .setSslContext (
114+ SSLContext .getInstance ("TLS" ), TlsUtil .trustManager (serverTls .certificate ().getEncoded ()));
115+
116+ assertThat (helper .getEffectiveTrustManager ()).isNull ();
117+ }
118+
119+ @ Test
120+ void getSslContext_usesDefaultTrustManagerWhenUnset () {
121+ assertThat (helper .getSslContext ()).isNotNull ();
122+ }
97123}
Original file line number Diff line number Diff line change @@ -79,6 +79,11 @@ void generatePrivateKey_Invalid() {
7979 .hasMessage ("Unable to generate key from supported algorithms: [EC]" );
8080 }
8181
82+ @ Test
83+ void defaultTrustManager () {
84+ assertThatCode (TlsUtil ::defaultTrustManager ).doesNotThrowAnyException ();
85+ }
86+
8287 /**
8388 * Append <a href="https://datatracker.ietf.org/doc/html/rfc7468#section-5.2">explanatory text</a>
8489 * prefix and verify {@link TlsUtil#keyManager(byte[], byte[])} succeeds.
Original file line number Diff line number Diff line change 1717import java .util .concurrent .ThreadPoolExecutor ;
1818import java .util .concurrent .TimeUnit ;
1919import java .util .concurrent .atomic .AtomicReference ;
20+ import javax .net .ssl .SSLContext ;
2021import org .junit .jupiter .api .Test ;
2122
2223class OkHttpHttpSenderTest {
@@ -60,4 +61,27 @@ public int getContentLength() {
6061 return 0 ;
6162 }
6263 }
64+
65+ @ Test
66+ void constructor_usesDefaultTrustManagerWhenTrustManagerIsNull () throws Exception {
67+ SSLContext sslContext = SSLContext .getInstance ("TLS" );
68+ sslContext .init (null , null , null );
69+
70+ OkHttpHttpSender sender =
71+ new OkHttpHttpSender (
72+ URI .create ("https://localhost" ),
73+ "text/plain" ,
74+ null ,
75+ Duration .ofSeconds (10 ),
76+ Duration .ofSeconds (10 ),
77+ Collections ::emptyMap ,
78+ null ,
79+ null ,
80+ sslContext ,
81+ null ,
82+ null ,
83+ Long .MAX_VALUE );
84+
85+ assertThat (sender ).isNotNull ();
86+ }
6387}
You can’t perform that action at this time.
0 commit comments