Skip to content

Commit

Permalink
Refactor error handling in CredentialsService to raise ObjectNotFound…
Browse files Browse the repository at this point in the history
… for undefined services and enhance test coverage for invalid credential scenarios
  • Loading branch information
arash77 committed Feb 11, 2025
1 parent 243f9db commit 9a4c608
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/services/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _create_or_update_credentials(
user, source_id, source_version, service_name, service_version
)
if source_credentials is None:
raise RequestParameterInvalidException(
raise ObjectNotFound(
f"Service '{service_name}' with version '{service_version}' is not defined"
f"in {source_type} with id {source_id} and version {source_version}."
)
Expand Down
25 changes: 10 additions & 15 deletions test/integration/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,9 @@ def test_delete_credentials_group(self):

@skip_without_tool(CREDENTIALS_TEST_TOOL)
def test_provide_credential_invalid_group(self):
payload = {
"source_type": "tool",
"source_id": CREDENTIALS_TEST_TOOL,
"source_version": "test",
"credentials": [
{
"name": "service1",
"version": "1",
"current_group": "invalid_group_name",
"groups": [{"name": "default", "variables": [], "secrets": []}],
}
],
}
response = self._post("/api/users/current/credentials", data=payload, json=True)
self._assert_status_code_is(response, 400)
payload = self._build_credentials_payload()
payload["credentials"][0]["current_group"] = "invalid_group_name"
self._provide_user_credentials(payload, status_code=400)

def test_invalid_source_type(self):
payload = self._build_credentials_payload(source_type="invalid_source_type")
Expand All @@ -148,6 +136,13 @@ def test_not_existing_service_version(self):
payload = self._build_credentials_payload(service_version="nonexistent_service_version")
self._provide_user_credentials(payload, status_code=404)

@skip_without_tool(CREDENTIALS_TEST_TOOL)
def test_invalid_credential_name(self):
for key in ["variables", "secrets"]:
payload = self._build_credentials_payload()
payload["credentials"][0]["groups"][0][key][0]["name"] = "invalid_name"
self._provide_user_credentials(payload, status_code=400)

def test_delete_nonexistent_service_credentials(self):
response = self._delete("/api/users/current/credentials/f2db41e1fa331b3e")
self._assert_status_code_is(response, 400)
Expand Down

0 comments on commit 9a4c608

Please sign in to comment.