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

fixed security tests #484

Merged
merged 6 commits into from
Feb 10, 2023
Merged
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
2 changes: 1 addition & 1 deletion alerting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ dependencies {
implementation "com.github.seancfoley:ipaddress:5.3.3"

testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testImplementation "org.mockito:mockito-core:4.7.0"
testImplementation "org.mockito:mockito-core:5.1.0"
testImplementation "org.opensearch.plugin:reindex-client:${opensearch_version}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import org.apache.lucene.util.BitDocIdSet;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.SetOnce;
import org.opensearch.common.SetOnce;
import org.opensearch.OpenSearchException;
import org.opensearch.ResourceNotFoundException;
import org.opensearch.Version;
Expand Down
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 @@ -129,7 +131,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 @@ -138,9 +140,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 @@ -158,19 +158,15 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
deleteRoleAndRoleMapping(TEST_HR_ROLE)
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Maintain an empty line between tests.

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 @@ -185,6 +181,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