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

Forward compatibility with Commons FileUpload 2.x #70

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.List;

import com.cloudbees.plugins.credentials.SecretBytes;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.FileItem;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.junit.Before;
Expand All @@ -26,6 +26,7 @@
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;

import hudson.model.FileParameterValue.FileItemImpl;
import hudson.security.ACL;
import hudson.util.Secret;

Expand Down Expand Up @@ -64,7 +65,7 @@ public void secretFileBaseTestWithDeprecatedCtor() throws IOException, URISyntax
}

private void secretFileTest(boolean useDeprecatedConstructor) throws IOException, URISyntaxException {
DiskFileItem fileItem = createEmptyFileItem();
FileItem fileItem = createEmptyFileItem();
Copy link
Member

@jtnord jtnord May 14, 2024

Choose a reason for hiding this comment

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

also relying on a Jenkins API rather than a particular third-party implementation will allow us to swap out the implementation in the future in jenkinsci/jenkins#9259 without breaking this test.

this is org.apache.commons.fileupload.FileItem and not a Jenkins API so this is still tied to an implementation (ie commons file upload) (albeit less of an implementation than before as this covers both v1 and v2).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly; your understanding is correct. I'll clarify this in detail when I write this up.


FileCredentialsImpl credential;

Expand Down Expand Up @@ -129,10 +130,7 @@ private <T extends BaseStandardCredentials> void testCreateUpdateDelete(T creden
* @throws FileNotFoundException
* @throws IOException
*/
private DiskFileItem createEmptyFileItem() throws URISyntaxException, FileNotFoundException, IOException {
DiskFileItem fileItem = (DiskFileItem) new DiskFileItemFactory().createItem("fileData", "text/plain", true, "fileName");
OutputStream os = fileItem.getOutputStream();
os.flush();
return fileItem;
private FileItem createEmptyFileItem() throws IOException {
return new FileItemImpl(Files.createTempFile("credential-test", null).toFile());
}
}