Skip to content

spring-test HtmlUnit does not recognize files for multipart uploading [SPR-13979] #18551

@spring-projects-issues

Description

@spring-projects-issues

Stephen Liang opened SPR-13979 and commented

Overview

The params method in HtmlUnitRequestBuilder does not check if a parameter contains a File payload, which results in a File input box to get its value (the path to the file) and submit it as a key/value rather than the payload being uploaded as multipart form data.

For Reference

https://github.com/spring-projects/spring-framework/blob/master/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java#L361

webRequest.getRequestParameters() is a KeyDataPair which contains a field called fileObject_. This field should be recognized and used in place of the value_ field which is the name of the field, rather than the content of the file (when the parameter is has a file).

To Reproduce

  1. Create a simple file upload form, e.g.:
<html><head></head><body>
<form enctype='multipart/form-data' action='"/upload"' method='POST'>
<input type='file' name='image' />
<input type='submit' id='clickMe'>
</form>
</body>
</html>
  1. Create a html unit test that sends the file path to the "file" input type
  2. Click on the submit button

Expected Result: The file contents are read and sent as form data
Actual Result: The file's name is sent as a key/value pair


Affects: 4.2 GA

0 votes, 5 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)status: ideal-for-contributionAn issue that a contributor can help us withstatus: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions