Skip to content

Commit

Permalink
CORE-11942, CORE-11860 - Block blank strings as regex for approval ru…
Browse files Browse the repository at this point in the history
…les (#4716)

Returning a 400 when a user tries to provide a blank string as a regex for an approval (or pre-auth) rule.
  • Loading branch information
dimosr authored Sep 27, 2023
1 parent 92056c1 commit 2adcee5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ class MGMRestResourceImpl internal constructor(
}

private fun validateRegex(expression: String) {
if (expression.isBlank()) {
throw BadRequestException("The regular expression was a blank string.")
}

try {
expression.toRegex()
} catch (e: PatternSyntaxException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ class MGMRestResourceTest {
stopService()
}

@Test
fun `addGroupApprovalRule throws invalid input for blank string regex`() {
startService()

assertThrows<BadRequestException> {
mgmRestResource.addGroupApprovalRule(HOLDING_IDENTITY_ID, ApprovalRuleRequestParams(" ", RULE_LABEL))
}
}

@Test
fun `addGroupApprovalRule throws bad request if short hash is invalid`() {
startService()
Expand Down Expand Up @@ -862,6 +871,16 @@ class MGMRestResourceTest {
)
}
}

@Test
fun `it throws bad request for blank string regex`() {
assertThrows<BadRequestException> {
callFunctionUnderTest(
HOLDING_IDENTITY_ID,
ApprovalRuleRequestParams(" ", RULE_LABEL)
)
}
}
}

@Nested
Expand Down

0 comments on commit 2adcee5

Please sign in to comment.