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-73136] Adapt HTTP Request tests for Jetty 12 (EE 8) #172

Merged
merged 37 commits into from
Aug 9, 2024

Conversation

BorisYaoA
Copy link
Contributor

@BorisYaoA BorisYaoA commented Jul 8, 2024

see https://issues.jenkins.io/browse/JENKINS-73136

The goal of this PR is to adapt http-request-plugin for jetty 12 (EE8).
There was some tests failures with jenkins.plugins.http_request.HttpRequestStepTest and jenkins.plugins.http_request.HttpRequestTest so I had to fix them.
The most of the work is about adapting SimpleHandler classes to use Handler.Abstract

Testing done

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

pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
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.

Very nice! I ran this locally and it all works quite nicely. I fixed a handful of trivial bugs and cleaned up the code a little bit. There is just one issue remaining before I am ready to approve this PR.

assertEquals(uploadFile.length(), part.getSize());
assertEquals(uploadFile.getName(), part.getSubmittedFileName());
assertEquals(MimeType.APPLICATION_ZIP.getValue(), part.getContentType());
if (multipartInputStream != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Try setting a breakpoint here and running the test suite. In my tests multipartInputStream is always null, and the code inside the if statement is never executed. As such, this turns the test into a false negative—the assertions are never executed. Presumably the assertions were executed before, making this a regression.

Copy link
Contributor Author

@BorisYaoA BorisYaoA Aug 9, 2024

Choose a reason for hiding this comment

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

Thank you for the catch, yes multipartInputStream is always null on my side too.
With what @olamy suggested here BorisYaoA#1, it is no more used and it is more clear.

And Just FTR I've run the same test in debug mode on the actual master branch and multipartInputStream is always null so it seems that the finally below isn't doing nothing

} finally {
String MULTIPART =
"org.eclipse.jetty.servlet.MultiPartFile.multiPartInputStream";
MultiPartFormInputStream multipartInputStream =
(MultiPartFormInputStream) request.getAttribute(MULTIPART);
if (multipartInputStream != null) {
multipartInputStream.deleteParts();
}

assertEquals(content,
IOUtils.toString(modelPart.getInputStream(), StandardCharsets.UTF_8));
assertEquals(MimeType.APPLICATION_JSON.getValue(), modelPart.getContentType());
if (multipartInputStream != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@basil basil added the tests label Aug 7, 2024
BorisYaoA and others added 2 commits August 8, 2024 10:42
…into Adapt_http_request_for_jetty12

# Conflicts:
#	src/test/java/jenkins/plugins/http_request/HttpRequestTestBase.java
@olamy
Copy link
Member

olamy commented Aug 9, 2024

regarding Jetty 12 core handller multipart feel to look at BorisYaoA#1
The secret is with those 2 lines of code ;)

String contentType = request.getHeaders().get(HttpHeader.CONTENT_TYPE);
MultiPartFormData.Parts parts = MultiPartFormData.from(request, request, contentType, new MultiPartConfig.Builder().build()).get();

@BorisYaoA
Copy link
Contributor Author

BorisYaoA commented Aug 9, 2024

regarding Jetty 12 core handller multipart feel to look at BorisYaoA#1 The secret is with those 2 lines of code ;)

String contentType = request.getHeaders().get(HttpHeader.CONTENT_TYPE);
MultiPartFormData.Parts parts = MultiPartFormData.from(request, request, contentType, new MultiPartConfig.Builder().build()).get();

Thank you @olamy, it is what I was missing for handling Parts

@BorisYaoA BorisYaoA requested a review from basil August 9, 2024 07:54
@BorisYaoA BorisYaoA marked this pull request as ready for review August 9, 2024 09:48
@BorisYaoA BorisYaoA requested a review from a team as a code owner August 9, 2024 09:48
basil added 2 commits August 9, 2024 08:59
"If false is returned, then this method must not generate a response, nor complete the callback."
@MarkEWaite MarkEWaite added developer Pull requests that improve developer experience and removed tests labels Aug 9, 2024
@MarkEWaite MarkEWaite changed the title [JENKINS-73136] Adapt HTTP Request for Jetty 12 (EE 8) [JENKINS-73136] Adapt HTTP Request tests for Jetty 12 (EE 8) Aug 9, 2024
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.

Thanks for the PR!

@basil basil merged commit fa04893 into jenkinsci:master Aug 9, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer Pull requests that improve developer experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants