24
24
25
25
import org.opensearch.gradle.test.RestIntegTestTask
26
26
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask
27
+ import org.opensearch.gradle.testclusters.OpenSearchCluster
27
28
29
+ import groovy.xml.XmlParser
28
30
import java.nio.file.Paths
29
- import java.time.LocalDateTime
30
31
import java.util.concurrent.Callable
31
32
import java.util.stream.Collectors
32
- import groovy.xml.XmlParser
33
33
34
34
plugins {
35
35
id " de.undercouch.download" version " 5.3.0"
74
74
75
75
return repo + " opensearch-security-${ securitySnapshotVersion} .zip"
76
76
}
77
+
78
+ File downloadedSecurityPlugin = null
79
+
80
+ configureSecurityPlugin = { OpenSearchCluster cluster ->
81
+
82
+ cluster. getNodes(). forEach { node ->
83
+ node. getCredentials(). add(Map . of(' useradd' , ' admin' , ' -p' , ' admin' ))
84
+ }
85
+
86
+ var projectAbsPath = projectDir. getAbsolutePath()
87
+
88
+ // add a check to avoid re-downloading multiple times during single test run
89
+ if (downloadedSecurityPlugin == null ) {
90
+ downloadedSecurityPlugin = Paths . get(projectAbsPath, ' bin' , ' opensearch-security-snapshot.zip' ). toFile()
91
+ download. run {
92
+ src getSecurityPluginDownloadLink()
93
+ dest downloadedSecurityPlugin
94
+ }
95
+ }
96
+
97
+ // Config below including files are copied from security demo configuration
98
+ [' esnode.pem' , ' esnode-key.pem' , ' root-ca.pem' ]. forEach { file ->
99
+ File local = Paths . get(projectAbsPath, ' bin' , file). toFile()
100
+ download. run {
101
+ src " https://raw.githubusercontent.com/opensearch-project/security/main/bwc-test/src/test/resources/security/" + file
102
+ dest local
103
+ overwrite false
104
+ }
105
+ cluster. extraConfigFile file, local
106
+ }
107
+ [
108
+ ' plugins.security.ssl.transport.pemcert_filepath' : ' esnode.pem' ,
109
+ ' plugins.security.ssl.transport.pemkey_filepath' : ' esnode-key.pem' ,
110
+ ' plugins.security.ssl.transport.pemtrustedcas_filepath' : ' root-ca.pem' ,
111
+ ' plugins.security.ssl.transport.enforce_hostname_verification' : ' false' ,
112
+ // https is disabled : because `OpenSearchCluster` is hardcoded to validate cluster health by http
113
+ // refer how IT framework implemented in security plugin and reuse/copy to activate https
114
+ ' plugins.security.ssl.http.enabled' : ' false' ,
115
+ ' plugins.security.ssl.http.pemcert_filepath' : ' esnode.pem' ,
116
+ ' plugins.security.ssl.http.pemkey_filepath' : ' esnode-key.pem' ,
117
+ ' plugins.security.ssl.http.pemtrustedcas_filepath' : ' root-ca.pem' ,
118
+ ' plugins.security.allow_unsafe_democertificates' : ' true' ,
119
+
120
+ ' plugins.security.allow_default_init_securityindex' : ' true' ,
121
+ // 'plugins.security.authcz.admin_dn' : 'CN=kirk,OU=client,O=client,L=test,C=de',
122
+ ' plugins.security.authcz.admin_dn' : ' CN=admin,OU=SSL,O=Test,L=Test,C=DE' ,
123
+ ' plugins.security.audit.type' : ' internal_opensearch' ,
124
+ ' plugins.security.enable_snapshot_restore_privilege' : ' true' ,
125
+ ' plugins.security.check_snapshot_restore_write_privileges' : ' true' ,
126
+ ' plugins.security.restapi.roles_enabled' : ' ["all_access", "security_rest_api_access"]' ,
127
+ ' plugins.security.system_indices.enabled' : ' true'
128
+ ]. forEach { name , value ->
129
+ cluster. setting name, value
130
+ }
131
+
132
+ cluster. plugin provider((Callable<RegularFile > ) (() -> (RegularFile ) (() -> downloadedSecurityPlugin)))
133
+ }
77
134
}
78
135
79
136
tasks. withType(licenseHeaders. class) {
@@ -142,73 +199,23 @@ compileTestJava {
142
199
143
200
testClusters. all {
144
201
testDistribution = ' archive'
202
+ plugin " :opensearch-sql-plugin"
145
203
146
204
// debug with command, ./gradlew opensearch-sql:run -DdebugJVM. --debug-jvm does not work with keystore.
147
205
if (System . getProperty(" debugJVM" ) != null ) {
148
206
jvmArgs ' -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'
149
207
}
150
208
}
151
209
152
- testClusters. integTest {
153
- plugin " :opensearch-sql-plugin"
154
- setting " plugins.query.datasources.encryption.masterkey" , " 1234567812345678"
155
- }
156
-
157
- File downloadedSecurityPlugin = null
158
-
159
210
testClusters {
211
+ integTest {
212
+ setting " plugins.query.datasources.encryption.masterkey" , " 1234567812345678"
213
+ }
160
214
remoteCluster {
161
- plugin " :opensearch-sql-plugin"
162
215
}
163
- integTestWithSecurity { // OpenSearchCluster
164
-
165
- getNodes(). forEach { node ->
166
- node. getCredentials(). add(Map . of(' useradd' , ' admin' , ' -p' , ' admin' ))
167
- }
168
-
169
- var projectAbsPath = projectDir. getAbsolutePath()
170
-
171
- // add a check to avoid re-downloading multiple times during single test run
172
- if (downloadedSecurityPlugin == null ) {
173
- downloadedSecurityPlugin = Paths . get(projectAbsPath, ' bin' , ' opensearch-security-snapshot.zip' ). toFile()
174
- download. run {
175
- src getSecurityPluginDownloadLink()
176
- dest downloadedSecurityPlugin
177
- }
178
- }
179
-
180
- // Config below including files are copied from security demo configuration
181
- [' esnode.pem' , ' esnode-key.pem' , ' root-ca.pem' ]. forEach { file ->
182
- File local = Paths . get(projectAbsPath, ' bin' , file). toFile()
183
- download. run {
184
- src " https://raw.githubusercontent.com/opensearch-project/security/main/bwc-test/src/test/resources/security/" + file
185
- dest local
186
- overwrite false
187
- }
188
- extraConfigFile file, local
189
- }
190
- setting ' plugins.security.ssl.transport.pemcert_filepath' , ' esnode.pem'
191
- setting ' plugins.security.ssl.transport.pemkey_filepath' , ' esnode-key.pem'
192
- setting ' plugins.security.ssl.transport.pemtrustedcas_filepath' , ' root-ca.pem'
193
- setting ' plugins.security.ssl.transport.enforce_hostname_verification' , ' false'
194
- // https is disabled, because `OpenSearchCluster` is hardcoded to validate cluster health by http
195
- // refer how IT framework implemented in security plugin and reuse/copy to activate https
196
- setting ' plugins.security.ssl.http.enabled' , ' false'
197
- setting ' plugins.security.ssl.http.pemcert_filepath' , ' esnode.pem'
198
- setting ' plugins.security.ssl.http.pemkey_filepath' , ' esnode-key.pem'
199
- setting ' plugins.security.ssl.http.pemtrustedcas_filepath' , ' root-ca.pem'
200
- setting ' plugins.security.allow_unsafe_democertificates' , ' true'
201
-
202
- setting ' plugins.security.allow_default_init_securityindex' , ' true'
203
- setting ' plugins.security.authcz.admin_dn' , ' CN=admin,OU=SSL,O=Test,L=Test,C=DE' // 'CN=kirk,OU=client,O=client,L=test, C=de'
204
- setting ' plugins.security.audit.type' , ' internal_opensearch'
205
- setting ' plugins.security.enable_snapshot_restore_privilege' , ' true'
206
- setting ' plugins.security.check_snapshot_restore_write_privileges' , ' true'
207
- setting ' plugins.security.restapi.roles_enabled' , ' ["all_access", "security_rest_api_access"]'
208
- setting ' plugins.security.system_indices.enabled' , ' true'
209
-
210
- plugin " :opensearch-sql-plugin"
211
- plugin provider((Callable<RegularFile > ) (() -> (RegularFile ) (() -> downloadedSecurityPlugin)))
216
+ integTestWithSecurity {
217
+ }
218
+ anotherintegTestWithSecurity {
212
219
}
213
220
}
214
221
@@ -290,6 +297,15 @@ task integJdbcTest(type: RestIntegTestTask) {
290
297
291
298
task integTestWithSecurity (type : RestIntegTestTask ) {
292
299
useCluster testClusters. integTestWithSecurity
300
+ useCluster testClusters. anotherintegTestWithSecurity
301
+
302
+ // Don't use `getClusters`: cluster order is important. IT framework adds/uses a cluster
303
+ // named as the task as default and uses it to init default REST client
304
+ systemProperty " cluster.names" , " integTestWithSecurity,anotherintegTestWithSecurity"
305
+
306
+ getClusters(). forEach { cluster ->
307
+ configureSecurityPlugin(cluster)
308
+ }
293
309
294
310
useJUnitPlatform()
295
311
dependsOn ' :opensearch-sql-plugin:bundlePlugin'
@@ -311,6 +327,7 @@ task integTestWithSecurity(type: RestIntegTestTask) {
311
327
doFirst {
312
328
systemProperty ' cluster.debug' , getDebug()
313
329
getClusters(). forEach { cluster ->
330
+
314
331
String allTransportSocketURI = cluster. nodes. stream(). flatMap { node ->
315
332
node. getAllTransportPortURI(). stream()
316
333
}. collect(Collectors . joining(" ," ))
@@ -320,13 +337,11 @@ task integTestWithSecurity(type: RestIntegTestTask) {
320
337
321
338
systemProperty " tests.rest.${ cluster.name} .http_hosts" , " ${ -> allHttpSocketURI} "
322
339
systemProperty " tests.rest.${ cluster.name} .transport_hosts" , " ${ -> allTransportSocketURI} "
323
- systemProperty " tests.rest.remoteCluster.http_hosts" , " ${ -> allHttpSocketURI} "
324
- systemProperty " tests.rest.remoteCluster.transport_hosts" , " ${ -> allTransportSocketURI} "
325
-
326
- systemProperty " https" , " false"
327
- systemProperty " user" , " admin"
328
- systemProperty " password" , " admin"
329
340
}
341
+
342
+ systemProperty " https" , " false"
343
+ systemProperty " user" , " admin"
344
+ systemProperty " password" , " admin"
330
345
}
331
346
332
347
if (System . getProperty(" test.debug" ) != null ) {
0 commit comments