From f7d231ae83bd219f3c46d363526c511a18e2f54a Mon Sep 17 00:00:00 2001 From: Bertrand Renuart Date: Fri, 26 Aug 2022 12:33:00 +0200 Subject: [PATCH] Add test case covering issue #735 issue #735 --- .../MaskingJsonGeneratorDecoratorTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/net/logstash/logback/mask/MaskingJsonGeneratorDecoratorTest.java b/src/test/java/net/logstash/logback/mask/MaskingJsonGeneratorDecoratorTest.java index b36cbb85..904fe8e4 100644 --- a/src/test/java/net/logstash/logback/mask/MaskingJsonGeneratorDecoratorTest.java +++ b/src/test/java/net/logstash/logback/mask/MaskingJsonGeneratorDecoratorTest.java @@ -16,6 +16,7 @@ package net.logstash.logback.mask; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.io.InputStream; @@ -40,6 +41,7 @@ import com.fasterxml.jackson.databind.MappingJsonFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; public class MaskingJsonGeneratorDecoratorTest { @@ -276,6 +278,38 @@ public void maskedArray() throws IOException { "foo/fieldA"); } + @Test + public void masedArrayByIndex() throws IOException { + testMaskByPath( + "{ 'array':[{'foo':'bar' },{'a':'b'}] }", + "{ 'array':[{'foo':'****'},{'a':'b'}] }", + "/array/0/foo" + ); + + testMaskByPath( + "{ 'array':[{'foo':'bar' },{'a':'b' }] }", + "{ 'array':[{'foo':'bar' },{'a':'****'}] }", + "/array/1/a" + ); + + + // Failed tests - see issue #735 + + assertThatThrownBy(() -> + testMaskByPath( + "{ 'array':['a','b', 'c'] }", + "{ 'array':['a','****','c'] }", + "/array/1" + )).isInstanceOf(AssertionFailedError.class); + + assertThatThrownBy(() -> + testMaskByPath( + "{ 'array':[{'foo':'bar'},{'a':'b'}] }", + "{ 'array':['****' ,{'a':'b'}] }", + "/array/0" + )).isInstanceOf(AssertionFailedError.class); + } + @Test public void maskedArrayOfObjects() throws IOException { testMaskByPath(