@@ -12,10 +12,10 @@ export class OpenSearchContainer extends GenericContainer {
1212 private readonly username = "admin" ;
1313
1414 // HTTPS + Basic Auth wait strategy
15- private readonly defaultWaitStrategy = Wait . forHttp ( "/" , OPENSEARCH_HTTP_PORT )
16- . usingTls ( )
17- . allowInsecure ( )
18- . withBasicCredentials ( this . username , this . password ) ;
15+ private readonly defaultWaitStrategy = Wait . forHttp ( "/" , OPENSEARCH_HTTP_PORT ) . withBasicCredentials (
16+ this . username ,
17+ this . password
18+ ) ;
1919
2020 constructor ( image : string ) {
2121 super ( image ) ;
@@ -67,16 +67,21 @@ export class OpenSearchContainer extends GenericContainer {
6767 OPENSEARCH_INITIAL_ADMIN_PASSWORD : this . password ,
6868 } ) ;
6969
70+ if ( this . securityEnabled ) {
71+ this . defaultWaitStrategy . usingTls ( ) . allowInsecure ( ) ;
72+ }
73+
7074 const started = await super . start ( ) ;
71- return new StartedOpenSearchContainer ( started , this . username , this . password ) ;
75+ return new StartedOpenSearchContainer ( started , this . username , this . password , this . securityEnabled ) ;
7276 }
7377}
7478
7579export class StartedOpenSearchContainer extends AbstractStartedContainer {
7680 constructor (
7781 override readonly startedTestContainer : StartedTestContainer ,
7882 private readonly username : string ,
79- private readonly password : string
83+ private readonly password : string ,
84+ private readonly securityEnabled : boolean
8085 ) {
8186 super ( startedTestContainer ) ;
8287 }
@@ -86,9 +91,14 @@ export class StartedOpenSearchContainer extends AbstractStartedContainer {
8691 return this . getMappedPort ( OPENSEARCH_HTTP_PORT ) ;
8792 }
8893
94+ /** Get the URL schema needed for connecting to this container */
95+ public getSchema ( ) : string {
96+ return this . securityEnabled ? "https" : "http" ;
97+ }
98+
8999 /** HTTPS endpoint URL */
90100 public getHttpUrl ( ) : string {
91- return `https ://${ this . getHost ( ) } :${ this . getPort ( ) } ` ;
101+ return `${ this . getSchema ( ) } ://${ this . getHost ( ) } :${ this . getPort ( ) } ` ;
92102 }
93103
94104 /** Admin username (always 'admin' by default) */
0 commit comments