Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdconrad committed Feb 25, 2025
1 parent 3b648b8 commit b78ce2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,8 @@ public void testFilesEntitlementsWithExclusive() {
Set.of()
)
);
assertEquals(
"duplicate/overlapping exclusive paths found in files entitlements: "
+ "[[plugin1] [test] [/tmp/test]] and [[plugin2] [test] [/tmp/test]]",
iae.getMessage()
);
assertTrue(iae.getMessage().contains("duplicate/overlapping exclusive paths found in files entitlements:"));
assertTrue(iae.getMessage().contains("[test] [/tmp/test]]"));

iae = expectThrows(
IllegalArgumentException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
import org.elasticsearch.entitlement.runtime.policy.Policy;
import org.elasticsearch.entitlement.runtime.policy.PolicyParser;
import org.elasticsearch.entitlement.runtime.policy.PolicyValidationException;
import org.elasticsearch.entitlement.runtime.policy.Scope;
import org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.FileData;
import org.elasticsearch.test.ESTestCase;
import org.junit.BeforeClass;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -112,4 +117,24 @@ public void testPathSettingResolve() {
settings = Settings.builder().put("foo.baz.bar", "/setting/path").put("foo.baz2.bar", "/other/path").build();
assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), containsInAnyOrder(Path.of("/setting/path"), Path.of("/other/path")));
}

public void testExclusiveParsing() throws Exception {
Policy parsedPolicy = new PolicyParser(new ByteArrayInputStream("""
entitlement-module-name:
- files:
- path: /test
mode: read
exclusive: true
""".getBytes(StandardCharsets.UTF_8)), "test-policy.yaml", true).parsePolicy();
Policy expected = new Policy(
"test-policy.yaml",
List.of(
new Scope(
"entitlement-module-name",
List.of(FilesEntitlement.build(List.of(Map.of("path", "/test", "mode", "read", "exclusive", true))))
)
)
);
assertEquals(expected, parsedPolicy);
}
}

0 comments on commit b78ce2c

Please sign in to comment.