Skip to content

Commit 353b0fa

Browse files
committed
184: Added security tests. Extended gradle file. Resolved 500 issue once opensearch status exception is raised
Signed-off-by: Stevan Buzejic <buzejic.stevan@gmail.com>
1 parent 072d2b7 commit 353b0fa

File tree

5 files changed

+640
-253
lines changed

5 files changed

+640
-253
lines changed

build.gradle

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.util.concurrent.Callable
1010
import java.util.concurrent.TimeUnit
1111
import java.util.function.Predicate
1212

13+
1314
buildscript {
1415
ext {
1516
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
@@ -20,19 +21,16 @@ buildscript {
2021
opensearch_build = version_tokens[0] + '.0'
2122
job_scheduler_no_snapshot = opensearch_build
2223
notifications_no_snapshot = opensearch_build
23-
security_no_snapshot = opensearch_build
2424
if (buildVersionQualifier) {
2525
opensearch_build += "-${buildVersionQualifier}"
2626
job_scheduler_no_snapshot += "-${buildVersionQualifier}"
2727
notifications_no_snapshot += "-${buildVersionQualifier}"
28-
security_no_snapshot = "-${buildVersionQualifier}"
2928
}
3029
if (isSnapshot) {
3130
opensearch_build += "-SNAPSHOT"
3231
}
33-
opensearch_no_snapshot = opensearch_version.replace("-SNAPSHOT", "")
32+
opensearch_no_snapshot = opensearch_version.replace("-SNAPSHOT","")
3433
job_scheduler_resource_folder = "src/test/resources/job-scheduler"
35-
security_resource_folder = "src/test/resources/security"
3634

3735
notifications_resource_folder = "src/test/resources/notifications"
3836
notifications_core_resource_folder = "src/test/resources/notifications-core"
@@ -41,9 +39,6 @@ buildscript {
4139
job_scheduler_version = System.getProperty("job_scheduler_version.version", opensearch_build)
4240
job_scheduler_build_download = 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/' + opensearch_no_snapshot +
4341
'/latest/linux/x64/tar/builds/opensearch/plugins/opensearch-job-scheduler-' + job_scheduler_no_snapshot + '.zip'
44-
security_version = System.getProperty("security.version", opensearch_build)
45-
secuirty_build_download = 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/' + opensearch_no_snapshot +
46-
'/latest/linux/x64/tar/builds/opensearch/plugins/opensearch-security-' + security_no_snapshot + '.zip'
4742
notifications_version = System.getProperty("notifications.version", opensearch_build)
4843
notifications_build_download = 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/' + opensearch_no_snapshot +
4944
'/latest/linux/x64/tar/builds/opensearch/plugins/opensearch-notifications-' + notifications_no_snapshot + '.zip'
@@ -276,6 +271,7 @@ afterEvaluate {
276271
node.setting("plugins.security.check_snapshot_restore_write_privileges", "true")
277272
node.setting("plugins.security.restapi.roles_enabled", "[\"all_access\", \"security_rest_api_access\"]")
278273
node.setting("plugins.security.system_indices.enabled", "true")
274+
// node.setting("plugins.security.system_indices.indices", "[\".opendistro-ism-config\"]")
279275
}
280276
}
281277
}
@@ -311,7 +307,7 @@ testClusters.integTest {
311307
}
312308
}
313309

314-
plugin(provider(new Callable<RegularFile>() {
310+
plugin(provider(new Callable<RegularFile>(){
315311
@Override
316312
RegularFile call() throws Exception {
317313
return new RegularFile() {
@@ -330,7 +326,7 @@ testClusters.integTest {
330326
}
331327
}))
332328

333-
plugin(provider(new Callable<RegularFile>() {
329+
plugin(provider(new Callable<RegularFile>(){
334330
@Override
335331
RegularFile call() throws Exception {
336332
return new RegularFile() {
@@ -349,7 +345,7 @@ testClusters.integTest {
349345
}
350346
}))
351347

352-
plugin(provider(new Callable<RegularFile>() {
348+
plugin(provider(new Callable<RegularFile>(){
353349
@Override
354350
RegularFile call() throws Exception {
355351
return new RegularFile() {
@@ -369,25 +365,10 @@ testClusters.integTest {
369365
}))
370366

371367
if (securityEnabled) {
372-
plugin(provider(new Callable<RegularFile>() {
373-
@Override
374-
RegularFile call() throws Exception {
375-
return new RegularFile() {
376-
@Override
377-
File getAsFile() {
378-
if (new File("$project.rootDir/$security_resource_folder/opensearch-security-$security_no_snapshot" + ".zip").exists()) {
379-
project.delete(files("$project.rootDir/$security_resource_folder/opensearch-security-$security_no_snapshot" + ".zip"))
380-
}
381-
if (new File("$project.rootDir/$security_resource_folder").exists() == false) {
382-
project.mkdir security_resource_folder
383-
}
384-
385-
ant.get(src: secuirty_build_download,
386-
dest: security_resource_folder,
387-
httpusecaches: false)
388-
return fileTree(security_resource_folder) { include "opensearch-security*" }.getSingleFile()
389-
}
390-
}
368+
plugin(provider({
369+
new RegularFile() {
370+
@Override
371+
File getAsFile() { fileTree("src/test/resources/security") { include "opensearch-security*" }.getSingleFile() }
391372
}
392373
}))
393374
}
@@ -433,20 +414,13 @@ integTest {
433414
}
434415
}
435416

436-
// run the test only if security is enabled
437-
if (!securityEnabled) {
438-
filter {
439-
excludeTestsMatching "org.opensearch.indexmanagement.SecurityBehaviorIT"
440-
}
441-
}
442-
443417
// TODO: raise issue in Core, this is because of the test framework
444418
if (System.getProperty("tests.clustername") != null) {
445419
exclude 'org/opensearch/indexmanagement/indexstatemanagement/MetadataRegressionIT.class'
446420
}
447421
}
448422

449-
task integTestRemote(type: RestIntegTestTask) {
423+
task integTestRemote(type: RestIntegTestTask) {
450424
testClassesDirs = sourceSets.test.output.classesDirs
451425
classpath = sourceSets.test.runtimeClasspath
452426
systemProperty 'tests.security.manager', 'false'
@@ -471,6 +445,12 @@ task integTestRemote(type: RestIntegTestTask) {
471445
excludeTestsMatching "org.opensearch.indexmanagement.indexstatemanagement.action.NotificationActionIT"
472446
}
473447
}
448+
449+
if (System.getProperty("tests.rest.bwcsuite") == null) {
450+
filter {
451+
excludeTestsMatching "org.opensearch.indexmanagement.bwc.*IT"
452+
}
453+
}
474454
// Snapshot action integration tests rely on node level setting path.repo which we can't set remotely
475455
exclude 'org/opensearch/indexmanagement/indexstatemanagement/action/SnapshotActionIT.class'
476456
}
@@ -492,13 +472,13 @@ String bwc_im_download_url = "https://github.com/opendistro-for-elasticsearch/in
492472
bwcVersion + "/index-management-artifacts.zip"
493473
getPluginResource(bwc_im_resource_location, bwc_im_download_url)
494474

495-
2.times { i ->
475+
2.times {i ->
496476
testClusters {
497477
"${baseName}$i" {
498478
testDistribution = "ARCHIVE"
499479
versions = ["7.10.2", opensearch_version]
500480
numberOfNodes = 3
501-
plugin(provider(new Callable<RegularFile>() {
481+
plugin(provider(new Callable<RegularFile>(){
502482
@Override
503483
RegularFile call() throws Exception {
504484
return new RegularFile() {
@@ -510,7 +490,7 @@ getPluginResource(bwc_im_resource_location, bwc_im_download_url)
510490
}
511491
}))
512492

513-
plugin(provider(new Callable<RegularFile>() {
493+
plugin(provider(new Callable<RegularFile>(){
514494
@Override
515495
RegularFile call() throws Exception {
516496
return new RegularFile() {
@@ -537,7 +517,7 @@ task prepareBwcTests {
537517
// Download the job scheduler test dependency
538518
getPluginResource(job_scheduler_resource_folder, job_scheduler_build_download)
539519
plugins = [
540-
provider(new Callable<RegularFile>() {
520+
provider(new Callable<RegularFile>(){
541521
@Override
542522
RegularFile call() throws Exception {
543523
return new RegularFile() {
@@ -554,7 +534,7 @@ task prepareBwcTests {
554534
}
555535

556536
// Create two test clusters with 3 nodes of the old version
557-
2.times { i ->
537+
2.times {i ->
558538
task "${baseName}#oldVersionClusterTask$i"(type: StandaloneRestIntegTestTask) {
559539
dependsOn 'prepareBwcTests'
560540
useCluster testClusters."${baseName}$i"
@@ -695,13 +675,6 @@ testClusters.mixedCluster {
695675
}
696676
}))
697677

698-
node.plugin(provider({
699-
new RegularFile() {
700-
@Override
701-
File getAsFile() { fileTree(security_resource_folder).getSingleFile() }
702-
}
703-
}))
704-
705678
node.plugin(provider({
706679
new RegularFile() {
707680
@Override

src/main/kotlin/org/opensearch/indexmanagement/util/IndexManagementException.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.indexmanagement.util
77

88
import org.opensearch.OpenSearchException
9+
import org.opensearch.OpenSearchStatusException
910
import org.opensearch.common.Strings
1011
import org.opensearch.common.ValidationException
1112
import org.opensearch.index.IndexNotFoundException
@@ -37,6 +38,10 @@ class IndexManagementException(message: String, val status: RestStatus, ex: Exce
3738
status = RestStatus.BAD_REQUEST
3839
friendlyMsg = ex.message as String
3940
}
41+
is OpenSearchStatusException -> {
42+
status = ex.status()
43+
friendlyMsg = ex.message as String
44+
}
4045
else -> {
4146
if (!Strings.isNullOrEmpty(ex.message)) {
4247
friendlyMsg = ex.message as String
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.indexmanagement
7+
8+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.explain.ExplainAction
9+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.getpolicy.GetPoliciesAction
10+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.getpolicy.GetPolicyAction
11+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.indexpolicy.IndexPolicyAction
12+
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexAction
13+
import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupAction
14+
import org.opensearch.indexmanagement.rollup.action.get.GetRollupAction
15+
import org.opensearch.indexmanagement.rollup.action.index.IndexRollupAction
16+
17+
const val WRITE_POLICY = IndexPolicyAction.NAME
18+
const val GET_POLICIES = GetPoliciesAction.NAME
19+
const val GET_POLICY = GetPolicyAction.NAME
20+
const val EXPLAIN_INDEX = ExplainAction.NAME
21+
const val MANAGED_INDEX = ManagedIndexAction.NAME
22+
const val ROLLUP_ALL = "cluster:admin/opendistro/rollup/*"
23+
const val INDEX_ROLLUP = IndexRollupAction.NAME
24+
const val GET_ROLLUP = GetRollupAction.NAME
25+
const val EXPLAIN_ROLLUP = ExplainRollupAction.NAME
26+
27+
// Index related
28+
const val GET_INDEX = "indices:admin/mappings/get"
29+
const val SEARCH_INDEX = "indices:data/read/search"

0 commit comments

Comments
 (0)