Skip to content

Commit

Permalink
test tweak
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <[email protected]>
  • Loading branch information
petardz committed May 17, 2023
1 parent 3397d71 commit f93e7eb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<String>) {
Expand Down

0 comments on commit f93e7eb

Please sign in to comment.