Skip to content

Commit

Permalink
Add test for validating Chime url.
Browse files Browse the repository at this point in the history
Signed-off-by: Aniruddh Srivastava <[email protected]>
  • Loading branch information
Noir01 committed Nov 23, 2023
1 parent 1a7bcfa commit fa7a5f7
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
package org.opensearch.integtest.config

import org.junit.Assert
import org.opensearch.client.Request
import org.opensearch.client.RequestOptions
import org.opensearch.client.ResponseException
import org.opensearch.commons.notifications.model.Chime
import org.opensearch.commons.notifications.model.ConfigType
import org.opensearch.commons.notifications.model.NotificationConfig
import org.opensearch.core.rest.RestStatus
import org.opensearch.integtest.PluginRestTestCase
import org.opensearch.integtest.getResponseBody
import org.opensearch.integtest.jsonify
import org.opensearch.notifications.NotificationPlugin.Companion.PLUGIN_BASE_URI
import org.opensearch.notifications.verifySingleConfigEquals
import org.opensearch.rest.RestRequest
Expand Down Expand Up @@ -307,4 +312,40 @@ class ChimeNotificationConfigCrudIT : PluginRestTestCase() {
RestStatus.INTERNAL_SERVER_ERROR.status
)
}

fun `test create config with wrong Chime url and get error text`() {
val sampleChime = Chime("https://hooks.chime.aws/incomingwebhooks/sample_chime_url?token=123456")
val referenceObject = NotificationConfig(
"this is a sample config name",
"this is a sample config description",
ConfigType.CHIME,
isEnabled = true,
configData = sampleChime
)
val createRequestJsonString = """
{
"config":{
"name":"${referenceObject.name}",
"description":"${referenceObject.description}",
"config_type":"chime",
"is_enabled":${referenceObject.isEnabled},
"chime":{"url":"${(referenceObject.configData as Chime).url}"}
}
}
""".trimIndent()
val response = try {
val request = Request(RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/configs")
request.setJsonEntity(createRequestJsonString)
val restOptionsBuilder = RequestOptions.DEFAULT.toBuilder()
restOptionsBuilder.addHeader("Content-Type", "application/json")
request.setOptions(restOptionsBuilder)
client().performRequest(request)
fail("Expected wrong Chime URL.")
} catch (exception: ResponseException) {
Assert.assertEquals(
"Wrong Chime url. Should contain \"hooks.chime.aws/incomingwebhooks/\" and \"?token=\"",
jsonify(getResponseBody(exception.response))["error"].asJsonObject["reason"].asString
)
}
}
}

0 comments on commit fa7a5f7

Please sign in to comment.