Skip to content

[JENKINS-48625] Restore binding of doCheckUrl methods and add some initial checks #841

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

Merged
merged 20 commits into from
Mar 1, 2020

Conversation

rishabhBudhouliya
Copy link
Contributor

@rishabhBudhouliya rishabhBudhouliya commented Feb 19, 2020

JENKINS-48625

The earlier doCheckUrl methods used to open a connection to validate a particular browser URL but that can be avoided (mostly) by adding some initial checks based on URL syntax validity and domain name match of the particular browser.

This change has been implemented for AssemblaWeb, GitBlitRepositoryBrowser, Gitiles and ViewGitWeb.

Note: A test file has been written for AssemblaWeb class, if it is considered okay then will do the same thing for the other 3 browser classes as well.

Submitter Checklist

  • I have read the CONTRIBUTING doc
  • I have referenced the Jira issue related to my changes in one or more commit messages
  • I have added tests that verify my changes
  • Unit tests pass locally with my changes
  • I have added documentation as necessary
  • No Javadoc warnings were introduced with my changes
  • No spotbugs warnings were introduced with my changes
  • I have interactively tested my changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Reviewer Checklist

  • Interactive test the assemblaweb doCheck method
  • Interactive test the other doCheck methods
  • Review the code in the other doCheck methods
  • Look for changes that are purely white space and remove them

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Feb 20, 2020

Thanks for the proposal. I started the code review today by walking through the new test in the debugger and watching that it reached all the branches of doCheckUrl(). Good work!

I pushed a commit in f99b832 . You are welcome to discard those changes if you're uncomfortable with them.

The key things that I would suggest for your consideration in the test are:

  • Prefer the hamcrest assertThat style as the newer form of JUnit assertions
  • Prefer a ClassRule to construct a single JenkinsRule for the entire test (faster execution)
  • Prefer a single assertion per test when feasible
  • Add a test that reaches the "This is a valid URL but it does not look like Assembla"

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

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

commons-validator comments

@rishabhBudhouliya
Copy link
Contributor Author

Thank you for reviewing the PR @MarkEWaite .
First, thanks for merging the master first, I should have done that before raising this PR. I branched from commits of unmerged #830, hence those two more commits.

I've seen many of the suggestions you have mentioned implemented in GitClientTest (Git-Client-Plugin), I'll follow these suggestions and take it as a reference point.

Thanks for the commit f99b832, those changes (good-practices) will give me a head start on making a better test class.

@Saucistophe
Copy link

LGTM, thanks for the fixing effort!

I had to read very carefully to detect the syntactic errors in the URL.
The comment helps me see more clearly.
Avoid undue load on any one server for this test.
@MarkEWaite MarkEWaite changed the title Jenkins-48625 fix: Restore binding of doCheckUrl methods and add some initial checks [JENKINS-48625] Restore binding of doCheckUrl methods and add some initial checks Feb 20, 2020
@rishabhBudhouliya
Copy link
Contributor Author

@Saucistophe thanks for the review!

@MarkEWaite I have taken the liberty of tweaking the code a little seeing this test case testPathLevelChecksOnRepoUrlSupersetOfAssembla().
Instead of opening a connection to check this, I have added an initial check on the hostname.
The check would ensure that the written browser-name should be followed by a "."
For ex: assemblas.com or assemblaxx.com will be rejected because it expects a "." right after "assembla"

@MarkEWaite
Copy link
Contributor

That's a great choice. I assume you'll delete that test or rework it so that it is useful based on your change?

@rishabhBudhouliya
Copy link
Contributor Author

That's a great choice. I assume you'll delete that test or rework it so that it is useful based on your change?

I have re-worked the test, now it asserts that the FormValidation message is "Invalid URL"

@@ -105,7 +103,7 @@ public FormValidation doCheckRepoUrl(@AncestorInPath Item project, @QueryParamet
return FormValidation.ok();
}
FormValidation response;
if (checkURIFormat(cleanUrl)) {
if (checkURIFormat(cleanUrl, "gitblit")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you can reasonably assume that a gitblit server must include gitblit in the hostname. Assembla only provides a hosted solution, so it is safe to check their specific hostname. Gitblit provides a solution that is either hosted or on premise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I never anticipated this obvious case. My implementation was based on this assumption that the hostname of the URL will contain the browser name (for ex: http://gitblit.example.com/).

As far as my understanding goes, either I can:

  • remove this assumption, but then would have to provide a custom implementation for Assembla, i.e making checkURIFormat an abstract method.
  • branch the logic into two cases, hosted check and on-premise check.

What do you think?

Copy link
Contributor

@MarkEWaite MarkEWaite Feb 20, 2020

Choose a reason for hiding this comment

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

I think that Assembla is the exception in this case. Most git hosting providers allow a hosted implementation and an implementation that is installed and maintained inside the user network.

I think it would be better to place checkURIFormat (or some more specific implementation of it) inside the Assembla specific class and then place something more general in the GitRepositoryBrowser class. The part of checkURIFormat that confirms the URL is an http or https URL is useful in all cases. The part that checks for a specific substring in the hostname is likely limited to Assembla and possibly a few others.

Copy link
Contributor Author

@rishabhBudhouliya rishabhBudhouliya Feb 21, 2020

Choose a reason for hiding this comment

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

Most git hosting providers allow a hosted implementation and an implementation that is installed and maintained inside the user network.

This means that creating a simple host name check is not feasible, hence I have created a separate checkURIFormatAndHostName for AssemblaWeb since Assembla provides a hosted solution only. For others, it's just a plain UrlValidatior check. For reference, the commit is 4a0915a .

return FormValidation.ok();
}
FormValidation response;
if (checkURIFormat(cleanUrl)) {
if (checkURIFormat(cleanUrl, "gerrit")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't assume that the Gerrit server includes "gerrit" in its hostname.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, implementation has been changed.

return FormValidation.ok();
}
FormValidation response;
if (checkURIFormat(cleanUrl)) {
if (checkURIFormat(cleanUrl, "viewgit")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't assume viewgit server contains viewgit in its hostname, I think?

}.check();
}.check();
} else {
response = FormValidation.error(Messages.invalidUrl());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be replaced with a return instead of storing the value the returning one statement later.

Suggested change
response = FormValidation.error(Messages.invalidUrl());
return FormValidation.error(Messages.invalidUrl());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, changed it.

} else {
response = FormValidation.error(Messages.invalidUrl());
}
return response;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be removed as part of removing the temporary variable response.

Suggested change
return response;

} else {
return FormValidation.error("This is a valid URL but it doesn't look like ViewGit");
}
FormValidation response;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this temporary is required, since the call to checkURIFormat can return from both the true and the false conditions.

Suggested change
FormValidation response;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, changed it.

throws UnsupportedEncodingException {
return param(url).add("p=" + projectName).add("a=commitdiff").add("h=" + path.getChangeSet().getId()) + "#" + URLEncoder.encode(path.getPath(),"UTF-8").toString();
}
private String buildCommitDiffSpec(URL url, Path path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't "fix" whitespace because it causes unnecessary conflicts in other pull requests. Refer to the style guide in the contributing guideline for this repo. In many other places it would be a good thing to correct the horribly inconsistent code formatting style. In this particular plugin, it is not a good thing to correct the code formatting style.

Suggested change
private String buildCommitDiffSpec(URL url, Path path)
private String buildCommitDiffSpec(URL url, Path path)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I apologize I've constantly ignored whitespace conflicts, I ran "Reformat Code" option available in IntelliJ which fixed all these whitespaces.

I have tried to fix all of them in the latest commit, I hope I have reverted all these fixes.

@rishabhBudhouliya
Copy link
Contributor Author

@MarkEWaite after the latest commit 5f48308, are there any more changes you would recommend? If not so, then I can create similar UTs for the other three browsers as well and move forward with the status of this PR.

@MarkEWaite
Copy link
Contributor

I need to review the current code again. It will likely be tomorrow before I can review it.

@MarkEWaite MarkEWaite added bugfix Fixes a bug - used by Release Drafter ShortTerm Short term Improvements labels Feb 21, 2020
@MarkEWaite MarkEWaite self-assigned this Feb 21, 2020
@MarkEWaite MarkEWaite added this to the Git Plugin 4.2.0 release milestone Feb 21, 2020
@rishabhBudhouliya
Copy link
Contributor Author

Since you have just mentioned that you are going to be busy next week, are you planning to review this PR and PR-830 within the time frame of the new release?

I just need your comments on the current commits and I will try to push the changes after your review as fast as possible.

@MarkEWaite
Copy link
Contributor

Thanks for asking! Based on travel schedule, I'll likely release 4.2 tomorrow as it currently exists on the master branch then reassign the remaining pull requests to a later release (4.2.1 or 4.3).

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

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

I've made some further changes to reduce whitespace diffs. Automated tests continue to pass. I'll perform interactive tests.

Are there other changes you'd like to make or would you prefer it be merged? I will likely release 4.2 24-30 hours from now.

@rishabhBudhouliya
Copy link
Contributor Author

rishabhBudhouliya commented Mar 1, 2020

Thanks for the review Mark! I don't suspect any further changes right now, you may merge it.

Apart from this PR, if there is any other documentation related task or fix pending for the new release, would be glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes a bug - used by Release Drafter ShortTerm Short term Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants