Skip to content

Commit

Permalink
uncomment system index viewing IT
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Toepker <[email protected]>
  • Loading branch information
toepkerd-zz committed Sep 26, 2024
1 parent 0d4d474 commit 6161caf
Showing 1 changed file with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@

package org.opensearch.alerting.resthandler

import org.apache.hc.core5.http.ContentType.APPLICATION_JSON
import org.apache.hc.core5.http.io.entity.StringEntity
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.opensearch.alerting.ALERTING_ACK_ALERTS_ROLE
import org.opensearch.alerting.ALERTING_FULL_ACCESS_ROLE
import org.opensearch.alerting.ALERTING_READ_ONLY_ACCESS
import org.opensearch.alerting.AlertingRestTestCase
import org.opensearch.alerting.makeRequest
import org.opensearch.alerting.randomAlert
import org.opensearch.alerting.settings.AlertingSettings.Companion.ALERTING_COMMENTS_ENABLED
import org.opensearch.client.ResponseException
import org.opensearch.client.RestClient
import org.opensearch.common.xcontent.XContentType
import org.opensearch.commons.alerting.model.Alert
import org.opensearch.commons.rest.SecureRestClientBuilder
import org.opensearch.core.rest.RestStatus
Expand Down Expand Up @@ -359,32 +363,31 @@ class SecureAlertingCommentsRestApiIT : AlertingRestTestCase() {
}
}

// TODO: Uncomment and this should pass in CIs
// fun `test user cannot directly search comments system index`() {
// createUserWithRoles(
// userA,
// listOf(ALERTING_FULL_ACCESS_ROLE),
// listOf(),
// false
// )
//
// val monitor = createRandomMonitor(refresh = true)
// val alert = createAlert(randomAlert(monitor).copy(state = Alert.State.ACTIVE))
// val alertId = alert.id
// val commentContent = "test comment"
//
// createAlertComment(alertId, commentContent, userAClient!!).id
//
// val query = SearchSourceBuilder().query(QueryBuilders.matchAllQuery())
// val searchResponse = userAClient!!.makeRequest(
// "GET",
// ".opensearch-alerting-comments-history-*/_search",
// StringEntity(query.toString(), APPLICATION_JSON)
// )
//
// val xcp = createParser(XContentType.JSON.xContent(), searchResponse.entity.content)
// val hits = xcp.map()["hits"]!! as Map<String, Map<String, Any>>
// val numberDocsFound = hits["total"]?.get("value")
// assertEquals("User was able to directly inspect alerting comments system index docs", 0, numberDocsFound)
// }
fun `test user cannot directly search comments system index`() {
createUserWithRoles(
userA,
listOf(ALERTING_FULL_ACCESS_ROLE),
listOf(),
false
)

val monitor = createRandomMonitor(refresh = true)
val alert = createAlert(randomAlert(monitor).copy(state = Alert.State.ACTIVE))
val alertId = alert.id
val commentContent = "test comment"

createAlertComment(alertId, commentContent, userAClient!!).id

val query = SearchSourceBuilder().query(QueryBuilders.matchAllQuery())
val searchResponse = userAClient!!.makeRequest(
"GET",
".opensearch-alerting-comments-history-*/_search",
StringEntity(query.toString(), APPLICATION_JSON)
)

val xcp = createParser(XContentType.JSON.xContent(), searchResponse.entity.content)
val hits = xcp.map()["hits"]!! as Map<String, Map<String, Any>>
val numberDocsFound = hits["total"]?.get("value")
assertEquals("User was able to directly inspect alerting comments system index docs", 0, numberDocsFound)
}
}

0 comments on commit 6161caf

Please sign in to comment.