Skip to content

Commit

Permalink
Add validation tests for Slack URL
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 fe1189d commit 8c17f39
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.opensearch.commons.authuser.User
import org.opensearch.commons.notifications.model.MicrosoftTeams
import org.opensearch.commons.notifications.model.Slack
import java.lang.reflect.Method
import kotlin.test.assertFails

Expand All @@ -28,8 +29,28 @@ class ConfigIndexingActionsTests {
assertFails { validateMicrosoftTeamsConfig.invoke(ConfigIndexingActions, microsoftTeams, user) }
}

@Test
fun `test validate slack`() {
val user = User()
var slack = Slack("https://hooks.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("http://hooks.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://hooks.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://hooks.slack.com/")
assertFails { validateSlackConfig.invoke(ConfigIndexingActions, slack, user) }
}

companion object {
private lateinit var validateMicrosoftTeamsConfig: Method
private lateinit var validateSlackConfig: Method

@BeforeAll
@JvmStatic
Expand All @@ -38,8 +59,12 @@ class ConfigIndexingActionsTests {
validateMicrosoftTeamsConfig = ConfigIndexingActions::class.java.getDeclaredMethod(
"validateMicrosoftTeamsConfig", MicrosoftTeams::class.java, User::class.java
)
validateSlackConfig = ConfigIndexingActions::class.java.getDeclaredMethod(
"validateSlackConfig", Slack::class.java, User::class.java
)

validateMicrosoftTeamsConfig.isAccessible = true
validateSlackConfig.isAccessible = true
}
}
}

0 comments on commit 8c17f39

Please sign in to comment.