Permalink
Browse files

Merge pull request #3 from lordofthejars/master

[FIXED JENKINS-30926] fieldName could be blank
  • Loading branch information...
jglick committed Oct 19, 2015
2 parents 4cb272d + 76766cd commit 792b70b3e5eab482c68cd86ac28c0914b5855f9c
@@ -1,2 +1,4 @@
target
work
.idea/
*.iml
@@ -42,6 +42,12 @@
<artifactId>credentials</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
@@ -67,6 +67,12 @@
this.fileName = fileName;
this.data = Base64.decodeBase64(data);
}
if (this.fileName == null || this.fileName.isEmpty()) {
throw new IllegalArgumentException(
String.format("No FileName was provided or resolved. " +
"Input file item was %s and input file name was %s.", file.toString(), fileName)
);
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "for {0} have {1} of length {2} after upload of ‘{3}’", new Object[] {getId(), this.fileName, unencrypted().length, name});
}
@@ -0,0 +1,136 @@
/*
* The MIT License
*
* Copyright 2015 asotobu.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jenkinsci.plugins.plaincredentials;

import com.cloudbees.plugins.credentials.CredentialsScope;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemHeaders;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

public class FileCredentialsTest {

@Test(expected = IllegalArgumentException.class)
@Issue("JENKINS-30926")
public void shouldThrowAnExceptionIfFileNameIsBlank() throws IOException {
FileCredentials fileCredentials = new FileCredentialsImpl(CredentialsScope.GLOBAL, "1", "",
new StubFileItem(), "", "");
}

private class StubFileItem implements FileItem {

@Override
public InputStream getInputStream() throws IOException {
return null;
}

@Override
public String getContentType() {
return null;
}

@Override
public String getName() {
return "";
}

@Override
public boolean isInMemory() {
return false;
}

@Override
public long getSize() {
return 0;
}

@Override
public byte[] get() {
return new byte[0];
}

@Override
public String getString(String encoding) throws UnsupportedEncodingException {
return null;
}

@Override
public String getString() {
return null;
}

@Override
public void write(File file) throws Exception {

}

@Override
public void delete() {

}

@Override
public String getFieldName() {
return null;
}

@Override
public void setFieldName(String name) {

}

@Override
public boolean isFormField() {
return false;
}

@Override
public void setFormField(boolean state) {

}

@Override
public OutputStream getOutputStream() throws IOException {
return null;
}

@Override
public FileItemHeaders getHeaders() {
return null;
}

@Override
public void setHeaders(FileItemHeaders headers) {

}
}

}

0 comments on commit 792b70b

Please sign in to comment.