Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] fixed security tests #789

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1182,10 +1182,11 @@ abstract class AlertingRestTestCase : ODFERestTestCase() {
client().performRequest(request)
}

fun createIndexRoleWithDocLevelSecurity(name: String, index: String, dlsQuery: String) {
fun createIndexRoleWithDocLevelSecurity(name: String, index: String, dlsQuery: String, clusterPermissions: String? = "") {
val request = Request("PUT", "/_plugins/_security/api/roles/$name")
var entity = "{\n" +
"\"cluster_permissions\": [\n" +
"\"$clusterPermissions\"\n" +
"],\n" +
"\"index_permissions\": [\n" +
"{\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SecureDestinationRestApiIT : AlertingRestTestCase() {
}
}

val user = "userOne"
val user = "userA"
var userClient: RestClient? = null

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.opensearch.alerting.ALERTING_GET_EMAIL_ACCOUNT_ACCESS
import org.opensearch.alerting.ALERTING_NO_ACCESS_ROLE
import org.opensearch.alerting.ALERTING_SEARCH_EMAIL_ACCOUNT_ACCESS
import org.opensearch.alerting.AlertingPlugin
import org.opensearch.alerting.AlertingRestTestCase
import org.opensearch.alerting.TEST_HR_BACKEND_ROLE
import org.opensearch.alerting.TEST_HR_INDEX
import org.opensearch.alerting.TEST_HR_ROLE
import org.opensearch.alerting.makeRequest
import org.opensearch.client.ResponseException
import org.opensearch.client.RestClient
import org.opensearch.commons.rest.SecureRestClientBuilder
import org.opensearch.rest.RestStatus
Expand Down Expand Up @@ -50,7 +52,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
}
}

val user = "userOne"
val user = "userB"
var userClient: RestClient? = null

@Before
Expand Down Expand Up @@ -126,7 +128,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {

/*
TODO: https://github.com/opensearch-project/alerting/issues/300

*/
fun `test get email accounts with an user without get email account role`() {
createUserWithTestDataAndCustomRole(
user,
Expand All @@ -135,9 +137,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
listOf(TEST_HR_BACKEND_ROLE),
getClusterPermissionsFromCustomRole(ALERTING_NO_ACCESS_ROLE)
)

val emailAccount = createRandomEmailAccountWithGivenName(true, randomAlphaOfLength(5))

try {
userClient?.makeRequest(
"GET",
Expand All @@ -155,19 +155,15 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
deleteRoleAndRoleMapping(TEST_HR_ROLE)
}
}

fun `test search email accounts with an user without search email account role`() {

createUserWithTestDataAndCustomRole(
user,
TEST_HR_INDEX,
TEST_HR_ROLE,
listOf(TEST_HR_BACKEND_ROLE),
getClusterPermissionsFromCustomRole(ALERTING_NO_ACCESS_ROLE)
)

createRandomEmailAccountWithGivenName(true, randomAlphaOfLength(5))

try {
userClient?.makeRequest(
"POST",
Expand All @@ -182,6 +178,4 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
deleteRoleAndRoleMapping(TEST_HR_ROLE)
}
}

*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SecureEmailGroupsRestApiIT : AlertingRestTestCase() {
}
}

val user = "userOne"
val user = "userC"
var userClient: RestClient? = null

@Before
Expand Down
Loading