mirror of https://github.com/apache/jclouds.git
Issue 433: don't accept empty userdata
This commit is contained in:
parent
0423f08a87
commit
892bc85d4e
|
@ -121,8 +121,9 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
|
||||||
* Unencoded data
|
* Unencoded data
|
||||||
*/
|
*/
|
||||||
public RunInstancesOptions withUserData(byte[] unencodedData) {
|
public RunInstancesOptions withUserData(byte[] unencodedData) {
|
||||||
checkArgument(checkNotNull(unencodedData, "unencodedData").length <= 16 * 1024,
|
int length = checkNotNull(unencodedData, "unencodedData").length;
|
||||||
"userData cannot be larger than 16kb");
|
checkArgument(length > 0, "userData cannot be empty");
|
||||||
|
checkArgument(length <= 16 * 1024, "userData cannot be larger than 16kb");
|
||||||
formParameters.put("UserData", Base64.encodeBytes(unencodedData));
|
formParameters.put("UserData", Base64.encodeBytes(unencodedData));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,7 @@ public class RunInstancesOptionsTest {
|
||||||
public void testWithSecurityGroup() {
|
public void testWithSecurityGroup() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.withSecurityGroup("test");
|
options.withSecurityGroup("test");
|
||||||
assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections
|
assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections.singletonList("test"));
|
||||||
.singletonList("test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,8 +91,7 @@ public class RunInstancesOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWithSecurityGroupStatic() {
|
public void testWithSecurityGroupStatic() {
|
||||||
RunInstancesOptions options = withSecurityGroup("test");
|
RunInstancesOptions options = withSecurityGroup("test");
|
||||||
assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections
|
assertEquals(options.buildFormParameters().get("SecurityGroup.1"), Collections.singletonList("test"));
|
||||||
.singletonList("test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -105,8 +103,7 @@ public class RunInstancesOptionsTest {
|
||||||
public void testWithAdditionalInfo() {
|
public void testWithAdditionalInfo() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.withAdditionalInfo("test");
|
options.withAdditionalInfo("test");
|
||||||
assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections
|
assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.singletonList("test"));
|
||||||
.singletonList("test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -118,8 +115,7 @@ public class RunInstancesOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWithAdditionalInfoStatic() {
|
public void testWithAdditionalInfoStatic() {
|
||||||
RunInstancesOptions options = withAdditionalInfo("test");
|
RunInstancesOptions options = withAdditionalInfo("test");
|
||||||
assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections
|
assertEquals(options.buildFormParameters().get("AdditionalInfo"), Collections.singletonList("test"));
|
||||||
.singletonList("test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -151,12 +147,16 @@ public class RunInstancesOptionsTest {
|
||||||
withUserData(null);
|
withUserData(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testWithUserDataEmpty() {
|
||||||
|
withUserData("".getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithInstanceType() {
|
public void testWithInstanceType() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.asType(InstanceType.C1_XLARGE);
|
options.asType(InstanceType.C1_XLARGE);
|
||||||
assertEquals(options.buildFormParameters().get("InstanceType"), Collections
|
assertEquals(options.buildFormParameters().get("InstanceType"), Collections.singletonList("c1.xlarge"));
|
||||||
.singletonList("c1.xlarge"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -168,8 +168,7 @@ public class RunInstancesOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWithInstanceTypeStatic() {
|
public void testWithInstanceTypeStatic() {
|
||||||
RunInstancesOptions options = asType(InstanceType.C1_XLARGE);
|
RunInstancesOptions options = asType(InstanceType.C1_XLARGE);
|
||||||
assertEquals(options.buildFormParameters().get("InstanceType"), Collections
|
assertEquals(options.buildFormParameters().get("InstanceType"), Collections.singletonList("c1.xlarge"));
|
||||||
.singletonList("c1.xlarge"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -205,22 +204,21 @@ public class RunInstancesOptionsTest {
|
||||||
public void testWithDeviceName() {
|
public void testWithDeviceName() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.withDeviceName("test");
|
options.withDeviceName("test");
|
||||||
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), Collections
|
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"),
|
||||||
.singletonList("test"));
|
Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullWithDeviceName() {
|
public void testNullWithDeviceName() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"),
|
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), Collections.EMPTY_LIST);
|
||||||
Collections.EMPTY_LIST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithDeviceNameStatic() {
|
public void testWithDeviceNameStatic() {
|
||||||
RunInstancesOptions options = withDeviceName("test");
|
RunInstancesOptions options = withDeviceName("test");
|
||||||
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"), Collections
|
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.DeviceName"),
|
||||||
.singletonList("test"));
|
Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -232,8 +230,7 @@ public class RunInstancesOptionsTest {
|
||||||
public void testWithMonitoringEnabled() {
|
public void testWithMonitoringEnabled() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.enableMonitoring();
|
options.enableMonitoring();
|
||||||
assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections
|
assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections.singletonList("true"));
|
||||||
.singletonList("true"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -245,8 +242,7 @@ public class RunInstancesOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWithMonitoringEnabledStatic() {
|
public void testWithMonitoringEnabledStatic() {
|
||||||
RunInstancesOptions options = enableMonitoring();
|
RunInstancesOptions options = enableMonitoring();
|
||||||
assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections
|
assertEquals(options.buildFormParameters().get("Monitoring.Enabled"), Collections.singletonList("true"));
|
||||||
.singletonList("true"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -277,8 +273,7 @@ public class RunInstancesOptionsTest {
|
||||||
public void testWithRamdisk() {
|
public void testWithRamdisk() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.withRamdisk("test");
|
options.withRamdisk("test");
|
||||||
assertEquals(options.buildFormParameters().get("RamdiskId"), Collections
|
assertEquals(options.buildFormParameters().get("RamdiskId"), Collections.singletonList("test"));
|
||||||
.singletonList("test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -290,8 +285,7 @@ public class RunInstancesOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWithRamdiskStatic() {
|
public void testWithRamdiskStatic() {
|
||||||
RunInstancesOptions options = withRamdisk("test");
|
RunInstancesOptions options = withRamdisk("test");
|
||||||
assertEquals(options.buildFormParameters().get("RamdiskId"), Collections
|
assertEquals(options.buildFormParameters().get("RamdiskId"), Collections.singletonList("test"));
|
||||||
.singletonList("test"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
@ -303,22 +297,21 @@ public class RunInstancesOptionsTest {
|
||||||
public void testWithVirtualName() {
|
public void testWithVirtualName() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
options.withVirtualName("test");
|
options.withVirtualName("test");
|
||||||
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), Collections
|
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"),
|
||||||
.singletonList("test"));
|
Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullWithVirtualName() {
|
public void testNullWithVirtualName() {
|
||||||
RunInstancesOptions options = new RunInstancesOptions();
|
RunInstancesOptions options = new RunInstancesOptions();
|
||||||
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"),
|
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), Collections.EMPTY_LIST);
|
||||||
Collections.EMPTY_LIST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithVirtualNameStatic() {
|
public void testWithVirtualNameStatic() {
|
||||||
RunInstancesOptions options = withVirtualName("test");
|
RunInstancesOptions options = withVirtualName("test");
|
||||||
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"), Collections
|
assertEquals(options.buildFormParameters().get("BlockDeviceMapping.VirtualName"),
|
||||||
.singletonList("test"));
|
Collections.singletonList("test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
|
Loading…
Reference in New Issue