From f7370d2b12f93827f3ed96d73f73f61d37457eda Mon Sep 17 00:00:00 2001 From: Timur Alperovich Date: Wed, 26 Aug 2015 09:22:25 -0700 Subject: [PATCH] JCLOUDS-217: Nova: do encode form parameters. OpenStack Nova tests should not pre-encode parameters before passing them to generate the HTTP requests, as they end up encoded twice. --- .../v2_0/features/ImageApiExpectTest.java | 21 ++++++++++++------- .../v2_0/features/ServerApiExpectTest.java | 14 ++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java index d70b111a77..f2d2689285 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiExpectTest.java @@ -29,6 +29,7 @@ import org.jclouds.openstack.nova.v2_0.parse.ParseImageListTest; import org.jclouds.openstack.nova.v2_0.parse.ParseImageTest; import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataListTest; import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest; +import org.jclouds.util.Strings2; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -265,11 +266,12 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { public void testGetMetadataItemWhenResponseIs2xx() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - String key = "Image%20Version"; + String key = "Image Version"; HttpRequest getMetadata = HttpRequest.builder() .method("GET") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); @@ -286,11 +288,12 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { public void testGetMetadataItemWhenResponseIs404() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - String key = "Image%20Version"; + String key = "Image Version"; HttpRequest getMetadata = HttpRequest.builder() .method("GET") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); @@ -328,11 +331,12 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - String key = "Image%20Version"; + String key = "Image Version"; HttpRequest deleteMetadata = HttpRequest.builder() .method("DELETE") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); @@ -347,11 +351,12 @@ public class ImageApiExpectTest extends BaseNovaApiExpectTest { public void testDeleteMetadataItemWhenResponseIs404() throws Exception { String imageId = "52415800-8b69-11e0-9b19-734f5736d2a2"; - String key = "Image%20Version"; + String key = "Image Version"; HttpRequest deleteMetadata = HttpRequest.builder() .method("DELETE") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/images/" + imageId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java index adfd85aad2..95cd4b36c6 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java @@ -34,6 +34,7 @@ import org.jclouds.openstack.nova.v2_0.parse.ParseMetadataUpdateTest; import org.jclouds.openstack.nova.v2_0.parse.ParseServerDetailsStatesTest; import org.jclouds.openstack.nova.v2_0.parse.ParseServerDiagnostics; import org.jclouds.openstack.nova.v2_0.parse.ParseServerListTest; +import org.jclouds.util.Strings2; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -618,7 +619,8 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { HttpRequest getMetadata = HttpRequest .builder() .method("GET") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/" + serverId + "/metadata/" + "Server%20Label") + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/" + serverId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); @@ -720,11 +722,12 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { public void testDeleteMetadataItemWhenResponseIs2xx() throws Exception { String serverId = "123"; - String key = "Server%20Label"; + String key = "Server Label"; HttpRequest updateMetadata = HttpRequest.builder() .method("DELETE") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/" + serverId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/" + serverId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build(); @@ -739,11 +742,12 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest { public void testDeleteMetadataItemWhenResponseIs404() throws Exception { String serverId = "123"; - String key = "Server%20Label"; + String key = "Server Label"; HttpRequest deleteMetadata = HttpRequest.builder() .method("DELETE") - .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/" + serverId + "/metadata/" + key) + .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/3456/servers/" + serverId + "/metadata/" + + Strings2.urlEncode(key)) .addHeader("Accept", "application/json") .addHeader("X-Auth-Token", authToken) .build();