Skip to content

Commit

Permalink
ensure name is at lest 1 char
Browse files Browse the repository at this point in the history
Signed-off-by: jowg-amazon <[email protected]>
  • Loading branch information
jowg-amazon committed Apr 12, 2024
1 parent 272513e commit 5c8888f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ data class DocLevelQuery(
const val QUERY_FIELD_NAMES_FIELD = "query_field_names"
const val NO_ID = ""
val INVALID_CHARACTERS: List<String> = listOf(" ", "[", "]", "{", "}", "(", ")")
val QUERY_NAME_REGEX = "^.{0,256}$".toRegex() // regex to restrict string length 256 chars
val QUERY_NAME_REGEX = "^.{1,256}$".toRegex() // regex to restrict string length between 1 - 256 chars

@JvmStatic
@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ class DocLevelMonitorInputTests {
@Test
fun `test create Doc Level Query with invalid name length`() {
val stringBuilder = StringBuilder()

// test empty string
val emptyString = stringBuilder.toString()
try {
randomDocLevelQuery(name = emptyString)
Assertions.fail("Expecting an illegal argument exception")
} catch (e: IllegalArgumentException) {
Assertions.assertEquals(
"The query name, $emptyString, can be max 256 characters.",
e.message
)
}

// test string with 257 chars
repeat(257) {
stringBuilder.append("a")
}
Expand Down

0 comments on commit 5c8888f

Please sign in to comment.