diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt index 6091da676..106117fa2 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementRestTestCase.kt @@ -102,6 +102,37 @@ abstract class IndexStateManagementRestTestCase : IndexManagementRestTestCase() updateValidationServiceSetting(true) } + protected fun createOrUpdateRole() { + val roleBody = """ + { + "cluster_permissions": ["cluster:admin/snapshot/restore", "cluster:admin/snapshot/create"], + "index_permissions": [ + { + "index_patterns": ["*"], + "allowed_actions": ["indices:*"] + } + ] + } + """.trimIndent() + + client().makeRequest( + method = "PUT", + endpoint = "/_plugins/_security/api/roles/snapshot_restore_role", + entity = StringEntity(roleBody, ContentType.APPLICATION_JSON), + ) + + // Map your test user to snapshot_restore_role + val roleMappingBody = """ + { + "users": ["testUser"] + } + """.trimIndent() + client().makeRequest( + method = "PUT", + endpoint = "/_plugins/_security/api/rolesmapping/snapshot_restore_role", + entity = StringEntity(roleMappingBody, ContentType.APPLICATION_JSON), + ) + } protected fun createPolicy( policy: Policy, policyId: String = OpenSearchTestCase.randomAlphaOfLength(10), diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ConvertIndexToRemoteActionIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ConvertIndexToRemoteActionIT.kt index 5617a9cf4..56b565680 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ConvertIndexToRemoteActionIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/ConvertIndexToRemoteActionIT.kt @@ -21,6 +21,7 @@ class ConvertIndexToRemoteActionIT : IndexStateManagementRestTestCase() { private val testIndexName = javaClass.simpleName.lowercase(Locale.ROOT) fun `test basic conversion to remote index`() { + createOrUpdateRole() val indexName = "${testIndexName}_index_basic" val policyID = "${testIndexName}_policy_basic" val repository = "repository"