From aa3b636bfeb6c863a8df594924df50ca5bf1b7af Mon Sep 17 00:00:00 2001 From: Aniruddh Date: Thu, 16 Nov 2023 02:56:10 -0500 Subject: [PATCH] Add validation for gov-slack.com domain Signed-off-by: Aniruddh --- .../notifications/index/ConfigIndexingActions.kt | 2 +- .../config/SlackNotificationConfigCrudIT.kt | 2 +- .../index/ConfigIndexingActionsTests.kt | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/notifications/notifications/src/main/kotlin/org/opensearch/notifications/index/ConfigIndexingActions.kt b/notifications/notifications/src/main/kotlin/org/opensearch/notifications/index/ConfigIndexingActions.kt index 5a228600..01e76dfa 100644 --- a/notifications/notifications/src/main/kotlin/org/opensearch/notifications/index/ConfigIndexingActions.kt +++ b/notifications/notifications/src/main/kotlin/org/opensearch/notifications/index/ConfigIndexingActions.kt @@ -57,7 +57,7 @@ object ConfigIndexingActions { @Suppress("UnusedPrivateMember") private fun validateSlackConfig(slack: Slack, user: User?) { require(slack.url.contains(Regex("https://hooks\\.(?:gov-)?slack\\.com/services"))) { - "Wrong Slack url. Should contain \"hooks.slack.com/services/\"" + "Wrong Slack url. Should contain \"hooks.slack.com/services/\" or \"hooks.gov-slack.com/services/\"" } } diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt index c2bdb823..5bbac40c 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/config/SlackNotificationConfigCrudIT.kt @@ -191,7 +191,7 @@ class SlackNotificationConfigCrudIT : PluginRestTestCase() { fail("Expected wrong Slack URL.") } catch (exception: ResponseException) { Assert.assertEquals( - "Wrong Slack url. Should contain \"hooks.slack.com/services/\"", + "Wrong Slack url. Should contain \"hooks.slack.com/services/\" or \"hooks.gov-slack.com/services/\"", jsonify(getResponseBody(exception.response))["error"].asJsonObject["reason"].asString ) } diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt b/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt index 1731cbef..ddbe104e 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/notifications/index/ConfigIndexingActionsTests.kt @@ -34,18 +34,32 @@ class ConfigIndexingActionsTests { val user = User() var slack = Slack("https://hooks.slack.com/services/123456789/123456789/123456789") validateSlackConfig.invoke(ConfigIndexingActions, slack, user) + slack = Slack("https://hooks.gov-slack.com/services/123456789/123456789/123456789") + validateSlackConfig.invoke(ConfigIndexingActions, slack, user) slack = Slack("https://hooks.slack.com/services/samplesamplesamplesamplesamplesamplesamplesamplesample") validateSlackConfig.invoke(ConfigIndexingActions, slack, user) + slack = Slack("https://hooks.gov-slack.com/services/samplesamplesamplesamplesamplesamplesamplesamplesample") + validateSlackConfig.invoke(ConfigIndexingActions, slack, user) slack = Slack("http://hooks.slack.com/services/123456789/123456789/123456789/123456789") assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } + slack = Slack("http://hooks.gov-slack.com/services/123456789/123456789/123456789/123456789") + assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } slack = Slack("https://slack.com/services/123456789/123456789/123456789/123456789") assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } + slack = Slack("https://gov-slack.com/services/123456789/123456789/123456789/123456789") + assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } slack = Slack("https://hooks.slack.com/123456789/123456789/123456789/123456789/123456789") assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } + slack = Slack("https://hooks.gov-slack.com/123456789/123456789/123456789/123456789/123456789") + assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } slack = Slack("https://hook.slack.com/services/123456789/123456789/123456789/123456789/123456789") assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } + slack = Slack("https://hook.gov-slack.com/services/123456789/123456789/123456789/123456789/123456789") + assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } slack = Slack("https://hooks.slack.com/") assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } + slack = Slack("https://hooks.gov-slack.com/") + assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) } } companion object {