Skip to content

Commit 0771970

Browse files
committed
Fix SNS pattern regex to correctly valid sns fifo topic ARNs
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
1 parent 7951ba9 commit 0771970

File tree

2 files changed

+12
-1
lines changed
  • src
    • main/kotlin/org/opensearch/commons/notifications/model
    • test/kotlin/org/opensearch/commons/notifications/model

2 files changed

+12
-1
lines changed

src/main/kotlin/org/opensearch/commons/notifications/model/Sns.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ data class Sns(val topicArn: String, val roleArn: String?) : BaseConfigData {
5858
private val log by logger(Sns::class.java)
5959

6060
private val SNS_ARN_REGEX =
61-
Pattern.compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z0-9-_]+)$")
61+
Pattern.compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z_0-9+=,.@\\-_/]+)$")
6262

6363
/**
6464
* reader to create instance of class from writable.

src/test/kotlin/org/opensearch/commons/notifications/model/SnsTests.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ package org.opensearch.commons.notifications.model
88
import com.fasterxml.jackson.core.JsonParseException
99
import org.junit.jupiter.api.Assertions
1010
import org.junit.jupiter.api.Assertions.assertThrows
11+
import org.junit.jupiter.api.Assertions.fail
1112
import org.junit.jupiter.api.Test
1213
import org.opensearch.commons.utils.createObjectFromJsonString
1314
import org.opensearch.commons.utils.getJsonString
15+
import org.opensearch.commons.utils.logger
1416
import org.opensearch.commons.utils.recreateObject
1517

1618
internal class SnsTests {
@@ -49,6 +51,15 @@ internal class SnsTests {
4951
}
5052
}
5153

54+
@Test
55+
fun `test SNS correctly validates SNS FIFO topic ARN`() {
56+
try {
57+
Sns("arn:aws:sns:ap-southeast-2:333654771707:sns-fifo-alerting.fifo", "arn:aws:iam::012345678912:role/iam-test")
58+
} catch (e: Exception) {
59+
fail("Expected fifo sns topic ARN to be validated successfully", e)
60+
}
61+
}
62+
5263
@Test
5364
fun `SNS serialize and deserialize transport object should be equal`() {
5465
val sampleSns = Sns("arn:aws:sns:us-east-1:012345678912:topic-test", "arn:aws:iam::012345678912:role/iam-test")

0 commit comments

Comments
 (0)