Skip to content

Commit a39b3a9

Browse files
committed
checkpoint
1 parent 857ba64 commit a39b3a9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTree.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ private FileAccessTree(
3636
List<ExclusivePath> exclusivePaths
3737
) {
3838
List<String> updatedExclusivePaths = new ArrayList<>();
39+
for (ExclusivePath exclusivePath : exclusivePaths) {
40+
updatedExclusivePaths.add(normalizePath(exclusivePath.path()));
41+
}
42+
3943
List<String> readPaths = new ArrayList<>();
4044
List<String> writePaths = new ArrayList<>();
4145
for (FilesEntitlement.FileData fileData : filesEntitlement.filesData()) {
@@ -46,8 +50,25 @@ private FileAccessTree(
4650
for (ExclusivePath exclusivePath : exclusivePaths) {
4751
if (exclusivePath.componentName().equals(componentName) == false
4852
|| exclusivePath.moduleName().equals(moduleName) == false) {
53+
if (true) throw new IllegalArgumentException(
54+
path.getFileSystem() + " " + exclusivePath.path().getFileSystem() + " " + path.startsWith(exclusivePath.path())
55+
);
4956
if (path.startsWith(exclusivePath.path())) {
50-
// TODO: throw
57+
throw new IllegalArgumentException(
58+
"["
59+
+ componentName
60+
+ "] ["
61+
+ moduleName
62+
+ "] cannot use"
63+
+ "exclusive path ["
64+
+ exclusivePath.path()
65+
+ "] from ["
66+
+ exclusivePath.componentName()
67+
+ "] "
68+
+ "["
69+
+ exclusivePath.moduleName()
70+
+ "]"
71+
);
5172
}
5273
updatedExclusivePaths.add(normalizePath(exclusivePath.path()));
5374
}

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTreeTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void testTempDirAccess() {
197197
assertThat(tree.canWrite(TEST_PATH_LOOKUP.tempDir()), is(true));
198198
}
199199

200-
public void testExclusiveAccess() {
200+
public void testBasicExclusiveAccess() {
201201
var tree = accessTree(entitlement("foo", "read"), exclusivePaths("test-component", "test-module", "foo"));
202202
assertThat(tree.canRead(path("foo")), is(true));
203203
assertThat(tree.canWrite(path("foo")), is(false));
@@ -213,6 +213,11 @@ public void testExclusiveAccess() {
213213
assertThat(tree.canWrite(path("foo/bar")), is(false));
214214
}
215215

216+
public void testInvalidExclusiveAccess() {
217+
var tree = accessTree(entitlement("foo/bar", "read"), exclusivePaths("test-component", "diff-module", "foo"));
218+
219+
}
220+
216221
FileAccessTree accessTree(FilesEntitlement entitlement, List<ExclusivePath> exclusivePaths) {
217222
return FileAccessTree.of("test-component", "test-module", entitlement, TEST_PATH_LOOKUP, exclusivePaths);
218223
}

0 commit comments

Comments
 (0)