|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.security.audit; |
9 | 9 |
|
| 10 | +import org.apache.http.entity.ContentType; |
| 11 | +import org.apache.http.entity.StringEntity; |
10 | 12 | import org.elasticsearch.client.Request; |
11 | 13 | import org.elasticsearch.client.RequestOptions; |
12 | 14 | import org.elasticsearch.client.Response; |
|
29 | 31 | import org.junit.ClassRule; |
30 | 32 |
|
31 | 33 | import java.io.IOException; |
| 34 | +import java.nio.charset.StandardCharsets; |
32 | 35 | import java.time.Instant; |
33 | 36 | import java.time.ZonedDateTime; |
34 | 37 | import java.time.format.DateTimeFormatter; |
|
39 | 42 | import java.util.concurrent.TimeUnit; |
40 | 43 | import java.util.function.Predicate; |
41 | 44 |
|
| 45 | +import static org.hamcrest.Matchers.allOf; |
42 | 46 | import static org.hamcrest.Matchers.containsString; |
43 | 47 | import static org.hamcrest.Matchers.hasEntry; |
44 | 48 | import static org.hamcrest.Matchers.hasKey; |
@@ -105,6 +109,25 @@ public void testFilteringOfRequestBodies() throws Exception { |
105 | 109 | }); |
106 | 110 | } |
107 | 111 |
|
| 112 | + public void testAuditAuthenticationSuccessForStreamingRequest() throws Exception { |
| 113 | + final Request request = new Request("POST", "/testindex/_bulk"); |
| 114 | + request.setEntity(new StringEntity(""" |
| 115 | + {"index":{}} |
| 116 | + {} |
| 117 | + """, ContentType.create("application/x-ndjson", StandardCharsets.UTF_8))); |
| 118 | + executeAndVerifyAudit( |
| 119 | + request, |
| 120 | + AuditLevel.AUTHENTICATION_SUCCESS, |
| 121 | + event -> assertThat( |
| 122 | + event, |
| 123 | + allOf( |
| 124 | + hasEntry(LoggingAuditTrail.AUTHENTICATION_TYPE_FIELD_NAME, "REALM"), |
| 125 | + hasEntry(LoggingAuditTrail.REQUEST_BODY_FIELD_NAME, "Request body had not been received at the time of the audit event") |
| 126 | + ) |
| 127 | + ) |
| 128 | + ); |
| 129 | + } |
| 130 | + |
108 | 131 | private void executeAndVerifyAudit(Request request, AuditLevel eventType, CheckedConsumer<Map<String, Object>, Exception> assertions) |
109 | 132 | throws Exception { |
110 | 133 | Instant start = Instant.now(); |
|
0 commit comments