Skip to content

Commit

Permalink
Add validation for gov-slack.com domain
Browse files Browse the repository at this point in the history
Signed-off-by: Aniruddh <[email protected]>
  • Loading branch information
Noir01 committed Nov 16, 2023
1 parent 875048f commit aa3b636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/\""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa3b636

Please sign in to comment.