Skip to content

Commit 3531a99

Browse files
authored
fixed security tests (#484) (#794)
* fixed security tests Signed-off-by: Raj Chakravarthi <[email protected]> (cherry picked from commit c51940f)
1 parent aaca5c8 commit 3531a99

File tree

5 files changed

+68
-58
lines changed

5 files changed

+68
-58
lines changed

alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,11 @@ abstract class AlertingRestTestCase : ODFERestTestCase() {
11821182
client().performRequest(request)
11831183
}
11841184

1185-
fun createIndexRoleWithDocLevelSecurity(name: String, index: String, dlsQuery: String) {
1185+
fun createIndexRoleWithDocLevelSecurity(name: String, index: String, dlsQuery: String, clusterPermissions: String? = "") {
11861186
val request = Request("PUT", "/_plugins/_security/api/roles/$name")
11871187
var entity = "{\n" +
11881188
"\"cluster_permissions\": [\n" +
1189+
"\"$clusterPermissions\"\n" +
11891190
"],\n" +
11901191
"\"index_permissions\": [\n" +
11911192
"{\n" +

alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureDestinationRestApiIT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SecureDestinationRestApiIT : AlertingRestTestCase() {
4141
}
4242
}
4343

44-
val user = "userOne"
44+
val user = "userA"
4545
var userClient: RestClient? = null
4646

4747
@Before

alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureEmailAccountRestApiIT.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import org.junit.After
1313
import org.junit.Before
1414
import org.junit.BeforeClass
1515
import org.opensearch.alerting.ALERTING_GET_EMAIL_ACCOUNT_ACCESS
16+
import org.opensearch.alerting.ALERTING_NO_ACCESS_ROLE
1617
import org.opensearch.alerting.ALERTING_SEARCH_EMAIL_ACCOUNT_ACCESS
1718
import org.opensearch.alerting.AlertingPlugin
1819
import org.opensearch.alerting.AlertingRestTestCase
1920
import org.opensearch.alerting.TEST_HR_BACKEND_ROLE
2021
import org.opensearch.alerting.TEST_HR_INDEX
2122
import org.opensearch.alerting.TEST_HR_ROLE
2223
import org.opensearch.alerting.makeRequest
24+
import org.opensearch.client.ResponseException
2325
import org.opensearch.client.RestClient
2426
import org.opensearch.commons.rest.SecureRestClientBuilder
2527
import org.opensearch.rest.RestStatus
@@ -50,7 +52,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
5052
}
5153
}
5254

53-
val user = "userOne"
55+
val user = "userB"
5456
var userClient: RestClient? = null
5557

5658
@Before
@@ -126,7 +128,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
126128

127129
/*
128130
TODO: https://github.com/opensearch-project/alerting/issues/300
129-
131+
*/
130132
fun `test get email accounts with an user without get email account role`() {
131133
createUserWithTestDataAndCustomRole(
132134
user,
@@ -135,9 +137,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
135137
listOf(TEST_HR_BACKEND_ROLE),
136138
getClusterPermissionsFromCustomRole(ALERTING_NO_ACCESS_ROLE)
137139
)
138-
139140
val emailAccount = createRandomEmailAccountWithGivenName(true, randomAlphaOfLength(5))
140-
141141
try {
142142
userClient?.makeRequest(
143143
"GET",
@@ -155,19 +155,15 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
155155
deleteRoleAndRoleMapping(TEST_HR_ROLE)
156156
}
157157
}
158-
159158
fun `test search email accounts with an user without search email account role`() {
160-
161159
createUserWithTestDataAndCustomRole(
162160
user,
163161
TEST_HR_INDEX,
164162
TEST_HR_ROLE,
165163
listOf(TEST_HR_BACKEND_ROLE),
166164
getClusterPermissionsFromCustomRole(ALERTING_NO_ACCESS_ROLE)
167165
)
168-
169166
createRandomEmailAccountWithGivenName(true, randomAlphaOfLength(5))
170-
171167
try {
172168
userClient?.makeRequest(
173169
"POST",
@@ -182,6 +178,4 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
182178
deleteRoleAndRoleMapping(TEST_HR_ROLE)
183179
}
184180
}
185-
186-
*/
187181
}

alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureEmailGroupsRestApiIT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SecureEmailGroupsRestApiIT : AlertingRestTestCase() {
5252
}
5353
}
5454

55-
val user = "userOne"
55+
val user = "userC"
5656
var userClient: RestClient? = null
5757

5858
@Before

0 commit comments

Comments
 (0)