bharatviswa504 commented on a change in pull request #1196: URL: https://github.com/apache/hadoop-ozone/pull/1196#discussion_r455410736
########## File path: hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/TestNormalizePaths.java ########## @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.hadoop.ozone.om.request; + +import org.junit.Assert; +import org.junit.Test; + +import static org.apache.hadoop.ozone.om.request.OMClientRequest.getNormalizedKey; + +/** + * Class to test normalize paths. + */ +public class TestNormalizePaths { + + @Test + public void testNormalizePathsEnabled() { + + Assert.assertEquals("a/b/c/d", + getNormalizedKey(true, "a/b/c/d")); + Assert.assertEquals("a/b/c/d", + getNormalizedKey(true, "/a/b/c/d")); + Assert.assertEquals("a/b/c/d", + getNormalizedKey(true, "////a/b/c/d")); + Assert.assertEquals("a/b/c/d", + getNormalizedKey(true, "////a/b/////c/d")); + Assert.assertEquals("a/b/c/...../d", + getNormalizedKey(true, "////a/b/////c/...../d")); + Assert.assertEquals("a/b/d", + getNormalizedKey(true, "/a/b/c/../d")); + Assert.assertEquals("a/d", Review comment: Done ########## File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java ########## @@ -265,4 +272,24 @@ public AuditMessage buildAuditMessage(AuditAction op, auditMap.put(OzoneConsts.VOLUME, volume); return auditMap; } + + @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") + public static String getNormalizedKey(boolean enableFileSystemPaths, Review comment: Moved common logic to a new method. ########## File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/OMClientRequest.java ########## @@ -265,4 +272,24 @@ public AuditMessage buildAuditMessage(AuditAction op, auditMap.put(OzoneConsts.VOLUME, volume); return auditMap; } + + @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") + public static String getNormalizedKey(boolean enableFileSystemPaths, + String keyName) { + if (enableFileSystemPaths) { + String normalizedKeyName; + if (keyName.startsWith(OM_KEY_PREFIX)) { + normalizedKeyName = Paths.get(keyName).toUri().normalize().getPath(); + } else { + normalizedKeyName = Paths.get(OM_KEY_PREFIX, keyName).toUri() + .normalize().getPath(); + } + if (!keyName.equals(normalizedKeyName)) { + LOG.debug("Normalized key {} to {} ", keyName, normalizedKeyName); Review comment: Done ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
