-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for masking multiple JSON values in the same input (#175)
Fixes #173
- Loading branch information
1 parent
4c98d6e
commit 9568ca4
Showing
6 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
src/test/JSONTestSuite/masked/i_string_UTF-16LE_with_BOM.json
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
src/test/JSONTestSuite/masked/n_structure_object_with_trailing_garbage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"a": "&&&"} "x" | ||
{"a": "&&&"} "***" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/dev/blaauwendraad/masker/json/MultiJsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dev.blaauwendraad.masker.json; | ||
|
||
import dev.blaauwendraad.masker.json.config.JsonMaskingConfig; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Set; | ||
|
||
public class MultiJsonTest { | ||
|
||
@Test | ||
void shouldMaskJsonLinesObjects() { | ||
JsonMasker jsonMasker = JsonMasker.getMasker(Set.of("maskMe")); | ||
|
||
Assertions.assertThat(jsonMasker.mask( | ||
""" | ||
{"maskMe":"secret"} | ||
{"maskMe":"secret"} | ||
{"maskMe":"secret"} | ||
""")) | ||
.isEqualTo( | ||
""" | ||
{"maskMe":"***"} | ||
{"maskMe":"***"} | ||
{"maskMe":"***"} | ||
"""); | ||
} | ||
|
||
@Test | ||
void shouldMaskJsonLinesArrays() { | ||
JsonMasker jsonMasker = JsonMasker.getMasker(Set.of("maskMe")); | ||
|
||
Assertions.assertThat(jsonMasker.mask( | ||
""" | ||
[{"maskMe":"secret"}] | ||
[{"maskMe":"secret"}] | ||
[{"maskMe":"secret"}] | ||
""")) | ||
.isEqualTo( | ||
""" | ||
[{"maskMe":"***"}] | ||
[{"maskMe":"***"}] | ||
[{"maskMe":"***"}] | ||
"""); | ||
} | ||
|
||
@Test | ||
void shouldMaskJsonLinesMixedTypes() { | ||
JsonMasker jsonMasker = JsonMasker.getMasker(JsonMaskingConfig.builder().allowKeys().build()); | ||
|
||
Assertions.assertThat(jsonMasker.mask( | ||
""" | ||
"secret" | ||
true | ||
false | ||
null | ||
123 | ||
""")) | ||
.isEqualTo( | ||
""" | ||
"***" | ||
"&&&" | ||
"&&&" | ||
null | ||
"###" | ||
"""); | ||
} | ||
@Test | ||
void shouldMaskRepeatedJsonsWithoutNewLines() { | ||
JsonMasker jsonMasker = JsonMasker.getMasker(Set.of("maskMe")); | ||
|
||
Assertions.assertThat(jsonMasker.mask( | ||
""" | ||
{"maskMe":"secret"}{"maskMe":"secret"} {"maskMe":"secret"} | ||
""")) | ||
.isEqualTo( | ||
""" | ||
{"maskMe":"***"}{"maskMe":"***"} {"maskMe":"***"} | ||
"""); | ||
} | ||
} |