Skip to content

Commit 0a04b2e

Browse files
committed
Use empty component path list instead of null
1 parent d08d6d2 commit 0a04b2e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/bootstrap/FilesEntitlementsValidation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.nio.file.Path;
1919
import java.util.HashSet;
20+
import java.util.List;
2021
import java.util.Map;
2122
import java.util.Set;
2223

@@ -44,7 +45,7 @@ static void validate(Map<String, Policy> pluginPolicies, PathLookup pathLookup)
4445
.map(x -> ((FilesEntitlement) x))
4546
.findFirst();
4647
if (filesEntitlement.isPresent()) {
47-
var fileAccessTree = FileAccessTree.withoutExclusivePaths(filesEntitlement.get(), pathLookup, null);
48+
var fileAccessTree = FileAccessTree.withoutExclusivePaths(filesEntitlement.get(), pathLookup, List.of());
4849
validateReadFilesEntitlements(pluginPolicy.getKey(), scope.moduleName(), fileAccessTree, readAccessForbidden);
4950
validateWriteFilesEntitlements(pluginPolicy.getKey(), scope.moduleName(), fileAccessTree, writeAccessForbidden);
5051
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,16 @@ private ModuleEntitlements computeEntitlements(Class<?> requestingClass) {
321321
);
322322
}
323323
case UNKNOWN -> {
324-
return defaultEntitlements(UNKNOWN.componentName, null, moduleName);
324+
return defaultEntitlements(UNKNOWN.componentName, List.of(), moduleName);
325325
}
326326
default -> {
327327
assert policyScope.kind() == PLUGIN;
328328
var pluginEntitlements = pluginsEntitlements.get(componentName);
329+
Collection<Path> componentPaths = pluginSourcePaths.getOrDefault(componentName, List.of());
329330
if (pluginEntitlements == null) {
330-
return defaultEntitlements(componentName, pluginSourcePaths.get(componentName), moduleName);
331+
return defaultEntitlements(componentName, componentPaths, moduleName);
331332
} else {
332-
return getModuleScopeEntitlements(pluginEntitlements, moduleName, componentName, pluginSourcePaths.get(componentName));
333+
return getModuleScopeEntitlements(pluginEntitlements, moduleName, componentName, componentPaths);
333334
}
334335
}
335336
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ public void testFollowLinks() throws IOException {
299299
}
300300

301301
public void testTempDirAccess() {
302-
var tree = FileAccessTree.of("test-component", "test-module", FilesEntitlement.EMPTY, TEST_PATH_LOOKUP, null, List.of());
302+
var tree = FileAccessTree.of("test-component", "test-module", FilesEntitlement.EMPTY, TEST_PATH_LOOKUP, List.of(), List.of());
303303
assertThat(tree.canRead(TEST_PATH_LOOKUP.getBaseDirPaths(TEMP).findFirst().get()), is(true));
304304
assertThat(tree.canWrite(TEST_PATH_LOOKUP.getBaseDirPaths(TEMP).findFirst().get()), is(true));
305305
}
306306

307307
public void testConfigDirAccess() {
308-
var tree = FileAccessTree.of("test-component", "test-module", FilesEntitlement.EMPTY, TEST_PATH_LOOKUP, null, List.of());
308+
var tree = FileAccessTree.of("test-component", "test-module", FilesEntitlement.EMPTY, TEST_PATH_LOOKUP, List.of(), List.of());
309309
assertThat(tree.canRead(TEST_PATH_LOOKUP.getBaseDirPaths(CONFIG).findFirst().get()), is(true));
310310
assertThat(tree.canWrite(TEST_PATH_LOOKUP.getBaseDirPaths(CONFIG).findFirst().get()), is(false));
311311
}
@@ -504,7 +504,7 @@ public void testWindowsMixedCaseAccess() {
504504
}
505505

506506
FileAccessTree accessTree(FilesEntitlement entitlement, List<ExclusivePath> exclusivePaths) {
507-
return FileAccessTree.of("test-component", "test-module", entitlement, TEST_PATH_LOOKUP, null, exclusivePaths);
507+
return FileAccessTree.of("test-component", "test-module", entitlement, TEST_PATH_LOOKUP, List.of(), exclusivePaths);
508508
}
509509

510510
static FilesEntitlement entitlement(String... values) {

0 commit comments

Comments
 (0)