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
30
+ import java.nio.file.Paths
28
31
import java.util.concurrent.Callable
29
32
import java.util.stream.Collectors
30
33
62
65
projectSubstitutions = [:]
63
66
licenseFile = rootProject. file(' LICENSE.TXT' )
64
67
noticeFile = rootProject. file(' NOTICE' )
68
+
69
+ getSecurityPluginDownloadLink = { ->
70
+ var repo = " https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/plugin/" +
71
+ " opensearch-security/$opensearch_build /"
72
+ var metadataFile = Paths . get(projectDir. toString(), " build" , " maven-metadata.xml" ). toAbsolutePath(). toFile()
73
+ download. run {
74
+ src repo + " maven-metadata.xml"
75
+ dest metadataFile
76
+ }
77
+ def metadata = new XmlParser (). parse(metadataFile)
78
+ def securitySnapshotVersion = metadata. versioning. snapshotVersions[0 ]. snapshotVersion[0 ]. value[0 ]. text()
79
+
80
+ return repo + " opensearch-security-${ securitySnapshotVersion} .zip"
81
+ }
82
+
83
+ File downloadedSecurityPlugin = null
84
+
85
+ configureSecurityPlugin = { OpenSearchCluster cluster ->
86
+
87
+ cluster. getNodes(). forEach { node ->
88
+ var creds = node. getCredentials()
89
+ if (creds. isEmpty()) {
90
+ creds. add(Map . of(' useradd' , ' admin' , ' -p' , ' admin' ))
91
+ } else {
92
+ creds. get(0 ). putAll(Map . of(' useradd' , ' admin' , ' -p' , ' admin' ))
93
+ }
94
+ }
95
+
96
+ var projectAbsPath = projectDir. getAbsolutePath()
97
+
98
+ // add a check to avoid re-downloading multiple times during single test run
99
+ if (downloadedSecurityPlugin == null ) {
100
+ downloadedSecurityPlugin = Paths . get(projectAbsPath, ' bin' , ' opensearch-security-snapshot.zip' ). toFile()
101
+ download. run {
102
+ src getSecurityPluginDownloadLink()
103
+ dest downloadedSecurityPlugin
104
+ }
105
+ }
106
+
107
+ // Config below including files are copied from security demo configuration
108
+ [' esnode.pem' , ' esnode-key.pem' , ' root-ca.pem' ]. forEach { file ->
109
+ File local = Paths . get(projectAbsPath, ' bin' , file). toFile()
110
+ download. run {
111
+ src " https://raw.githubusercontent.com/opensearch-project/security/main/bwc-test/src/test/resources/security/" + file
112
+ dest local
113
+ overwrite false
114
+ }
115
+ cluster. extraConfigFile file, local
116
+ }
117
+ [
118
+ // config copied from security plugin demo configuration
119
+ ' plugins.security.ssl.transport.pemcert_filepath' : ' esnode.pem' ,
120
+ ' plugins.security.ssl.transport.pemkey_filepath' : ' esnode-key.pem' ,
121
+ ' plugins.security.ssl.transport.pemtrustedcas_filepath' : ' root-ca.pem' ,
122
+ ' plugins.security.ssl.transport.enforce_hostname_verification' : ' false' ,
123
+ // https is disabled to simplify test debugging
124
+ ' plugins.security.ssl.http.enabled' : ' false' ,
125
+ ' plugins.security.ssl.http.pemcert_filepath' : ' esnode.pem' ,
126
+ ' plugins.security.ssl.http.pemkey_filepath' : ' esnode-key.pem' ,
127
+ ' plugins.security.ssl.http.pemtrustedcas_filepath' : ' root-ca.pem' ,
128
+ ' plugins.security.allow_unsafe_democertificates' : ' true' ,
129
+
130
+ ' plugins.security.allow_default_init_securityindex' : ' true' ,
131
+ ' plugins.security.authcz.admin_dn' : ' CN=kirk,OU=client,O=client,L=test,C=de' ,
132
+ ' plugins.security.audit.type' : ' internal_opensearch' ,
133
+ ' plugins.security.enable_snapshot_restore_privilege' : ' true' ,
134
+ ' plugins.security.check_snapshot_restore_write_privileges' : ' true' ,
135
+ ' plugins.security.restapi.roles_enabled' : ' ["all_access", "security_rest_api_access"]' ,
136
+ ' plugins.security.system_indices.enabled' : ' true'
137
+ ]. forEach { name , value ->
138
+ cluster. setting name, value
139
+ }
140
+
141
+ cluster. plugin provider((Callable<RegularFile > ) (() -> (RegularFile ) (() -> downloadedSecurityPlugin)))
142
+ }
65
143
}
66
144
67
145
tasks. withType(licenseHeaders. class) {
@@ -108,6 +186,7 @@ dependencies {
108
186
testImplementation group : ' com.h2database' , name : ' h2' , version : ' 2.2.220'
109
187
testImplementation group : ' org.xerial' , name : ' sqlite-jdbc' , version : ' 3.41.2.2'
110
188
testImplementation group : ' com.google.code.gson' , name : ' gson' , version : ' 2.8.9'
189
+ testCompileOnly ' org.apiguardian:apiguardian-api:1.1.2'
111
190
112
191
// Needed for BWC tests
113
192
zipArchive group : ' org.opensearch.plugin' , name :' opensearch-sql-plugin' , version : " ${ bwcVersion} -SNAPSHOT"
@@ -128,21 +207,28 @@ compileTestJava {
128
207
}
129
208
130
209
testClusters. all {
131
- testDistribution = ' archive'
132
-
133
210
// debug with command, ./gradlew opensearch-sql:run -DdebugJVM. --debug-jvm does not work with keystore.
134
211
if (System . getProperty(" debugJVM" ) != null ) {
135
212
jvmArgs ' -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'
136
213
}
137
214
}
138
215
139
- testClusters. integTest {
140
- plugin " :opensearch-sql-plugin"
141
- setting " plugins.query.datasources.encryption.masterkey" , " 1234567812345678"
142
- }
143
-
144
216
testClusters {
217
+ integTest {
218
+ testDistribution = ' archive'
219
+ plugin " :opensearch-sql-plugin"
220
+ setting " plugins.query.datasources.encryption.masterkey" , " 1234567812345678"
221
+ }
145
222
remoteCluster {
223
+ testDistribution = ' archive'
224
+ plugin " :opensearch-sql-plugin"
225
+ }
226
+ integTestWithSecurity {
227
+ testDistribution = ' archive'
228
+ plugin " :opensearch-sql-plugin"
229
+ }
230
+ remoteIntegTestWithSecurity {
231
+ testDistribution = ' archive'
146
232
plugin " :opensearch-sql-plugin"
147
233
}
148
234
}
@@ -223,6 +309,65 @@ task integJdbcTest(type: RestIntegTestTask) {
223
309
}
224
310
}
225
311
312
+ task integTestWithSecurity (type : RestIntegTestTask ) {
313
+ useCluster testClusters. integTestWithSecurity
314
+ useCluster testClusters. remoteIntegTestWithSecurity
315
+
316
+ systemProperty " cluster.names" ,
317
+ getClusters(). stream(). map(cluster -> cluster. getName()). collect(Collectors . joining(" ," ))
318
+
319
+ getClusters(). forEach { cluster ->
320
+ configureSecurityPlugin(cluster)
321
+ }
322
+
323
+ useJUnitPlatform()
324
+ dependsOn ' :opensearch-sql-plugin:bundlePlugin'
325
+ testLogging {
326
+ events " passed" , " skipped" , " failed"
327
+ }
328
+ afterTest { desc , result ->
329
+ logger. quiet " ${ desc.className} .${ desc.name} : ${ result.resultType} ${ (result.getEndTime() - result.getStartTime())/1000} s"
330
+ }
331
+
332
+ systemProperty ' tests.security.manager' , ' false'
333
+ systemProperty ' project.root' , project. projectDir. absolutePath
334
+
335
+ // Set default query size limit
336
+ systemProperty ' defaultQuerySizeLimit' , ' 10000'
337
+
338
+ // Tell the test JVM if the cluster JVM is running under a debugger so that tests can use longer timeouts for
339
+ // requests. The 'doFirst' delays reading the debug setting on the cluster till execution time.
340
+ doFirst {
341
+ systemProperty ' cluster.debug' , getDebug()
342
+ getClusters(). forEach { cluster ->
343
+
344
+ String allTransportSocketURI = cluster. nodes. stream(). flatMap { node ->
345
+ node. getAllTransportPortURI(). stream()
346
+ }. collect(Collectors . joining(" ," ))
347
+ String allHttpSocketURI = cluster. nodes. stream(). flatMap { node ->
348
+ node. getAllHttpSocketURI(). stream()
349
+ }. collect(Collectors . joining(" ," ))
350
+
351
+ systemProperty " tests.rest.${ cluster.name} .http_hosts" , " ${ -> allHttpSocketURI} "
352
+ systemProperty " tests.rest.${ cluster.name} .transport_hosts" , " ${ -> allTransportSocketURI} "
353
+ }
354
+
355
+ systemProperty " https" , " false"
356
+ systemProperty " user" , " admin"
357
+ systemProperty " password" , " admin"
358
+ }
359
+
360
+ if (System . getProperty(" test.debug" ) != null ) {
361
+ jvmArgs ' -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
362
+ }
363
+
364
+ // NOTE: this IT config discovers only junit5 (jupiter) tests.
365
+ // https://github.com/opensearch-project/sql/issues/1974
366
+ filter {
367
+ includeTestsMatching ' org.opensearch.sql.security.CrossClusterSearchIT'
368
+ }
369
+ }
370
+
226
371
// Run PPL ITs and new, legacy and comparison SQL ITs with new SQL engine enabled
227
372
integTest {
228
373
useCluster testClusters. remoteCluster
@@ -305,8 +450,8 @@ integTest {
305
450
// Exclude JDBC related tests
306
451
exclude ' org/opensearch/sql/jdbc/**'
307
452
308
- // Exclude this IT until running IT with security plugin enabled is ready
309
- exclude ' org/opensearch/sql/ppl/CrossClusterSearchIT.class '
453
+ // Exclude this IT, because they executed in another task (:integTestWithSecurity)
454
+ exclude ' org/opensearch/sql/security/** '
310
455
}
311
456
312
457
0 commit comments