Skip to content

Commit e0e3734

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 89b7457 commit e0e3734

File tree

2 files changed

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

2 files changed

+14
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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
@@ -49,6 +50,18 @@ internal class SnsTests {
4950
}
5051
}
5152

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

0 commit comments

Comments
 (0)