Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Feb 20, 2024
1 parent cf5c36c commit d346546
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,17 @@ void run(ActionExecutionContext actionExecutionContext) throws IOException {
public void relativeSymlinkTraversingOutsideOfTreeArtifact() throws Exception {
SpecialArtifact out = createTreeArtifact("output");

scratch.file(out.getRoot().getRoot().getRelative("some/file").getPathString());


Action action =
new SimpleTestAction(out) {
@Override
void run(ActionExecutionContext actionExecutionContext) throws IOException {
writeFile(out.getPath().getChild("one"), "one");
writeFile(out.getPath().getChild("two"), "two");
FileSystemUtils.ensureSymbolicLink(
out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
out.getPath().getChild("links").getChild("link"), "../../some/file");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,12 @@ public void visitTree_permitsUpLevelSymlinkInsideTree() throws Exception {

@Test
public void visitTree_permitsUpLevelSymlinkOutsideTree() throws Exception {
Path otherTreeDir = scratch.dir("other_tree");
scratch.file("other_tree/file");
Path treeDir = scratch.dir("tree");
scratch.file("tree/file");
scratch.dir("tree/a");
scratch.resolve("tree/a/uplink").createSymbolicLink(PathFragment.create("../../non_existent"));
scratch.resolve("tree/a/uplink").createSymbolicLink(PathFragment.create("../../other_tree/file"));
List<VisitTreeArgs> children = new ArrayList<>();

TreeArtifactValue.visitTree(
Expand All @@ -586,9 +588,10 @@ public void visitTree_permitsUpLevelSymlinkOutsideTree() throws Exception {

assertThat(children)
.containsExactly(
VisitTreeArgs.of(PathFragment.create(""), Dirent.Type.DIRECTORY, false),
VisitTreeArgs.of(PathFragment.create("file"), Dirent.Type.FILE, false),
VisitTreeArgs.of(PathFragment.create("a"), Dirent.Type.DIRECTORY, false),
VisitTreeArgs.of(PathFragment.create("a/uplink"), Dirent.Type.SYMLINK, true));
VisitTreeArgs.of(PathFragment.create("a/uplink"), Dirent.Type.FILE, true));
}

@Test
Expand Down Expand Up @@ -617,16 +620,27 @@ public void visitTree_permitsAbsoluteSymlink() throws Exception {
}

@Test
public void visitTree_throwsOnSymlinkTraversingOutsideThenBackInsideTree() throws Exception {
public void visitTree_permitsSymlinkTraversingOutsideThenBackInsideTree() throws Exception {
Path treeDir = scratch.dir("tree");
scratch.file("tree/file");
scratch.resolve("tree/link").createSymbolicLink(PathFragment.create("../tree/file"));

Exception e =
assertThrows(
IOException.class,
() -> TreeArtifactValue.visitTree(treeDir, (child, type, traversedSymlink) -> {}));
assertThat(e).hasMessageThat().contains("/tree/link pointing to ../tree/file");
List<VisitTreeArgs> children = new ArrayList<>();

TreeArtifactValue.visitTree(
treeDir,
(child, type, traversedSymlink) -> {
synchronized (children) {
children.add(VisitTreeArgs.of(child, type, traversedSymlink));
}
});

assertThat(children)
.containsExactly(
VisitTreeArgs.of(PathFragment.create(""), Dirent.Type.DIRECTORY, false),
VisitTreeArgs.of(PathFragment.create("file"), Dirent.Type.FILE, false),
VisitTreeArgs.of(
PathFragment.create("link"), Dirent.Type.FILE, true));
}

@Test
Expand Down

0 comments on commit d346546

Please sign in to comment.