Skip to content

Commit f7d231a

Browse files
committed
Add test case covering issue #735
issue #735
1 parent a03c402 commit f7d231a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/test/java/net/logstash/logback/mask/MaskingJsonGeneratorDecoratorTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package net.logstash.logback.mask;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1920

2021
import java.io.IOException;
2122
import java.io.InputStream;
@@ -40,6 +41,7 @@
4041
import com.fasterxml.jackson.databind.MappingJsonFactory;
4142
import com.fasterxml.jackson.databind.node.ObjectNode;
4243
import org.junit.jupiter.api.Test;
44+
import org.opentest4j.AssertionFailedError;
4345

4446

4547
public class MaskingJsonGeneratorDecoratorTest {
@@ -276,6 +278,38 @@ public void maskedArray() throws IOException {
276278
"foo/fieldA");
277279
}
278280

281+
@Test
282+
public void masedArrayByIndex() throws IOException {
283+
testMaskByPath(
284+
"{ 'array':[{'foo':'bar' },{'a':'b'}] }",
285+
"{ 'array':[{'foo':'****'},{'a':'b'}] }",
286+
"/array/0/foo"
287+
);
288+
289+
testMaskByPath(
290+
"{ 'array':[{'foo':'bar' },{'a':'b' }] }",
291+
"{ 'array':[{'foo':'bar' },{'a':'****'}] }",
292+
"/array/1/a"
293+
);
294+
295+
296+
// Failed tests - see issue #735
297+
298+
assertThatThrownBy(() ->
299+
testMaskByPath(
300+
"{ 'array':['a','b', 'c'] }",
301+
"{ 'array':['a','****','c'] }",
302+
"/array/1"
303+
)).isInstanceOf(AssertionFailedError.class);
304+
305+
assertThatThrownBy(() ->
306+
testMaskByPath(
307+
"{ 'array':[{'foo':'bar'},{'a':'b'}] }",
308+
"{ 'array':['****' ,{'a':'b'}] }",
309+
"/array/0"
310+
)).isInstanceOf(AssertionFailedError.class);
311+
}
312+
279313
@Test
280314
public void maskedArrayOfObjects() throws IOException {
281315
testMaskByPath(

0 commit comments

Comments
 (0)