|
11 | 11 |
|
12 | 12 | import org.elasticsearch.common.settings.Settings; |
13 | 13 | import org.elasticsearch.entitlement.runtime.policy.PathLookup; |
| 14 | +import org.elasticsearch.entitlement.runtime.policy.Policy; |
| 15 | +import org.elasticsearch.entitlement.runtime.policy.PolicyParser; |
14 | 16 | import org.elasticsearch.entitlement.runtime.policy.PolicyValidationException; |
| 17 | +import org.elasticsearch.entitlement.runtime.policy.Scope; |
15 | 18 | import org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.FileData; |
16 | 19 | import org.elasticsearch.test.ESTestCase; |
17 | 20 | import org.junit.BeforeClass; |
18 | 21 |
|
| 22 | +import java.io.ByteArrayInputStream; |
| 23 | +import java.nio.charset.StandardCharsets; |
19 | 24 | import java.nio.file.Path; |
20 | 25 | import java.util.List; |
21 | 26 | import java.util.Map; |
@@ -112,4 +117,24 @@ public void testPathSettingResolve() { |
112 | 117 | settings = Settings.builder().put("foo.baz.bar", "/setting/path").put("foo.baz2.bar", "/other/path").build(); |
113 | 118 | assertThat(fileData.resolvePaths(TEST_PATH_LOOKUP).toList(), containsInAnyOrder(Path.of("/setting/path"), Path.of("/other/path"))); |
114 | 119 | } |
| 120 | + |
| 121 | + public void testExclusiveParsing() throws Exception { |
| 122 | + Policy parsedPolicy = new PolicyParser(new ByteArrayInputStream(""" |
| 123 | + entitlement-module-name: |
| 124 | + - files: |
| 125 | + - path: /test |
| 126 | + mode: read |
| 127 | + exclusive: true |
| 128 | + """.getBytes(StandardCharsets.UTF_8)), "test-policy.yaml", true).parsePolicy(); |
| 129 | + Policy expected = new Policy( |
| 130 | + "test-policy.yaml", |
| 131 | + List.of( |
| 132 | + new Scope( |
| 133 | + "entitlement-module-name", |
| 134 | + List.of(FilesEntitlement.build(List.of(Map.of("path", "/test", "mode", "read", "exclusive", true)))) |
| 135 | + ) |
| 136 | + ) |
| 137 | + ); |
| 138 | + assertEquals(expected, parsedPolicy); |
| 139 | + } |
115 | 140 | } |
0 commit comments