Skip to content

Commit a5b7cc9

Browse files
[Failure Store] Test field capabilities API
1 parent d5c0778 commit a5b7cc9

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,84 @@ public void testFailureStoreAccessWithApiKeys() throws Exception {
20272027
expectThrowsWithApiKey(apiKey, new Search("test1"), 403);
20282028
}
20292029

2030+
public void testFieldCapabilities() throws Exception {
2031+
setupDataStream();
2032+
2033+
final Tuple<String, String> backingIndices = getSingleDataAndFailureIndices("test1");
2034+
final String dataIndexName = backingIndices.v1();
2035+
final String failureIndexName = backingIndices.v2();
2036+
2037+
createUser("user", PASSWORD, "role");
2038+
upsertRole("""
2039+
{
2040+
"cluster": ["all"],
2041+
"indices": [
2042+
{
2043+
"names": ["test*"],
2044+
"privileges": ["read"]
2045+
}
2046+
]
2047+
}""", "role");
2048+
2049+
{
2050+
expectThrows(
2051+
() -> performRequest("user", new Request("POST", Strings.format("/%s/_field_caps?fields=name", "test1::failures"))),
2052+
403
2053+
);
2054+
Response fieldCapsResponse = performRequest(
2055+
"user",
2056+
new Request("POST", Strings.format("/%s/_field_caps?fields=name", "test1"))
2057+
);
2058+
assertOK(fieldCapsResponse);
2059+
ObjectPath objectPath = ObjectPath.createFromResponse(fieldCapsResponse);
2060+
2061+
List<String> indices = objectPath.evaluate("indices");
2062+
assertThat(indices, containsInAnyOrder(dataIndexName));
2063+
2064+
Map<String, Object> fields = objectPath.evaluate("fields");
2065+
assertThat(fields.keySet(), containsInAnyOrder("name"));
2066+
}
2067+
2068+
upsertRole("""
2069+
{
2070+
"cluster": ["all"],
2071+
"indices": [
2072+
{
2073+
"names": ["test*"],
2074+
"privileges": ["read_failure_store"]
2075+
}
2076+
]
2077+
}""", "role");
2078+
2079+
{
2080+
expectThrows(() -> performRequest("user", new Request("POST", Strings.format("/%s/_field_caps?fields=name", "test1"))), 403);
2081+
Response fieldCapsResponse = performRequest(
2082+
"user",
2083+
new Request("POST", Strings.format("/%s/_field_caps?fields=error.*", "test1::failures"))
2084+
);
2085+
assertOK(fieldCapsResponse);
2086+
ObjectPath objectPath = ObjectPath.createFromResponse(fieldCapsResponse);
2087+
2088+
List<String> indices = objectPath.evaluate("indices");
2089+
assertThat(indices, containsInAnyOrder(failureIndexName));
2090+
2091+
Map<String, Object> fields = objectPath.evaluate("fields");
2092+
assertThat(
2093+
fields.keySet(),
2094+
containsInAnyOrder(
2095+
"error.message",
2096+
"error.pipeline_trace",
2097+
"error.processor_type",
2098+
"error.type",
2099+
"error.processor_tag",
2100+
"error.pipeline",
2101+
"error.stack_trace",
2102+
"error"
2103+
)
2104+
);
2105+
}
2106+
}
2107+
20302108
public void testPit() throws Exception {
20312109
List<String> docIds = setupDataStream();
20322110
String dataDocId = "1";

0 commit comments

Comments
 (0)