Skip to content

Commit

Permalink
Addition of Constants (#295)
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Jindal <[email protected]>
  • Loading branch information
Aditya Jindal authored and qreshi committed Feb 21, 2022
1 parent 9023eb5 commit b147534
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,6 @@ fun randomADMonitor(
fun randomADUser(backendRole: String = OpenSearchRestTestCase.randomAlphaOfLength(10)): User {
return User(
OpenSearchRestTestCase.randomAlphaOfLength(10), listOf(backendRole),
listOf(OpenSearchRestTestCase.randomAlphaOfLength(10), "all_access"), listOf("test_attr=test")
listOf(OpenSearchRestTestCase.randomAlphaOfLength(10), ALL_ACCESS_ROLE), listOf("test_attr=test")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ abstract class AlertingRestTestCase : ODFERestTestCase() {
client().makeRequest("DELETE", "/_plugins/_security/api/rolesmapping/$name")
}

fun deleteRoleAndRoleMapping(role: String, roleMapping: String) {
deleteRoleMapping(role)
deleteRole(role)
deleteRoleMapping(roleMapping)
}

fun createUserWithTestData(user: String, index: String, role: String, backendRole: String) {
createUser(user, user, arrayOf(backendRole))
createTestIndex(index)
Expand Down
10 changes: 9 additions & 1 deletion alerting/src/test/kotlin/org/opensearch/alerting/TestHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,21 @@ fun randomEmailGroup(

fun randomScript(source: String = "return " + OpenSearchRestTestCase.randomBoolean().toString()): Script = Script(source)

val ADMIN = "admin"
val ALERTING_BASE_URI = "/_plugins/_alerting/monitors"
val ALERTING_FULL_ACCESS_ROLE = "alerting_full_access"
val ALL_ACCESS_ROLE = "all_access"
val DESTINATION_BASE_URI = "/_plugins/_alerting/destinations"
val LEGACY_OPENDISTRO_ALERTING_BASE_URI = "/_opendistro/_alerting/monitors"
val LEGACY_OPENDISTRO_DESTINATION_BASE_URI = "/_opendistro/_alerting/destinations"
val ALWAYS_RUN = Script("return true")
val NEVER_RUN = Script("return false")
val DRYRUN_MONITOR = mapOf("dryrun" to "true")
val TEST_HR_INDEX = "hr_data"
val TEST_NON_HR_INDEX = "not_hr_data"
val TEST_HR_ROLE = "hr_role"
val TEST_HR_BACKEND_ROLE = "HR"
val TERM_DLS_QUERY = "{\"term\": { \"accessible\": true}}"

fun randomTemplateScript(
source: String,
Expand Down Expand Up @@ -420,7 +428,7 @@ fun randomUser(): User {
OpenSearchRestTestCase.randomAlphaOfLength(10),
OpenSearchRestTestCase.randomAlphaOfLength(10)
),
listOf(OpenSearchRestTestCase.randomAlphaOfLength(10), "all_access"),
listOf(OpenSearchRestTestCase.randomAlphaOfLength(10), ALL_ACCESS_ROLE),
listOf("test_attr=test")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package org.opensearch.alerting.model

import org.opensearch.alerting.ADMIN
import org.opensearch.alerting.model.destination.Chime
import org.opensearch.alerting.model.destination.CustomWebhook
import org.opensearch.alerting.model.destination.Destination
Expand Down Expand Up @@ -193,8 +194,8 @@ class DestinationTests : OpenSearchTestCase() {
"POST",
mutableMapOf(),
mutableMapOf(),
"admin",
"admin"
ADMIN,
ADMIN
),
null
)
Expand Down
Loading

0 comments on commit b147534

Please sign in to comment.