public void testGetNodeLocation() throws Exception { MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com", null); MockCachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); String location = repository.getNodeLocation(mcus); String expected = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); expected = LockssRepositoryImpl.mapUrlToFileLocation(expected, "http://www.example.com"); assertEquals(expected, location); }
public void testDotUrlHandling() throws Exception { // testing correction of nodes with bad '..'-including urls, // filtering the first '..' but resolving the second // should filter out the first '..' line but resolve the second MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com/branch/test/../test2", null); MockCachedUrlSet mcus = new MockCachedUrlSet(mau, mspec); String location = repository.getNodeLocation(mcus); String expectedStart = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); String expected = LockssRepositoryImpl.mapUrlToFileLocation( expectedStart, "http://www.example.com/branch/test2"); assertEquals(expected, location); mspec = new MockCachedUrlSetSpec("http://www.example.com/branch/./test", null); mcus = new MockCachedUrlSet(mau, mspec); location = repository.getNodeLocation(mcus); expected = LockssRepositoryImpl.mapUrlToFileLocation( expectedStart, "http://www.example.com/branch/test"); assertEquals(expected, location); try { mspec = new MockCachedUrlSetSpec("http://www.example.com/..", null); mcus = new MockCachedUrlSet(mau, mspec); location = repository.getNodeLocation(mcus); fail("Should have thrown MalformedURLException."); } catch (MalformedURLException mue) { } try { mspec = new MockCachedUrlSetSpec("http://www.example.com/test/../../test2", null); mcus = new MockCachedUrlSet(mau, mspec); location = repository.getNodeLocation(mcus); fail("Should have thrown MalformedURLException."); } catch (MalformedURLException mue) { } }