Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Feb 20, 2024
1 parent 067d041 commit cf5c36c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,48 @@ void run(ActionExecutionContext actionExecutionContext) throws IOException {
buildArtifact(out);
}

@Test
public void relativeSymlinkTraversingToDirOutsideOfTreeArtifact() throws Exception {
SpecialArtifact out = createTreeArtifact("output");

// Create a valid directory that can be referenced
scratch.dir(out.getRoot().getRoot().getRelative("some/dir").getPathString());

TestAction 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"), "../../some/dir");
}
};

registerAction(action);
buildArtifact(out);
}

@Test
public void relativeSymlinkTraversingOutsideOfTreeArtifact() throws Exception {
SpecialArtifact out = createTreeArtifact("output");

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");
}
};

registerAction(action);
buildArtifact(out);
}


@Test
public void constructMetadataForDigest() throws Exception {
SpecialArtifact out = createTreeArtifact("output");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,21 +574,21 @@ public void visitTree_permitsUpLevelSymlinkOutsideTree() throws Exception {
scratch.file("tree/file");
scratch.dir("tree/a");
scratch.resolve("tree/a/uplink").createSymbolicLink(PathFragment.create("../../non_existent"));
List<Pair<PathFragment, Dirent.Type>> children = new ArrayList<>();
List<VisitTreeArgs> children = new ArrayList<>();

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

assertThat(children)
.containsExactly(
Pair.of(PathFragment.create("file"), Dirent.Type.FILE),
Pair.of(PathFragment.create("a"), Dirent.Type.DIRECTORY),
Pair.of(PathFragment.create("a/uplink"), Dirent.Type.SYMLINK));
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));
}

@Test
Expand Down

0 comments on commit cf5c36c

Please sign in to comment.