You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by al...@apache.org on 2021/06/03 19:24:08 UTC
[helix] branch master updated: Enforce id field in Helix rest to
update resource config (#1672)
This is an automated email from the ASF dual-hosted git repository.
alizamus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new a3b6a4d Enforce id field in Helix rest to update resource config (#1672)
a3b6a4d is described below
commit a3b6a4dd1d485c1c4ef16644ff4695572e253bbf
Author: Ali Reza Zamani Zadeh Najari <an...@linkedin.com>
AuthorDate: Thu Jun 3 12:23:57 2021 -0700
Enforce id field in Helix rest to update resource config (#1672)
In this commit, in the update resource config REST call, the id field
will be validated to avoid creation of ZNodes that does not have any
id.
---
.../server/resources/helix/ClusterAccessor.java | 2 +-
.../server/resources/helix/ResourceAccessor.java | 5 +++++
.../helix/rest/server/TestResourceAccessor.java | 23 ++++++++++++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
index a16821f..78010b9 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ClusterAccessor.java
@@ -501,7 +501,7 @@ public class ClusterAccessor extends AbstractHelixResource {
return badRequest("Input is not a valid ZNRecord!");
}
- if (!record.getId().equals(clusterId)) {
+ if (!clusterId.equals(record.getId())) {
return badRequest("ID does not match the cluster name in input!");
}
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
index 8c93c79..ec63076 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
@@ -422,6 +422,11 @@ public class ResourceAccessor extends AbstractHelixResource {
_logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
return badRequest("Input is not a valid ZNRecord!");
}
+
+ if (!resourceName.equals(record.getId())) {
+ return badRequest("ID does not match the resourceName name in input!");
+ }
+
ResourceConfig resourceConfig = new ResourceConfig(record);
ConfigAccessor configAccessor = getConfigAccessor();
try {
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java
index d194ccb..ce11b2f 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestResourceAccessor.java
@@ -380,6 +380,29 @@ public class TestResourceAccessor extends AbstractTestClass {
* @throws Exception
*/
@Test(dependsOnMethods = "updateResourceConfig")
+ public void updateResourceConfigIDMissing() throws Exception {
+ System.out.println("Start test :" + TestHelper.getTestMethodName());
+ // An invalid input which does not have any ID
+ String dummyInput = "{\"simpleFields\":{}}";
+
+ String dummyResourceName = "RESOURCE_TEST_DUMMY";
+ // Update the config with dummy input
+ Entity entity = Entity.entity(dummyInput, MediaType.APPLICATION_JSON_TYPE);
+ // As id field is missing, the response of the post request should be BAD_REQUEST
+ post("clusters/" + CLUSTER_NAME + "/resources/" + dummyResourceName + "/configs", null, entity,
+ Response.Status.BAD_REQUEST.getStatusCode());
+ ResourceConfig resourceConfig =
+ _configAccessor.getResourceConfig(CLUSTER_NAME, dummyResourceName);
+ // Since the id is missing in the input, the znode should not get created.
+ Assert.assertNull(resourceConfig);
+ System.out.println("End test :" + TestHelper.getTestMethodName());
+ }
+
+ /**
+ * Test "delete" command of updateResourceConfig.
+ * @throws Exception
+ */
+ @Test(dependsOnMethods = "updateResourceConfigIDMissing")
public void deleteFromResourceConfig() throws Exception {
ZNRecord record = new ZNRecord(RESOURCE_NAME);