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

Content-Type Header for Multipart-Requests should be checked case-insensitive #2707

Merged
merged 6 commits into from May 17, 2024

Conversation

mufasa1976
Copy link
Contributor

References

When testing SOAP-Requests with MTOM enabled the Standard SAAJ Implementation sends a HTTP-Header Content-Type: Multipart/Related; boundary=.... This leads to a Failure on Wiremock Multipart Behaviour because it only has checked against lowercased multipart/.

Instead it checks against a case-insensitive Regular-Expression ^multipart/.*.

Can this be also merged to the Java-8 related Versions?

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@mufasa1976 mufasa1976 requested a review from a team as a code owner May 4, 2024 14:00
@dieppa dieppa self-assigned this May 14, 2024
@dieppa
Copy link
Contributor

dieppa commented May 14, 2024

Hello @mufasa1976 , can you fix the pipeline, so we can review it.

Thanks!

but without knowing what to fix because on my local machine there will be no error
@mufasa1976
Copy link
Contributor Author

I've tried to fix the formatting Issues on MultipartBodyMatchingAcceptanceTest without knowing what to fix.
Unfortunatly this try also fails and I don't know where to look for the formatting Rules which the Code violates.

On my local Machine (Ubuntu 22.04.4 LTS) the Task ./gradlew :check --stacktrace --no-daemon leads no no violations.
Can you please help me just saying, which rules the Test-Code violates? And maybe why the Gradle-Task would not fail on my local Machine?

Thank you very much

@dieppa
Copy link
Contributor

dieppa commented May 14, 2024

Can you give it a try running ./gradlew :spotlessApply ?

@mufasa1976
Copy link
Contributor Author

mufasa1976 commented May 14, 2024

I've tried but there were no File changes after ./gradlew :spotlessApply

@@ -289,7 +289,7 @@ public Collection<Part> getParts() {
@Override
public boolean isMultipart() {
String header = getHeader("Content-Type");
return (header != null && header.contains("multipart/"));
return (header != null && header.matches("(?i)^multipart/.*"));
Copy link
Contributor

@dieppa dieppa May 15, 2024

Choose a reason for hiding this comment

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

Generally speaking this is right and improve the current behaviour(not only for case insensitive aspect), but I would like to support also potential white spaces at the beginning. I suggest to trim the String or add it in the regular expression.

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 agree. I've updated the regular Expression to ignore any whitespace character at the beginning of content-type

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, one. Can you keep both, with and without spaces?😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This regular Expression already handles both cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or did you mean the Test Case?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, I meant the test case,hehe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, i've adapted the Test so that the same Content will be sent twice. One time with leading spaces before the content-type and one time without leading spaces

@dieppa
Copy link
Contributor

dieppa commented May 16, 2024

Nice work! Just one last change and it's done; keep two independent methods, one without spaces(acceptsAMultipartRequestWithCamelcasedContentTypeInformation) and another one with them(acceptsAMultipartRequestWithCamelcasedContentTypeInformationWithLeadingSpaces).

It sounds stupid, but that makes clear and easier to spot what has gone wrong in the future.

@dieppa
Copy link
Contributor

dieppa commented May 16, 2024

Regarding the formatting, this should work:

  1. run ./gradlew spotlessJavaCheck -> This should fail
  2. run ./gradlew :spotlessApply -> This should fix it

However, if this doesn't work, let me know.

@mufasa1976
Copy link
Contributor Author

Nice work! Just one last change and it's done; keep two independent methods, one without spaces(acceptsAMultipartRequestWithCamelcasedContentTypeInformation) and another one with them(acceptsAMultipartRequestWithCamelcasedContentTypeInformationWithLeadingSpaces).

It sounds stupid, but that makes clear and easier to spot what has gone wrong in the future.

Ok, I have splitted one test into 2 tests with the appropriate Method-Names

@mufasa1976
Copy link
Contributor Author

Regarding the formatting, this should work:

  1. run ./gradlew spotlessJavaCheck -> This should fail
  2. run ./gradlew :spotlessApply -> This should fix it

However, if this doesn't work, let me know.

Thank you very much. Indead this had helped!

@dieppa
Copy link
Contributor

dieppa commented May 17, 2024

Merged it!

And sorry for the formatting, I believe the fix is just run those comments I mentioned, but we want to ensure and will document it.

Thanks for your contribution

@dieppa dieppa merged commit 5471681 into wiremock:master May 17, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants