From 5a6fb9dbc79a622b9d2e420129838ad31935aad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Mon, 13 Jan 2025 17:28:41 +0100 Subject: [PATCH] Return 'none' body filter if list of to-be-filtered JSON field-names is empty --- .../LogbookAutoConfiguration.java | 4 ++- .../ObfuscateBodyDefaultTest.java | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java diff --git a/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java b/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java index 55fe7323b..bfce2844d 100644 --- a/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java +++ b/logbook-spring-boot-autoconfigure/src/main/java/org/zalando/logbook/autoconfigure/LogbookAutoConfiguration.java @@ -260,7 +260,9 @@ public BodyFilter bodyFilter() { public BodyFilter jsonBodyFieldsFilter() { final LogbookProperties.Obfuscate obfuscate = properties.getObfuscate(); final List jsonBodyFields = obfuscate.getJsonBodyFields(); - + if (jsonBodyFields.isEmpty()) { + return BodyFilter.none(); + } return new JacksonJsonFieldBodyFilter(jsonBodyFields, obfuscate.getReplacement()); } diff --git a/logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java b/logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java new file mode 100644 index 000000000..956e57718 --- /dev/null +++ b/logbook-spring-boot-autoconfigure/src/test/java/org/zalando/logbook/autoconfigure/ObfuscateBodyDefaultTest.java @@ -0,0 +1,25 @@ +package org.zalando.logbook.autoconfigure; + +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.zalando.logbook.BodyFilter; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +@LogbookTest +class ObfuscateBodyDefaultTest { + + @Autowired + @Qualifier("jsonBodyFieldsFilter") + private BodyFilter jsonBodyFieldsFilter; + + @Test + void shouldNotFilterJsonBodiesIfEmptyObfuscateJsonBodyFieldNames() throws IOException, JSONException { + assertThat(jsonBodyFieldsFilter).isSameAs(BodyFilter.none()); + } + +}