PathsUpdate implements Updateable.Update { public static String parsePath(String path) throws SentryMalformedPathException { if (StringUtils.isEmpty(path)) { return null; } URI uri; try { uri = new URI(StringUtils.stripStart(new URIBuilder().setPath(path).toString(), "/")); } catch (URISyntaxException e) { throw new SentryMalformedPathException("Incomprehensible path [" + path + "]", e); } String scheme = uri.getScheme(); if (scheme == null) { scheme = DEFAULT_SCHEME; if(scheme == null) { throw new SentryMalformedPathException( "Scheme is missing and could not be constructed from configuration"); } } if(!scheme.equalsIgnoreCase(SUPPORTED_SCHEME)) { return null; } String uriPath = uri.getPath(); if(uriPath == null) { throw new SentryMalformedPathException("Path is empty. uri=" + uri); } if (!uriPath.startsWith("/")) { throw new SentryMalformedPathException("Path part of uri does not seem right, was expecting a non empty path" + ": path = " + uriPath + ", uri=" + uri); } if (uriPath.indexOf(" uriPath = uriPath.replaceAll(" } return StringUtils.strip(uriPath, "/"); } PathsUpdate();  PathsUpdate(TPathsUpdate tPathsUpdate);  PathsUpdate(long seqNum, boolean hasFullImage);  PathsUpdate(long seqNum, long imgNum, boolean hasFullImage); @Override boolean hasFullImage(); TPathChanges newPathChange(String authzObject); @Override long getSeqNum(); @Override void setSeqNum(long seqNum); @Override long getImgNum(); @Override void setImgNum(long imgNum); TPathsUpdate toThrift(); @VisibleForTesting static void setDefaultScheme(String scheme); static String parsePath(String path); @Override byte[] serialize(); @Override void deserialize(byte[] data); @Override void JSONDeserialize(String update); @Override String JSONSerialize(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final String ALL_PATHS; }
@Test public void testPositiveParsePath() throws SentryMalformedPathException { String urls[] = { "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: "hdfs: }; String path = "path1/path2/path3"; for (String url : urls) { String result = PathsUpdate.parsePath(url); Assert.assertEquals("Unexpected path in " + url, path, result); } }
@Test(expected = SentryMalformedPathException.class) public void testMalformedPathFunny() throws SentryMalformedPathException{ PathsUpdate.parsePath("hdfs: }
@Test public void testMalformedPathFile() throws SentryMalformedPathException{ String result = PathsUpdate.parsePath("file: Assert.assertNull("Parse path without throwing exception",result); }