Skip to content

Commit c51940f

Browse files
authored
fixed security tests (opensearch-project#484)
* fixed security tests Signed-off-by: Raj Chakravarthi <[email protected]>
1 parent 830dff1 commit c51940f

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
@@ -129,7 +131,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
129131

130132
/*
131133
TODO: https://github.com/opensearch-project/alerting/issues/300
132-
134+
*/
133135
fun `test get email accounts with an user without get email account role`() {
134136
createUserWithTestDataAndCustomRole(
135137
user,
@@ -138,9 +140,7 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
138140
listOf(TEST_HR_BACKEND_ROLE),
139141
getClusterPermissionsFromCustomRole(ALERTING_NO_ACCESS_ROLE)
140142
)
141-
142143
val emailAccount = createRandomEmailAccountWithGivenName(true, randomAlphaOfLength(5))
143-
144144
try {
145145
userClient?.makeRequest(
146146
"GET",
@@ -158,19 +158,15 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
158158
deleteRoleAndRoleMapping(TEST_HR_ROLE)
159159
}
160160
}
161-
162161
fun `test search email accounts with an user without search email account role`() {
163-
164162
createUserWithTestDataAndCustomRole(
165163
user,
166164
TEST_HR_INDEX,
167165
TEST_HR_ROLE,
168166
listOf(TEST_HR_BACKEND_ROLE),
169167
getClusterPermissionsFromCustomRole(ALERTING_NO_ACCESS_ROLE)
170168
)
171-
172169
createRandomEmailAccountWithGivenName(true, randomAlphaOfLength(5))
173-
174170
try {
175171
userClient?.makeRequest(
176172
"POST",
@@ -185,6 +181,4 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
185181
deleteRoleAndRoleMapping(TEST_HR_ROLE)
186182
}
187183
}
188-
189-
*/
190184
}

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)