Skip to content

Commit

Permalink
Return 'none' body filter if list of to-be-filtered JSON field-names …
Browse files Browse the repository at this point in the history
…is empty
  • Loading branch information
skjolber committed Jan 13, 2025
1 parent 9cf028b commit 5a6fb9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ public BodyFilter bodyFilter() {
public BodyFilter jsonBodyFieldsFilter() {
final LogbookProperties.Obfuscate obfuscate = properties.getObfuscate();
final List<String> jsonBodyFields = obfuscate.getJsonBodyFields();

if (jsonBodyFields.isEmpty()) {
return BodyFilter.none();
}
return new JacksonJsonFieldBodyFilter(jsonBodyFields, obfuscate.getReplacement());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit 5a6fb9d

Please sign in to comment.