|
28 | 28 |
|
29 | 29 | import java.io.File;
|
30 | 30 | import java.io.IOException;
|
31 |
| -import java.net.URI; |
32 | 31 | import java.nio.file.Files;
|
33 | 32 | import java.nio.file.Path;
|
34 | 33 | import java.nio.file.Paths;
|
|
44 | 43 | import org.opengrok.indexer.condition.ConditionalRun;
|
45 | 44 | import org.opengrok.indexer.condition.ConditionalRunRule;
|
46 | 45 | import org.opengrok.indexer.condition.UnixPresent;
|
47 |
| -import org.opengrok.indexer.web.Util; |
48 | 46 |
|
49 | 47 | /**
|
50 | 48 | * Represents a container for tests of {@link PathUtils}.
|
@@ -146,6 +144,43 @@ public void shouldHandleLinksOfArbitraryDepthWithValidation()
|
146 | 144 | assertEquals("because link is OKed", "b/" + SYMLINK2, rel);
|
147 | 145 | }
|
148 | 146 |
|
| 147 | + @Test |
| 148 | + @ConditionalRun(UnixPresent.class) |
| 149 | + public void shouldHandleLinksToCanonicalChildrenOfAllowedLinks() |
| 150 | + throws IOException, ForbiddenSymlinkException { |
| 151 | + // Create real directories |
| 152 | + File sourceRoot = createTemporaryDirectory("srcroot"); |
| 153 | + assertTrue(sourceRoot + " should be a dir", sourceRoot.isDirectory()); |
| 154 | + |
| 155 | + File realDir1 = createTemporaryDirectory("realdir1"); |
| 156 | + assertTrue(realDir1 + " should be a dir", realDir1.isDirectory()); |
| 157 | + |
| 158 | + File realDir1b = new File(realDir1, "b"); |
| 159 | + assertTrue(realDir1b + " should be created", realDir1b.mkdir()); |
| 160 | + |
| 161 | + // Create symlink #1 to realdir1/ in source root. |
| 162 | + final String SYMLINK1 = "symlink1"; |
| 163 | + File symlink1 = new File(sourceRoot, SYMLINK1); |
| 164 | + Files.createSymbolicLink(symlink1.toPath(), realDir1.toPath()); |
| 165 | + assertTrue(symlink1 + " should exist", symlink1.exists()); |
| 166 | + |
| 167 | + // Create symlink #2 to realdir1/b in source root. |
| 168 | + final String SYMLINK2 = "symlink2"; |
| 169 | + File symlink2 = new File(realDir1b, SYMLINK2); |
| 170 | + Files.createSymbolicLink(symlink2.toPath(), realDir1b.toPath()); |
| 171 | + assertTrue(symlink2 + " should exist", symlink2.exists()); |
| 172 | + |
| 173 | + // Test symlink2 v. realDir1 canonical with validation and an allowed symlink1 |
| 174 | + Set<String> allowedSymLinks = new HashSet<>(); |
| 175 | + allowedSymLinks.add(symlink1.getPath()); |
| 176 | + |
| 177 | + String realDir1Canon = realDir1.getCanonicalPath(); |
| 178 | + String rel = PathUtils.getRelativeToCanonical(symlink2.toString(), |
| 179 | + realDir1Canon, allowedSymLinks, null); |
| 180 | + assertEquals("symlink2 should be allowed implicitly as a canonical child of symlink1", |
| 181 | + "b", rel); |
| 182 | + } |
| 183 | + |
149 | 184 | @Ignore("macOS has /var symlink, and I also made a second link, `myhome'.")
|
150 | 185 | @Test
|
151 | 186 | public void shouldResolvePrivateVarOnMacOS() throws IOException {
|
|
0 commit comments