Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ object NotificationConstants {
const val PLUGIN_FEATURES_TAG = "plugin_features"

const val DEFAULT_MAX_ITEMS = 1000
const val ENCRYPTION_PREFIX = "enc:"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.opensearch.commons.notifications.model

import org.opensearch.commons.notifications.NotificationConstants.ENCRYPTION_PREFIX
import org.opensearch.commons.notifications.NotificationConstants.URL_TAG
import org.opensearch.commons.utils.logger
import org.opensearch.commons.utils.validateUrl
Expand All @@ -26,7 +27,9 @@ data class Chime(

init {
require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" }
validateUrl(url)
if (!url.startsWith(ENCRYPTION_PREFIX)) {
validateUrl(url)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.opensearch.commons.notifications.model

import org.opensearch.commons.notifications.NotificationConstants.ENCRYPTION_PREFIX
import org.opensearch.commons.notifications.NotificationConstants.URL_TAG
import org.opensearch.commons.utils.logger
import org.opensearch.commons.utils.validateUrl
Expand All @@ -26,7 +27,9 @@ data class MicrosoftTeams(

init {
require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" }
validateUrl(url)
if (!url.startsWith(ENCRYPTION_PREFIX)) {
validateUrl(url)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.opensearch.commons.notifications.model

import org.opensearch.commons.notifications.NotificationConstants.ENCRYPTION_PREFIX
import org.opensearch.commons.notifications.NotificationConstants.URL_TAG
import org.opensearch.commons.utils.logger
import org.opensearch.commons.utils.validateUrl
Expand All @@ -26,7 +27,9 @@ data class Slack(

init {
require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" }
validateUrl(url)
if (!url.startsWith(ENCRYPTION_PREFIX)) {
validateUrl(url)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.opensearch.commons.notifications.model

import org.opensearch.commons.notifications.NotificationConstants.ENCRYPTION_PREFIX
import org.opensearch.commons.notifications.NotificationConstants.HEADER_PARAMS_TAG
import org.opensearch.commons.notifications.NotificationConstants.METHOD_TAG
import org.opensearch.commons.notifications.NotificationConstants.URL_TAG
Expand Down Expand Up @@ -32,7 +33,9 @@ data class Webhook(

init {
require(!Strings.isNullOrEmpty(url)) { "URL is null or empty" }
validateUrl(url)
if (!url.startsWith(ENCRYPTION_PREFIX)) {
validateUrl(url)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ internal class ChimeTests {
}
}

@Test
fun `Chime should skip url validation when url starts with enc prefix`() {
val encryptedUrl = "enc:this-is-not-a-real-url"
val chime = Chime(encryptedUrl)
assertEquals(encryptedUrl, chime.url)
}

@Test
fun `Chime with enc prefix should serialize and deserialize transport object`() {
val sampleChime = Chime("enc:some-encrypted-value")
val recreatedObject = recreateObject(sampleChime) { Chime(it) }
assertEquals(sampleChime, recreatedObject)
}

@Test
fun `Chime with enc prefix should serialize and deserialize using json object`() {
val sampleChime = Chime("enc:some-encrypted-value")
val jsonString = getJsonString(sampleChime)
val recreatedObject = createObjectFromJsonString(jsonString) { Chime.parse(it) }
assertEquals(sampleChime, recreatedObject)
}

@Test
fun `Chime should safely ignore extra field in json object`() {
val sampleChime = Chime("https://domain.com/sample_url#1234567890")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ internal class MicrosoftTeamsTests {
}
}

@Test
fun `Microsoft Teams should skip url validation when url starts with enc prefix`() {
val encryptedUrl = "enc:this-is-not-a-real-url"
val microsoftTeams = MicrosoftTeams(encryptedUrl)
assertEquals(encryptedUrl, microsoftTeams.url)
}

@Test
fun `Microsoft Teams with enc prefix should serialize and deserialize transport object`() {
val sampleMicrosoftTeams = MicrosoftTeams("enc:some-encrypted-value")
val recreatedObject = recreateObject(sampleMicrosoftTeams) { MicrosoftTeams(it) }
assertEquals(sampleMicrosoftTeams, recreatedObject)
}

@Test
fun `Microsoft Teams with enc prefix should serialize and deserialize using json object`() {
val sampleMicrosoftTeams = MicrosoftTeams("enc:some-encrypted-value")
val jsonString = getJsonString(sampleMicrosoftTeams)
val recreatedObject = createObjectFromJsonString(jsonString) { MicrosoftTeams.parse(it) }
assertEquals(sampleMicrosoftTeams, recreatedObject)
}

@Test
fun `Microsoft Teams should safely ignore extra field in json object`() {
val sampleMicrosoftTeams = MicrosoftTeams("https://domain.com/sample_url#1234567890")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ internal class SlackTests {
}
}

@Test
fun `Slack should skip url validation when url starts with enc prefix`() {
val encryptedUrl = "enc:this-is-not-a-real-url"
val slack = Slack(encryptedUrl)
assertEquals(encryptedUrl, slack.url)
}

@Test
fun `Slack with enc prefix should serialize and deserialize transport object`() {
val sampleSlack = Slack("enc:some-encrypted-value")
val recreatedObject = recreateObject(sampleSlack) { Slack(it) }
assertEquals(sampleSlack, recreatedObject)
}

@Test
fun `Slack with enc prefix should serialize and deserialize using json object`() {
val sampleSlack = Slack("enc:some-encrypted-value")
val jsonString = getJsonString(sampleSlack)
val recreatedObject = createObjectFromJsonString(jsonString) { Slack.parse(it) }
assertEquals(sampleSlack, recreatedObject)
}

@Test
fun `Slack should safely ignore extra field in json object`() {
val sampleSlack = Slack("https://domain.com/sample_url#1234567890")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ internal class WebhookTests {
}
}

@Test
fun `Webhook should skip url validation when url starts with enc prefix`() {
val encryptedUrl = "enc:this-is-not-a-real-url"
val webhook = Webhook(encryptedUrl)
assertEquals(encryptedUrl, webhook.url)
}

@Test
fun `Webhook with enc prefix should serialize and deserialize transport object`() {
val sampleWebhook = Webhook("enc:some-encrypted-value")
val recreatedObject = recreateObject(sampleWebhook) { Webhook(it) }
assertEquals(sampleWebhook, recreatedObject)
}

@Test
fun `Webhook with enc prefix should serialize and deserialize using json object`() {
val sampleWebhook = Webhook("enc:some-encrypted-value")
val jsonString = getJsonString(sampleWebhook)
val recreatedObject = createObjectFromJsonString(jsonString) { Webhook.parse(it) }
assertEquals(sampleWebhook, recreatedObject)
}

@Test
fun `Webhook should safely ignore extra field in json object`() {
val sampleWebhook = Webhook("https://domain.com/sample_url#1234567890")
Expand Down
Loading