Skip to content

Commit

Permalink
Fix SNS pattern regex to correctly valid sns fifo topic ARNs (opensea…
Browse files Browse the repository at this point in the history
…rch-project#381)

Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep authored Mar 15, 2023
1 parent 89b7457 commit deed4bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit deed4bd

Please sign in to comment.