From 14b3a95cf15c8f21934c2283a75a0e4a902f252e Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Wed, 15 Mar 2023 09:25:52 -0700 Subject: [PATCH] Fix SNS pattern regex to correctly valid sns fifo topic ARNs (#381) Signed-off-by: Surya Sashank Nistala (cherry picked from commit deed4bda567ed371cdea79f3b0f7596ceb63dda6) --- .../opensearch/commons/notifications/model/Sns.kt | 2 +- .../commons/notifications/model/SnsTests.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/opensearch/commons/notifications/model/Sns.kt b/src/main/kotlin/org/opensearch/commons/notifications/model/Sns.kt index 583aec49..fc377b75 100644 --- a/src/main/kotlin/org/opensearch/commons/notifications/model/Sns.kt +++ b/src/main/kotlin/org/opensearch/commons/notifications/model/Sns.kt @@ -58,7 +58,7 @@ data class Sns(val topicArn: String, val roleArn: String?) : BaseConfigData { private val log by logger(Sns::class.java) private val SNS_ARN_REGEX = - Pattern.compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z0-9-_]+)$") + Pattern.compile("^arn:aws(-[^:]+)?:sns:([a-zA-Z0-9-]+):([0-9]{12}):([a-zA-Z_0-9+=,.@\\-_/]+)$") /** * reader to create instance of class from writable. diff --git a/src/test/kotlin/org/opensearch/commons/notifications/model/SnsTests.kt b/src/test/kotlin/org/opensearch/commons/notifications/model/SnsTests.kt index 494f09e9..f81e8d3f 100644 --- a/src/test/kotlin/org/opensearch/commons/notifications/model/SnsTests.kt +++ b/src/test/kotlin/org/opensearch/commons/notifications/model/SnsTests.kt @@ -8,6 +8,7 @@ package org.opensearch.commons.notifications.model import com.fasterxml.jackson.core.JsonParseException import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertThrows +import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test import org.opensearch.commons.utils.createObjectFromJsonString import org.opensearch.commons.utils.getJsonString @@ -49,6 +50,18 @@ internal class SnsTests { } } + @Test + fun `test SNS correctly validates SNS FIFO topic ARN`() { + try { + Sns( + "arn:aws:sns:ap-southeast-2:333654771707:sns-fifo-alerting.fifo", + "arn:aws:iam::012345678912:role/iam-test" + ) + } catch (e: Exception) { + fail("Expected fifo sns topic ARN to be validated successfully", e) + } + } + @Test fun `SNS serialize and deserialize transport object should be equal`() { val sampleSns = Sns("arn:aws:sns:us-east-1:012345678912:topic-test", "arn:aws:iam::012345678912:role/iam-test")