forked from opensearch-project/alerting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added input validation for GetRemoteIndexes API, and added related un…
…it and integration tests. Signed-off-by: AWSHurneyt <[email protected]>
- Loading branch information
1 parent
a5c9975
commit 02b8387
Showing
8 changed files
with
520 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
alerting/src/test/kotlin/org/opensearch/alerting/action/GetRemoteIndexesActionTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.alerting.action | ||
|
||
import org.opensearch.test.OpenSearchTestCase | ||
|
||
class GetRemoteIndexesActionTests : OpenSearchTestCase() { | ||
private val validPatterns = listOf( | ||
"local-index-name", | ||
"localindexname", | ||
"local-index-*-pattern-*", | ||
"*local-index-*-pattern-*", | ||
"cluster-name:remote-index-name", | ||
"cluster-name:remoteindexname", | ||
"cluster-name:remote-index-*-pattern-*", | ||
"cluster-name:*remote-index-*-pattern-*", | ||
"cluster-*pattern-*:remote-index-name", | ||
"cluster-*pattern-*:remoteindexname", | ||
"cluster-*pattern-*:remote-index-*-pattern-*", | ||
"cluster-*pattern-*:*remote-index-*-pattern-*", | ||
"*cluster-*pattern-*:remote-index-*-pattern-*", | ||
"cluster-*:pattern-*:remote-index-name", | ||
"cluster-*:pattern-*:remoteindexname", | ||
"cluster-*:pattern-*:remote-index-*-pattern-*", | ||
"*cluster-*:pattern-*:remote-index-*-pattern-*", | ||
) | ||
|
||
private val invalidPatterns = listOf( | ||
// `<cluster-pattern>` character length less than 1 should return FALSE | ||
":remote-index-name", | ||
|
||
// `<cluster-pattern>` character length greater than 63 should return FALSE | ||
"${randomAlphaOfLength(256)}:remote-index-name", | ||
|
||
// Invalid characters should return FALSE | ||
"local-index#-name", | ||
"cluster-name:remote-#index-name", | ||
"cluster-#name:remote-index-name", | ||
"cluster-#name:remote-#index-name", | ||
|
||
// More than 1 `:` character in `<cluster-pattern>` should return FALSE | ||
"bad:cluster:name:remote-index-name", | ||
) | ||
|
||
fun `test get remote indexes action name`() { | ||
assertNotNull(GetRemoteIndexesAction.INSTANCE.name()) | ||
assertEquals(GetRemoteIndexesAction.INSTANCE.name(), GetRemoteIndexesAction.NAME) | ||
} | ||
|
||
fun `test GetRemoteIndexesRequest isValid with empty array`() { | ||
val request = GetRemoteIndexesRequest( | ||
indexes = emptyList(), | ||
includeMappings = false | ||
) | ||
assertFalse(request.isValid()) | ||
} | ||
|
||
fun `test GetRemoteIndexesRequest isValid with one valid entry`() { | ||
validPatterns.forEach { | ||
val request = GetRemoteIndexesRequest( | ||
indexes = listOf(it), | ||
includeMappings = false | ||
) | ||
assertTrue("Expected pattern '$it' to be valid.", request.isValid()) | ||
} | ||
} | ||
|
||
fun `test GetRemoteIndexesRequest isValid with multiple valid entries`() { | ||
val request = GetRemoteIndexesRequest( | ||
indexes = validPatterns, | ||
includeMappings = false | ||
) | ||
assertTrue(request.isValid()) | ||
} | ||
|
||
fun `test GetRemoteIndexesRequest isValid with one invalid entry`() { | ||
invalidPatterns.forEach { | ||
val request = GetRemoteIndexesRequest( | ||
indexes = listOf(it), | ||
includeMappings = false | ||
) | ||
assertFalse("Expected pattern '$it' to be invalid.", request.isValid()) | ||
} | ||
} | ||
|
||
fun `test GetRemoteIndexesRequest isValid with multiple invalid entries`() { | ||
val request = GetRemoteIndexesRequest( | ||
indexes = invalidPatterns, | ||
includeMappings = false | ||
) | ||
assertFalse(request.isValid()) | ||
} | ||
|
||
fun `test GetRemoteIndexesRequest isValid with valid and invalid entries`() { | ||
val request = GetRemoteIndexesRequest( | ||
indexes = validPatterns + invalidPatterns, | ||
includeMappings = false | ||
) | ||
assertFalse(request.isValid()) | ||
} | ||
} |
Oops, something went wrong.