1- namespace Testcontainers . Elasticsearch ;
1+ namespace Testcontainers . Elasticsearch ;
22
33/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
44[ PublicAPI ]
@@ -138,7 +138,7 @@ public WaitUntil(ElasticsearchConfiguration configuration)
138138 public async Task < bool > UntilAsync ( IContainer container )
139139 {
140140 using var httpMessageHandler = new HttpClientHandler ( ) ;
141- httpMessageHandler . ServerCertificateCustomValidationCallback = ( _ , _ , _ , _ ) => true ;
141+ httpMessageHandler . ServerCertificateCustomValidationCallback = ( _ , _ , _ , _ ) => true ; // intentionally trusting the self‑signed test certificate
142142
143143 var httpWaitStrategy = new HttpWaitStrategy ( )
144144 . UsingHttpMessageHandler ( httpMessageHandler )
@@ -147,12 +147,19 @@ public async Task<bool> UntilAsync(IContainer container)
147147 . ForPort ( ElasticsearchHttpsPort )
148148 . ForStatusCode ( HttpStatusCode . OK )
149149 . WithHeader ( "Authorization" , "Basic " + _credentials )
150- . ForResponseMessageMatching ( async ( m ) =>
150+ . ForResponseMessageMatching ( async m =>
151151 {
152- var content = await m . Content . ReadAsStringAsync ( ) ;
153- var response = JsonSerializer . Deserialize < ElasticHealthResponse > ( content ) ;
154- return string . Equals ( ElasticHealthResponse . YellowStatus , response . Status , StringComparison . OrdinalIgnoreCase ) ||
155- string . Equals ( ElasticHealthResponse . GreenStatus , response . Status , StringComparison . OrdinalIgnoreCase ) ;
152+ var content = await m . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
153+ try
154+ {
155+ var response = JsonSerializer . Deserialize < ElasticHealthResponse > ( content ) ;
156+ return string . Equals ( ElasticHealthResponse . YellowStatus , response . Status , StringComparison . OrdinalIgnoreCase ) ||
157+ string . Equals ( ElasticHealthResponse . GreenStatus , response . Status , StringComparison . OrdinalIgnoreCase ) ;
158+ }
159+ catch ( JsonException )
160+ {
161+ return false ;
162+ }
156163 } ) ;
157164
158165 return await httpWaitStrategy . UntilAsync ( container )
@@ -165,7 +172,7 @@ private class ElasticHealthResponse
165172 public const string GreenStatus = "green" ;
166173
167174 [ JsonPropertyName ( "status" ) ]
168- public string Status { get ; set ; }
175+ public string Status { get ; set ; } = "unknown" ;
169176 }
170177 }
171178}
0 commit comments