JoaoJandre commented on code in PR #8418:
URL: https://github.com/apache/cloudstack/pull/8418#discussion_r1636636454


##########
engine/userdata/src/main/java/org/apache/cloudstack/userdata/UserDataManagerImpl.java:
##########
@@ -90,49 +90,54 @@ public String concatenateUserData(String userdata1, String 
userdata2, String use
 
     @Override
     public String validateUserData(String userData, BaseCmd.HTTPMethod 
httpmethod) {
-        byte[] decodedUserData = null;
-        if (userData != null) {
-
-            if (userData.contains("%")) {
-                try {
-                    userData = URLDecoder.decode(userData, "UTF-8");
-                } catch (UnsupportedEncodingException e) {
-                    throw new InvalidParameterValueException("Url decoding of 
userdata failed.");
-                }
-            }
+        if (StringUtils.isBlank(userData)) {
+            s_logger.debug("Null/empty user data set");
+            return null;
+        }
 
-            if (!Base64.isBase64(userData)) {
-                throw new InvalidParameterValueException("User data is not 
base64 encoded");
-            }
-            // If GET, use 4K. If POST, support up to 1M.
-            if (httpmethod.equals(BaseCmd.HTTPMethod.GET)) {
-                decodedUserData = validateAndDecodeByHTTPMethod(userData, 
MAX_HTTP_GET_LENGTH, BaseCmd.HTTPMethod.GET);
-            } else if (httpmethod.equals(BaseCmd.HTTPMethod.POST)) {
-                decodedUserData = validateAndDecodeByHTTPMethod(userData, 
MAX_HTTP_POST_LENGTH, BaseCmd.HTTPMethod.POST);
+        if (userData.contains("%")) {
+            try {
+                userData = URLDecoder.decode(userData, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                throw new InvalidParameterValueException("Url decoding of user 
data failed.");
             }
+        }
 
-            if (decodedUserData == null || decodedUserData.length < 1) {
-                throw new InvalidParameterValueException("User data is too 
short");
-            }
-            // Re-encode so that the '=' paddings are added if necessary since 
'isBase64' does not require it, but python does on the VR.
-            return Base64.encodeBase64String(decodedUserData);
+        if (!Base64.isBase64(userData)) {
+            throw new InvalidParameterValueException("User data is not base64 
encoded.");

Review Comment:
   Add the userdata in this message as well.



##########
engine/userdata/src/main/java/org/apache/cloudstack/userdata/UserDataManagerImpl.java:
##########
@@ -90,49 +90,54 @@ public String concatenateUserData(String userdata1, String 
userdata2, String use
 
     @Override
     public String validateUserData(String userData, BaseCmd.HTTPMethod 
httpmethod) {
-        byte[] decodedUserData = null;
-        if (userData != null) {
-
-            if (userData.contains("%")) {
-                try {
-                    userData = URLDecoder.decode(userData, "UTF-8");
-                } catch (UnsupportedEncodingException e) {
-                    throw new InvalidParameterValueException("Url decoding of 
userdata failed.");
-                }
-            }
+        if (StringUtils.isBlank(userData)) {
+            s_logger.debug("Null/empty user data set");
+            return null;
+        }
 
-            if (!Base64.isBase64(userData)) {
-                throw new InvalidParameterValueException("User data is not 
base64 encoded");
-            }
-            // If GET, use 4K. If POST, support up to 1M.
-            if (httpmethod.equals(BaseCmd.HTTPMethod.GET)) {
-                decodedUserData = validateAndDecodeByHTTPMethod(userData, 
MAX_HTTP_GET_LENGTH, BaseCmd.HTTPMethod.GET);
-            } else if (httpmethod.equals(BaseCmd.HTTPMethod.POST)) {
-                decodedUserData = validateAndDecodeByHTTPMethod(userData, 
MAX_HTTP_POST_LENGTH, BaseCmd.HTTPMethod.POST);
+        if (userData.contains("%")) {
+            try {
+                userData = URLDecoder.decode(userData, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                throw new InvalidParameterValueException("Url decoding of user 
data failed.");

Review Comment:
   ```suggestion
                   throw new InvalidParameterValueException(String.format("Url 
decoding of user data [%s] failed.", userData));
   ```
   If we are not logging it at the beginning of the method, could we at least 
add it to the exception's message? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to