Skip to content

Commit

Permalink
Forward compatibility with Commons FileUpload 2.x (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored May 14, 2024
1 parent dc06939 commit 468b97b
Showing 1 changed file with 6 additions and 8 deletions.
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();

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());
}
}

0 comments on commit 468b97b

Please sign in to comment.