Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-74964] Display error message when adding invalid certificate credentials #580

Merged
merged 9 commits into from
Dec 20, 2024

Conversation

Priya-CB
Copy link
Contributor

@Priya-CB Priya-CB commented Dec 6, 2024

JENKINS-74964

  • The "Add Credentials" popup now correctly displays an error message when users attempt to add invalid certificate credentials. Previously, the validation errors were shown on the form but no error message appeared upon clicking "Add," leading to a silent rejection of the credentials.

Testing done

Automated Unit Testing

Implemented unit tests to verify that the error messages are returned in the response on form submit

Manual Testing

  1. Adding certificate credentials with invalid inputs (e.g., empty PEM-encoded certificates or password < 14 characters in FIPS mode).
  2. Verified that clicking "Add" prevents invalid credentials from being stored and displays an appropriate error message to the user.

Popup screen:

Screenshot 2024-12-06 at 9 19 12 PM Screenshot 2024-12-06 at 9 14 04 PM Screenshot 2024-12-06 at 9 23 39 PM Screenshot 2024-12-06 at 8 19 14 PM

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@Priya-CB Priya-CB marked this pull request as ready for review December 6, 2024 18:57
@Priya-CB Priya-CB requested a review from a team as a code owner December 6, 2024 18:57
@@ -123,6 +123,7 @@ window.credentials.addSubmit = function (_) {
.catch((e) => {
// notificationBar.show(...) with logging ID could be handy here?
console.error("Could not add credentials:", e);
window.notificationBar.show("Credentials creation failed.", window.notificationBar["ERROR"]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Add Credentials" popup does not handle HTML responses ("angry Jenkins"), causing the catch block to execute. Added notificationBar to inform the user about the failure(unexpected cases) in credential creation.

@jtnord jtnord requested a review from a team December 10, 2024 11:54
Comment on lines 626 to 627
* Descriptor#newInstanceImpl throws a LinkageError if the constructor throws any exception other
* than HTTP response exceptions such as Descriptor.FormException.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK FormException is not a RuntimeException, and only `RuntimeException are not causing a LinkageError: https://github.com/jenkinsci/jenkins/blob/171097618b5b2b70ec3142e3efc80b4f2aff9601/core/src/main/java/hudson/model/Descriptor.java#L623 so

Suggested change
* Descriptor#newInstanceImpl throws a LinkageError if the constructor throws any exception other
* than HTTP response exceptions such as Descriptor.FormException.
* Descriptor#newInstanceImpl throws a LinkageError if the DataBoundConstructor or any DataBoundSetter throw any exception other
* than RuntimeException implementing HttpResponse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While FormException itself is not a RuntimeException, it is wrapped into HttpResponses, which is a RuntimeException,
https://github.com/jenkinsci/stapler/blob/master/core/src/main/java/org/kohsuke/stapler/RequestImpl.java#L691

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, that's incorrect. As for https://github.com/jenkinsci/jenkins/blob/171097618b5b2b70ec3142e3efc80b4f2aff9601/core/src/main/java/hudson/model/Descriptor.java#L622-L627 the Linkage error only can happen if the caught exception is RuntimeException AND HttpResponse. FormException is not in the catch clause, so it's not caught at all but directly thrown as stated in the method signature. The only way of getting a LinkageError is that the error is a NoSuchMethodException, an InstantiationException, an IllegalAccessException, an InvocationTargetException, or a RuntimeException that is not implementing HttpResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct that FormException is not explicitly in the catch clause of Descriptor#newInstanceImpl. However, my point was that FormException, when thrown, is wrapped into HttpResponses and HttpResponses is a RuntimeException.
Because of this wrapping, it ultimately satisfies the condition of being a RuntimeException and implementing HttpResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment

Copy link

@jmdesprez jmdesprez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with previous reviews/comments

@fcojfernandez fcojfernandez merged commit bcda74a into jenkinsci:master Dec 20, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants