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-70240] fix for non http based UpdateCenter URLs cause exception in plugin manager #7520

Closed
wants to merge 3 commits into from

Conversation

julieheard
Copy link
Contributor

@julieheard julieheard commented Dec 14, 2022

  • Local update centers use local json files which are valid
  • I have added the value.replace("file:/", ""); as when using a war, it adds 'file:/' to the path
  • This checks if the file is a valid file and if true returns FormValidation.ok

See JENKINS-70240.

Testing done

Steps:

  • Forked Repo and opened local version in intelliJ
  • Made code changes as seen in this PR
  • did mvn install -Dmaven.test.skip=true skipping the tests at first as they took hours to run through all tests
  • manually tested to see if demon jenkins appeared. Manual tests involved inputting a valid URL, putting invalid URL, putting valid file location, putting invalid file location
  • finally did mvn install without skipping the tests to check all tests passed

Before:
image

After:
image
image
image

This issue was caused by #6886 which did not have any tests written for the method. I have not written any tests for the method as a whole yet.

Proposed changelog entries

  • Entry 1: Non-HTTP based UpdateCenter URLs do not cause exception in plugin manager

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples).
    • Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@mention

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

- Local update centers use local json files which are valid
- I have added the value.replace("file:/", ""); as when using a war, it adds 'file:/' to the path
- This checks if the file is a valid file and if true returns FormValidation.ok
Update error message for when invalid URL message appears.
@julieheard julieheard changed the title [JENKINS-70240] fix for non http based UpdateCenter URLS cause exception in plugin manager [JENKINS-70240] fix for non http based UpdateCenter URLs cause exception in plugin manager Dec 14, 2022
@NotMyFault NotMyFault added the regression-fix Pull request that fixes a regression in one of the previous Jenkins releases label Dec 14, 2022
@@ -1966,6 +1966,13 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
return FormValidation.error(Messages.PluginManager_emptyUpdateSiteUrl());
}

//Check to see if the value is a file as some update centers are local json files
Copy link
Member

Choose a reason for hiding this comment

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

will involve a file lookup for something like http://foo.example.com/bar
e.g.
new File("http://foo.example.com/bar").exists()

Rather than check for something that is obviously bogus perhaps first the URI should be created.
Then if it is a file based one do X, if it is http/https do Y (create another URI from the parsed URI appending the query parameter for the version)
if it is anything else return an FormValidation.warning("unable to check validity of update center due to protocol -> the protocol")

core/src/main/resources/hudson/Messages.properties Outdated Show resolved Hide resolved
if (file.isFile()) {
return FormValidation.ok();
}

Copy link
Member

Choose a reason for hiding this comment

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

if the url is file://foo but the file does not exist we keep on trucking as if it is HTTP which is doomed to failure.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Since this functionality is rarely used, I think it is at a high risk of regression during future code changes. For this reason, I think it would be desirable to add a test to ensure this fix does not regress in the future. I think it should be straightforward to ensure that files that exist pass form validation and files that do not exist fail form validation. Such a test could even likely be written without JenkinsRule. An example of a recent change that added a similar form validation test is #7508, and git grep doCheck | grep src.test turns up several more examples.

@basil basil added the needs-testcase Test automation is required for this pull request label Dec 14, 2022
Updated wording on invalidURL
@basil
Copy link
Member

basil commented Dec 17, 2022

Closing in favor of #7524.

@basil basil closed this Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-testcase Test automation is required for this pull request regression-fix Pull request that fixes a regression in one of the previous Jenkins releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants