Skip to content

Commit

Permalink
fix security test workflow (opensearch-project#407)
Browse files Browse the repository at this point in the history
Signed-off-by: Subhobrata Dey <[email protected]>
Signed-off-by: Angie Zhang <[email protected]>
  • Loading branch information
sbcd90 authored and Angie Zhang committed Jun 29, 2022
1 parent 9c5dddf commit a361c12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,17 @@ abstract class AlertingRestTestCase : ODFERestTestCase() {
client.makeRequest("POST", "$ALERTING_BASE_URI/_execute", params, monitor.toHttpEntityWithUser())

protected fun indexDoc(index: String, id: String, doc: String, refresh: Boolean = true): Response {
return indexDoc(client(), index, id, doc, refresh)
}

protected fun indexDocWithAdminClient(index: String, id: String, doc: String, refresh: Boolean = true): Response {
return indexDoc(adminClient(), index, id, doc, refresh)
}

private fun indexDoc(client: RestClient, index: String, id: String, doc: String, refresh: Boolean = true): Response {
val requestBody = StringEntity(doc, APPLICATION_JSON)
val params = if (refresh) mapOf("refresh" to "true") else mapOf()
val response = client().makeRequest("PUT", "$index/_doc/$id", params, requestBody)
val response = client.makeRequest("PUT", "$index/_doc/$id", params, requestBody)
assertTrue(
"Unable to index doc: '${doc.take(15)}...' to index: '$index'",
listOf(RestStatus.OK, RestStatus.CREATED).contains(response.restStatus())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class DestinationMigrationUtilServiceIT : AlertingRestTestCase() {
val emailGroupDoc = "{\"email_group\" : ${emailGroup.toJsonString()}}"
val emailAccountId = UUID.randomUUID().toString()
val emailGroupId = UUID.randomUUID().toString()
indexDoc(SCHEDULED_JOBS_INDEX, emailAccountId, emailAccountDoc)
indexDoc(SCHEDULED_JOBS_INDEX, emailGroupId, emailGroupDoc)
indexDocWithAdminClient(SCHEDULED_JOBS_INDEX, emailAccountId, emailAccountDoc)
indexDocWithAdminClient(SCHEDULED_JOBS_INDEX, emailGroupId, emailGroupDoc)

val recipient = Recipient(Recipient.RecipientType.EMAIL, null, "[email protected]")
val email = Email(emailAccountId, listOf(recipient))
Expand Down Expand Up @@ -75,7 +75,7 @@ class DestinationMigrationUtilServiceIT : AlertingRestTestCase() {
"destination" : ${destination.toJsonString()}
}
""".trimIndent()
indexDoc(SCHEDULED_JOBS_INDEX, destination.id, dest)
indexDocWithAdminClient(SCHEDULED_JOBS_INDEX, destination.id, dest)
ids.add(destination.id)
}

Expand Down

0 comments on commit a361c12

Please sign in to comment.