Skip to content

Commit 809df1b

Browse files
committed
fix tests
1 parent 20f20d3 commit 809df1b

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ public static FilesEntitlement build(List<Object> paths) {
230230
throw new PolicyValidationException("unknown key(s) [" + file + "] in a listed file for files entitlement");
231231
}
232232
int foundKeys = (pathAsString != null ? 1 : 0) + (relativePathAsString != null ? 1 : 0) + (pathSetting != null ? 1 : 0)
233-
+ (relativePathSetting != null ? 1 : 0) + (modeAsString != null ? 1 : 0);
233+
+ (relativePathSetting != null ? 1 : 0);
234234
if (foundKeys != 1) {
235-
throw new PolicyValidationException(
236-
"files entitlement must contain one of [path, relative_path, path_setting, relative_path_setting] for every entry"
235+
throw new PolicyValidationException("a files entitlement entry must contain one of " +
236+
"[path, relative_path, path_setting, relative_path_setting]"
237237
);
238238
}
239239

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ public void testForwardSlashes() {
163163
}
164164

165165
public void testTempDirAccess() {
166-
Path tempDir = createTempDir();
167166
var tree = FileAccessTree.of(FilesEntitlement.EMPTY, TEST_PATH_LOOKUP);
168-
assertThat(tree.canRead(tempDir), is(true));
169-
assertThat(tree.canWrite(tempDir), is(true));
167+
assertThat(tree.canRead(TEST_PATH_LOOKUP.tempDir()), is(true));
168+
assertThat(tree.canWrite(TEST_PATH_LOOKUP.tempDir()), is(true));
170169
}
171170

172171
FileAccessTree accessTree(FilesEntitlement entitlement) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public void testEntitlementMutuallyExclusiveParameters() {
103103
""".getBytes(StandardCharsets.UTF_8)), "test-failure-policy.yaml", false).parsePolicy());
104104
assertEquals(
105105
"[2:5] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
106-
+ "for entitlement type [files]: a files entitlement entry cannot contain both 'path' and 'relative_path'",
106+
+ "for entitlement type [files]: a files entitlement entry must contain one of " +
107+
"[path, relative_path, path_setting, relative_path_setting]",
107108
ppe.getMessage()
108109
);
109110
}
@@ -116,7 +117,8 @@ public void testEntitlementAtLeastOneParameter() {
116117
""".getBytes(StandardCharsets.UTF_8)), "test-failure-policy.yaml", false).parsePolicy());
117118
assertEquals(
118119
"[2:5] policy parsing error for [test-failure-policy.yaml] in scope [entitlement-module-name] "
119-
+ "for entitlement type [files]: files entitlement must contain either 'path' or 'relative_path' for every entry",
120+
+ "for entitlement type [files]: a files entitlement entry must contain one of " +
121+
"[path, relative_path, path_setting, relative_path_setting]",
120122
ppe.getMessage()
121123
);
122124
}

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlementTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ;
2424
import static org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.Mode.READ_WRITE;
2525
import static org.hamcrest.Matchers.contains;
26+
import static org.hamcrest.Matchers.containsInAnyOrder;
2627
import static org.hamcrest.Matchers.empty;
2728
import static org.hamcrest.Matchers.is;
2829

@@ -83,6 +84,6 @@ public void testPathSettingResolve() {
8384

8485
fileData = FileData.ofPathSetting("foo.*.bar", READ);
8586
settings = Settings.builder().put("foo.baz.bar", "/setting/path").put("foo.baz2.bar", "/other/path").build();
86-
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), contains(Path.of("/setting/path"), Path.of("/other/path")));
87+
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), containsInAnyOrder(Path.of("/setting/path"), Path.of("/other/path")));
8788
}
8889
}

server/src/test/java/org/elasticsearch/common/settings/SettingsTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,10 @@ public void testProcessSetting() throws IOException {
703703
{"ant.bee":{"cat.dog":{"ewe":"value3"},"cat":"value2"},"ant":"value1"}""", Strings.toString(builder));
704704
}
705705

706+
public void testGlobValues() throws IOException {
707+
Settings test = Settings.builder().put("foo.x.bar", "1").put("foo.y.bar", "2").build();
708+
var values = test.getGlobValues("foo.*.bar").toList();
709+
assertThat(values, containsInAnyOrder("1", "2"));
710+
}
711+
706712
}

0 commit comments

Comments
 (0)