Skip to content

Commit

Permalink
Wrapped URI syntax exception in IllegalArgument exception. (#645)
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
(cherry picked from commit 0aae343)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Apr 25, 2024
1 parent 6a17f3b commit 7867088
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ data class ClusterMetricsInput(
return if (url.isEmpty()) {
constructUrlFromInputs()
} else {
URIBuilder(url).build()
try {
URIBuilder(url).build()
} catch (e: URISyntaxException) {
throw IllegalArgumentException("Invalid URL syntax.")
}
}
}

Expand Down Expand Up @@ -243,7 +247,11 @@ data class ClusterMetricsInput(
.setHost(SUPPORTED_HOST)
.setPort(SUPPORTED_PORT)
.setPath(path + pathParams)
uriBuilder.build()
try {
uriBuilder.build()
} catch (e: URISyntaxException) {
throw IllegalArgumentException("Invalid URL syntax.")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,40 @@ class ClusterMetricsInputTests {
)
}
}

@Test
fun `test url field contains invalid characters`() {
// GIVEN
path = ""
pathParams = ""
url = "http://localhost:9200/${ILLEGAL_PATH_PARAMETER_CHARACTERS.joinToString("")}"

// WHEN + THEN
assertFailsWith<IllegalArgumentException>("Invalid URL syntax.") {
ClusterMetricsInput(
path = path,
pathParams = pathParams,
url = url,
clusters = listOf()
)
}
}

@Test
fun `test URI fields provided and url contains invalid characters`() {
// GIVEN
path = "/_cluster/health"
pathParams = "index1,index2,index3,index4,index5"
url = "http://localhost:9200/${ILLEGAL_PATH_PARAMETER_CHARACTERS.joinToString("")}"

// WHEN + THEN
assertFailsWith<IllegalArgumentException>("Invalid URL syntax.") {
ClusterMetricsInput(
path = path,
pathParams = pathParams,
url = url,
clusters = listOf()
)
}
}
}

0 comments on commit 7867088

Please sign in to comment.