From f93e7ebf8bf5f79a40891a5918bf78d20bf422bf Mon Sep 17 00:00:00 2001 From: Petar Dzepina Date: Wed, 17 May 2023 21:37:21 +0200 Subject: [PATCH] test tweak Signed-off-by: Petar Dzepina --- .../IndexStateManagementSecurityBehaviorIT.kt | 2 +- .../indexmanagement/PolicySecurityBehaviorIT.kt | 7 ++----- .../indexmanagement/SecurityRestTestCase.kt | 12 ++++++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt index 18fbd72ba..7966222c6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/IndexStateManagementSecurityBehaviorIT.kt @@ -43,7 +43,7 @@ import java.util.Locale class IndexStateManagementSecurityBehaviorIT : SecurityRestTestCase() { private val testIndexName = javaClass.simpleName.lowercase(Locale.ROOT) - private val password = "Test123!" + private val password = "Test123sdfsdfds435346FDGDFGDFG2342&^%#$@#35!" private val superIsmUser = "john" private var superUserClient: RestClient? = null diff --git a/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt index 5a67f91dc..5af30a616 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/PolicySecurityBehaviorIT.kt @@ -23,7 +23,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.model.State import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification import org.opensearch.indexmanagement.indexstatemanagement.transport.action.addpolicy.AddPolicyAction -import org.opensearch.rest.RestRequest import org.opensearch.rest.RestStatus import org.opensearch.test.OpenSearchTestCase import org.opensearch.test.junit.annotations.TestLogging @@ -110,10 +109,8 @@ class PolicySecurityBehaviorIT : SecurityRestTestCase() { refreshAllIndices() - val searchResponse = responseAsMap(client().makeRequest(RestRequest.Method.GET.toString(), "$INDEX_MANAGEMENT_INDEX/_search?size=1000")) - val numOfHits = ((searchResponse["hits"] as Map<*, *>)["total"] as Map<*, *>)["value"] as Int - // 1 Policy document + 5 ManagedIndex docs - assertEquals(1 + 5, numOfHits) + val explainResponseAsMap = managedIndexExplainAllAsMap(client()) + assertEquals(5, explainResponseAsMap["total_managed_indices"] as Int) } catch (e: ResponseException) { logger.error(e.message, e) } finally { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt index 1852aa668..05612f8d4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/SecurityRestTestCase.kt @@ -25,6 +25,7 @@ import org.opensearch.common.xcontent.XContentType import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy +import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestExplainAction import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.toJsonString import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_NUMBER_OF_REPLICAS @@ -213,6 +214,13 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { return IndexStateManagementRestTestCaseExt.createPolicyExt(policy, policyId, refresh, client) } + protected fun managedIndexExplainAllAsMap( + client: RestClient?, + ): Map<*, *> { + val request = Request("GET", "${RestExplainAction.EXPLAIN_BASE_URI}") + return entityAsMap(executeRequest(request, RestStatus.OK, client!!)) + } + protected fun getExistingManagedIndexConfig(index: String) = IndexStateManagementRestTestCaseExt.getExistingManagedIndexConfigExt(index) protected fun createPolicyJson( @@ -400,7 +408,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { val request = Request(RestRequest.Method.PUT.name, "_plugins/_security/api/internalusers/$name") request.setJsonEntity(json) - executeRequest(request, null, client()) + executeRequest(request, RestStatus.CREATED, client()) } protected fun createUserWithCustomRole( @@ -453,7 +461,7 @@ abstract class SecurityRestTestCase : IndexManagementRestTestCase() { """.trimIndent() request.setJsonEntity(entity) - client().performRequest(request) + executeRequest(request, RestStatus.CREATED, client()) } protected fun assignRoleToUsers(role: String, users: List) {