Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions logstash-core/src/test/java/org/logstash/EventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.HexFormat;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -149,7 +150,7 @@ public void bigNumsBinaryRoundtrip() throws Exception {

@Test
public void deserializeStringrefExtensionEnabled() throws Exception {
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-enabled.annotated-cbor.txt");
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-enabled.annotated-cbor.asc");
Event event = Event.deserialize(stringrefCBOR);
event.getField("[event][original]");
assertEquals("stringref", event.getField("test"));
Expand All @@ -158,7 +159,7 @@ public void deserializeStringrefExtensionEnabled() throws Exception {

@Test
public void deserializeStringrefExtensionDisabled() throws Exception {
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-disabled.annotated-cbor.txt");
byte[] stringrefCBOR = loadAnnotatedCBORFixture("stringref-disabled.annotated-cbor.asc");
Event event = Event.deserialize(stringrefCBOR);
event.getField("[event][original]");
assertEquals("stringref", event.getField("test"));
Expand Down Expand Up @@ -592,9 +593,13 @@ static byte[] loadAnnotatedCBORFixture(String name) throws IOException {
try (InputStream resourceAsStream = EventTest.class.getResourceAsStream(name)) {
assertNotNull(resourceAsStream);

String annotated = new String(resourceAsStream.readAllBytes(), StandardCharsets.UTF_8);
// annotated CBOR: strip #-initiated line comments, then strip whitespace to get hex
String hexBytes = annotated.replaceAll("#.*(\\n|$)", "").replaceAll("\\s", "");
final String annotatedFixture = new String(resourceAsStream.readAllBytes(), StandardCharsets.US_ASCII);
final String hexBytes = annotatedFixture.lines()
// strip #-prefixed annotations
.map(line -> line.split("#", 2)[0])
// strip all remaining whitespace
.map(line -> line.replaceAll("\\s", ""))
.collect(Collectors.joining());

// result should be even number of hex digits
assert hexBytes.matches("(?i:[0-9a-f]{2})*");
Expand Down