From 6ef197c372cce519bb653fb99cb36b39558455c8 Mon Sep 17 00:00:00 2001 From: fsun1 Date: Tue, 12 Nov 2024 21:06:16 -0800 Subject: [PATCH] split JsonFieldPatternBuilder for String, Boolean and Numeric --- .../com/ebay/ejmask/api/IPatternBuilder.java | 6 + .../json/JsonBooleanFieldPatternBuilder.java | 108 ++++++++++ .../builder/json/JsonFieldPatternBuilder.java | 16 +- .../json/JsonNumericFieldPatternBuilder.java | 108 ++++++++++ .../JsonBooleanFieldPatternBuilderTest.java | 160 +++++++++++++++ .../json/JsonFieldPatternBuilderTest.java | 107 +++------- .../JsonNumericFieldPatternBuilderTest.java | 185 ++++++++++++++++++ 7 files changed, 597 insertions(+), 93 deletions(-) create mode 100644 ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilder.java create mode 100644 ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilder.java create mode 100644 ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilderTest.java create mode 100644 ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilderTest.java diff --git a/ejmask-api/src/main/java/com/ebay/ejmask/api/IPatternBuilder.java b/ejmask-api/src/main/java/com/ebay/ejmask/api/IPatternBuilder.java index d73b6da..614d04c 100644 --- a/ejmask-api/src/main/java/com/ebay/ejmask/api/IPatternBuilder.java +++ b/ejmask-api/src/main/java/com/ebay/ejmask/api/IPatternBuilder.java @@ -44,6 +44,12 @@ public interface IPatternBuilder { @Deprecated String buildReplacement(int visibleCharacters, String... fieldNames); + /** + * Build pattern to match + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return + */ default List buildPatternEntities(int visibleCharacters, String... fieldNames) { return Arrays.asList(new PatternEntity(buildPattern(visibleCharacters, fieldNames), buildReplacement(visibleCharacters, fieldNames))); } diff --git a/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilder.java b/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilder.java new file mode 100644 index 0000000..f67ad19 --- /dev/null +++ b/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilder.java @@ -0,0 +1,108 @@ +package com.ebay.ejmask.extenstion.builder.json; +/** + * Copyright (c) 2023 eBay Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import com.ebay.ejmask.api.PatternEntity; +import com.ebay.ejmask.extenstion.builder.AbstractRegexPatternBuilder; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import static com.ebay.ejmask.core.util.CommonUtils.emptyIfNull; + +/** + * An implementation of IPatternBuilder to support sensitive JSON field, whose value need to be partially masked. + * This builder is for masking the field value with a Boolean type. + * + * @author fsun1 + */ +public class JsonBooleanFieldPatternBuilder extends AbstractRegexPatternBuilder { + + private static final List PATTERN_ENTITY_LIST = Arrays.asList( + /** + * Boolean field with value to be masked + * @link https://regex101.com/r/AEwc99/1 + */ + new PatternEntity("\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*)(\\b(true|TRUE|True|false|FALSE|False)\\b)([^\\\"]{1,3})[^\\\"]*(\\\\?\\\"|)", "\"$1$2\"xxxx\"$5$6") + ); + + /** + * Build pattern to match + * + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return match pattern + */ + @Override + public String buildPattern(int visibleCharacters, String... fieldNames) { + return this.buildPattern(null, visibleCharacters, fieldNames); + } + + /** + * Build pattern to match + * @param patternEntity as instance of PatternEntity + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return + */ + private String buildPattern(PatternEntity patternEntity, int visibleCharacters, String... fieldNames) { + if (visibleCharacters < 1) { + throw new IllegalArgumentException("visibleCharacters must be a possessive value instead of " + visibleCharacters); + } + if(patternEntity == null) { + patternEntity = PATTERN_ENTITY_LIST.get(0); + } + return String.format(patternEntity.getPatternTemplate(), super.buildFieldNamesForRegexOr(fieldNames), visibleCharacters); + } + + + /** + * Build pattern to replace. + * + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return match pattern + */ + @Override + public String buildReplacement(int visibleCharacters, String... fieldNames) { + return this.buildReplacement(null, visibleCharacters, fieldNames); + } + + /** + * Build pattern to replace. + * + * @param patternEntity as instance of PatternEntity + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return match pattern + */ + private String buildReplacement(PatternEntity patternEntity, int visibleCharacters, String... fieldNames) { + if(patternEntity == null) { + patternEntity = PATTERN_ENTITY_LIST.get(0); + } + return patternEntity.getReplacementTemplate(); + } + + @Override + public List buildPatternEntities(int visibleCharacters, String... fieldNames) { + List result = new LinkedList<>(); + emptyIfNull(PATTERN_ENTITY_LIST).forEach(patternEntity -> { + result.add(new PatternEntity(this.buildPattern(patternEntity, visibleCharacters, fieldNames), this.buildReplacement(patternEntity, visibleCharacters, fieldNames))); + }); + return result; + } + +} diff --git a/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilder.java b/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilder.java index dd7f4dc..f356080 100644 --- a/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilder.java +++ b/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilder.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import com.ebay.ejmask.api.PatternEntity; import com.ebay.ejmask.extenstion.builder.AbstractRegexPatternBuilder; @@ -26,6 +25,7 @@ /** * An implementation of IPatternBuilder to support sensitive JSON field, whose value need to be partially masked. + * This builder is for masking the field value with a String type. * * @author prakv */ @@ -36,19 +36,7 @@ public class JsonFieldPatternBuilder extends AbstractRegexPatternBuilder { * String field with value to be masked * @link https://regex101.com/r/ZDQWod/5 */ - new PatternEntity("\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*\\\")([^\\\"]{1,%d})[^\\\"]*(\\\\?\\\"|)", "\"$1$2$3-xxxx$4"), - - /** - * Numeric field with value to be masked - * @link https://regex101.com/r/rOeErB/1 - */ - new PatternEntity("\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*)(-?\\b\\d+(\\.\\d+)?(e-?\\d+)?\\b)([^\\\"]{1,2})", "\"$1$2\"xxxx\"$6"), - /** - * Boolean field with value to be masked - * @link https://regex101.com/r/AEwc99/1 - */ - new PatternEntity("\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*)(\\b(true|TRUE|True|false|FALSE|False)\\b)([^\\\"]{1,3})[^\\\"]*(\\\\?\\\"|)", "\"$1$2\"xxxx\"$5$6") - + new PatternEntity("\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*\\\")([^\\\"]{1,%d})[^\\\"]*(\\\\?\\\"|)", "\"$1$2$3-xxxx$4") ); /** diff --git a/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilder.java b/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilder.java new file mode 100644 index 0000000..b3c71d9 --- /dev/null +++ b/ejmask-extensions/src/main/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilder.java @@ -0,0 +1,108 @@ +package com.ebay.ejmask.extenstion.builder.json; +/** + * Copyright (c) 2023 eBay Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import com.ebay.ejmask.api.PatternEntity; +import com.ebay.ejmask.extenstion.builder.AbstractRegexPatternBuilder; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import static com.ebay.ejmask.core.util.CommonUtils.emptyIfNull; + +/** + * An implementation of IPatternBuilder to support sensitive JSON field, whose value need to be partially masked. + * This builder is for masking the field value with a Numeric type. + * + * @author fsun1 + */ +public class JsonNumericFieldPatternBuilder extends AbstractRegexPatternBuilder { + + private static final List PATTERN_ENTITY_LIST = Arrays.asList( + /** + * Numeric field with value to be masked + * @link https://regex101.com/r/rOeErB/1 + */ + new PatternEntity("\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*)(-?\\b\\d+(\\.\\d+)?(e-?\\d+)?\\b)([^\\\"]{1,2})", "\"$1$2\"xxxx\"$6") + ); + + /** + * Build pattern to match + * + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return match pattern + */ + @Override + public String buildPattern(int visibleCharacters, String... fieldNames) { + return this.buildPattern(null, visibleCharacters, fieldNames); + } + + /** + * Build pattern to match + * @param patternEntity as instance of PatternEntity + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return + */ + private String buildPattern(PatternEntity patternEntity, int visibleCharacters, String... fieldNames) { + if (visibleCharacters < 1) { + throw new IllegalArgumentException("visibleCharacters must be a possessive value instead of " + visibleCharacters); + } + if(patternEntity == null) { + patternEntity = PATTERN_ENTITY_LIST.get(0); + } + return String.format(patternEntity.getPatternTemplate(), super.buildFieldNamesForRegexOr(fieldNames), visibleCharacters); + } + + + /** + * Build pattern to replace. + * + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return match pattern + */ + @Override + public String buildReplacement(int visibleCharacters, String... fieldNames) { + return this.buildReplacement(null, visibleCharacters, fieldNames); + } + + /** + * Build pattern to replace. + * + * @param patternEntity as instance of PatternEntity + * @param visibleCharacters as no of characters to be visible. + * @param fieldNames as list of field names + * @return match pattern + */ + private String buildReplacement(PatternEntity patternEntity, int visibleCharacters, String... fieldNames) { + if(patternEntity == null) { + patternEntity = PATTERN_ENTITY_LIST.get(0); + } + return patternEntity.getReplacementTemplate(); + } + + @Override + public List buildPatternEntities(int visibleCharacters, String... fieldNames) { + List result = new LinkedList<>(); + emptyIfNull(PATTERN_ENTITY_LIST).forEach(patternEntity -> { + result.add(new PatternEntity(this.buildPattern(patternEntity, visibleCharacters, fieldNames), this.buildReplacement(patternEntity, visibleCharacters, fieldNames))); + }); + return result; + } + +} diff --git a/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilderTest.java b/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilderTest.java new file mode 100644 index 0000000..c5827e5 --- /dev/null +++ b/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonBooleanFieldPatternBuilderTest.java @@ -0,0 +1,160 @@ +package com.ebay.ejmask.extenstion.builder.json; + +import com.ebay.ejmask.api.PatternEntity; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +/** + * @author fsun1 + */ +public class JsonBooleanFieldPatternBuilderTest { + + public static final JsonBooleanFieldPatternBuilder instance = new JsonBooleanFieldPatternBuilder(); + public static final String[] fieldNames = new String[]{"firstName", "lastName", "number", "boolValue"}; + + + /** + * Test of buildPattern method, of class JsonFieldPatternBuilder. + */ + @Test + public void testBuildPattern() { + int visibleCharacters = 12; + String result = instance.buildPattern(visibleCharacters, fieldNames); + Assertions.assertEquals("\\\"(firstName|lastName|number|boolValue)(\\\\*\\\"\\s*:\\s*\\\\*)(\\b(true|TRUE|True|false|FALSE|False)\\b)([^\\\"]{1,3})[^\\\"]*(\\\\?\\\"|)", result); + } + + /** + * Test of buildPattern method, of class JsonFieldPatternBuilder. + */ + @Test + public void testBuildPattern_without_visible_characters() { + int visibleCharacters = 0; + Assertions.assertThrows(IllegalArgumentException.class, () -> instance.buildPattern(visibleCharacters, fieldNames)); + } + + /** + * Test of buildReplacement method, of class JsonFieldPatternBuilder. + */ + @Test + public void testBuildReplacement() { + int visibleCharacters = 0; + String result = instance.buildReplacement(visibleCharacters, fieldNames); + Assertions.assertEquals("\"$1$2\"xxxx\"$5$6", result); + } + + @ParameterizedTest + @MethodSource("dataForTestMatch") + public void testMatch(String name, String data, String expected) { + String regex = instance.buildPattern(2, fieldNames); + String replacement = instance.buildReplacement(2, fieldNames); + Pattern pattern = Pattern.compile(regex); + String result = pattern.matcher(data).replaceAll(replacement); + Assertions.assertEquals(expected, result); + } + + @ParameterizedTest + @MethodSource("dataForTestMatch") + public void testMatchForPatternList(String name, String data, String expected) { + List patternEntityList = instance.buildPatternEntities(2, fieldNames); + String result = data; + for (PatternEntity patternEntity : patternEntityList) { + Pattern pattern = Pattern.compile(patternEntity.getPatternTemplate()); + result = pattern.matcher(result).replaceAll(patternEntity.getReplacementTemplate()); + } + Assertions.assertEquals(expected, result); + } + + static Stream dataForTestMatch() { + return Stream.of( + Arguments.arguments( + "test with normal json", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}" + ), + Arguments.arguments( + "test with empty values", + "{\"firstName\":\"\",\"lastName\":null,\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\":\"\",\"lastName\":null,\"nonSensitiveData\":\"firstName\"}" + ), + Arguments.arguments( + "test with space", + "{\"firstName\" : \"sensitive data\", \"lastName\" :\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\" : \"sensitive data\", \"lastName\" :\"sensitive data\",\"nonSensitiveData\":\"firstName\"}" + ), + Arguments.arguments( + "test with json encoded json", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}" + + ), + Arguments.arguments( + "test with double json encoded json", + "{\\\\\\\"firstName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"lastName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}", + "{\\\\\\\"firstName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"lastName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}" + ), + Arguments.arguments( + "test with encoded broken json", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data" + ), + Arguments.arguments( + "test with encoded broken json 2", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\" + ), + Arguments.arguments( + "test with normal json for integer", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}" + ), + Arguments.arguments( + "test with broken json for integer", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"" + ), + Arguments.arguments( + "test with normal json for flot", + "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", + "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}" + ), + Arguments.arguments( + "test with broken json for flot", + "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", + "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}" + ), + Arguments.arguments( + "test with normal json for scientific notation", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}" + ), + Arguments.arguments( + "test with broken json for scientific notation", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"" + ), + Arguments.arguments( + "test with normal json for boolean in all lower case", + "{\"serializedStr\":\"dink\",\"boolValue\":true,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":false }\"}", + "{\"serializedStr\":\"dink\",\"boolValue\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":\"xxxx\" }\"}" + ), + Arguments.arguments( + "test with normal json for boolean in all capital case", + "{\"serializedStr\":\"dink\",\"boolValue\":TRUE,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":FALSE }\"}", + "{\"serializedStr\":\"dink\",\"boolValue\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":\"xxxx\" }\"}" + ), + Arguments.arguments( + "test with normal json for boolean in first capital case", + "{\"serializedStr\":\"dink\",\"boolValue\":True,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":False }\"}", + "{\"serializedStr\":\"dink\",\"boolValue\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":\"xxxx\" }\"}" + ) + ); + } + +} diff --git a/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilderTest.java b/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilderTest.java index ca1103d..f6d278b 100644 --- a/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilderTest.java +++ b/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonFieldPatternBuilderTest.java @@ -61,7 +61,7 @@ public void testMatch(String name, String data, String expected) { } @ParameterizedTest - @MethodSource("dataForFullTestMatch") + @MethodSource("dataForTestMatch") public void testMatchForPatternList(String name, String data, String expected) { List patternEntityList = instance.buildPatternEntities(2, fieldNames); String result = data; @@ -149,133 +149,82 @@ static Stream dataForTestMatch() { "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\", //"{\\\"firstName\\\":\\\"se-xxxx\\\",\\\"lastName\\\":\\\"se-xxxx\\", "{\\\"firstName\\\":\\\"se-xxxx\",\\\"lastName\\\":\\\"se-xxxx" - )); - } - - static Stream dataForFullTestMatch() { - return Stream.of( - Arguments.arguments( - "test with normal json", - "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", - "{\"firstName\":\"se-xxxx\",\"lastName\":\"se-xxxx\",\"nonSensitiveData\":\"firstName\"}" - - ), - Arguments.arguments( - "test with empty values", - "{\"firstName\":\"\",\"lastName\":null,\"nonSensitiveData\":\"firstName\"}", - "{\"firstName\":\"\",\"lastName\":null,\"nonSensitiveData\":\"firstName\"}" - - ), - Arguments.arguments( - "test with space", - "{\"firstName\" : \"sensitive data\", \"lastName\" :\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", - "{\"firstName\" : \"se-xxxx\", \"lastName\" :\"se-xxxx\",\"nonSensitiveData\":\"firstName\"}" - - ), - Arguments.arguments( - "test with line break", - "{\n" - + " \"firstName\": \"sensitive data\",\n" - + " \"lastName\": \"sensitive data\",\n" - + " \"nonSensitiveData\": \"firstName\"\n" - + "}", - "{\n" - + " \"firstName\": \"se-xxxx\",\n" - + " \"lastName\": \"se-xxxx\",\n" - + " \"nonSensitiveData\": \"firstName\"\n" - + "}" - ), Arguments.arguments( - "test with broken json", - "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data", - "{\"firstName\":\"se-xxxx\",\"lastName\":\"se-xxxx" - + "test with normal json for integer", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}" ), Arguments.arguments( - "test with normal json", - "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", - "{\"firstName\":\"se-xxxx\",\"lastName\":\"se-xxxx\",\"nonSensitiveData\":\"firstName\"}" - + "test with broken json for integer", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"" ), - - /* - * TODO: json formatting is little messed up due to limitation - * of regex. commented the expected. - */ Arguments.arguments( - "test with json encoded json", - "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}", - //"{\\\"firstName\\\":\\\"se-xxxx\\\",\\\"lastName\\\":\\\"se-xxxx\\\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}" - "{\\\"firstName\\\":\\\"se-xxxx\",\\\"lastName\\\":\\\"se-xxxx\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}" - + "test with normal json for flot", + "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", + "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}" ), Arguments.arguments( - "test with double json encoded json", - "{\\\\\\\"firstName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"lastName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}", - //"{\\\\\\\"firstName\\\\\\\":\\\\\\\"se-xxxx\\\\\\\",\\\\\\\"lastName\\\\\\\":\\\\\\\"se-xxxx\\\\\\\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}" - "{\\\\\\\"firstName\\\\\\\":\\\\\\\"se-xxxx\",\\\\\\\"lastName\\\\\\\":\\\\\\\"se-xxxx\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}" - + "test with broken json for flot", + "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", + "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}" ), Arguments.arguments( - "test with encoded broken json", - "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data", - //"{\\\"firstName\\\":\\\"se-xxxx\\\",\\\"lastName\\\":\\\"se-xxxx" - "{\\\"firstName\\\":\\\"se-xxxx\",\\\"lastName\\\":\\\"se-xxxx" - + "test with normal json for scientific notation", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}" ), Arguments.arguments( - "test with encoded broken json 2", - "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\", - //"{\\\"firstName\\\":\\\"se-xxxx\\\",\\\"lastName\\\":\\\"se-xxxx\\", - "{\\\"firstName\\\":\\\"se-xxxx\",\\\"lastName\\\":\\\"se-xxxx" + "test with broken json for scientific notation", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"" ), Arguments.arguments( "test with normal json for integer", "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}", - "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}" ), Arguments.arguments( "test with broken json for integer", "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"", - "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"" + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"" ), Arguments.arguments( "test with normal json for flot", "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", - "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}" ), Arguments.arguments( "test with broken json for flot", "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", - "\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}" ), Arguments.arguments( "test with normal json for scientific notation", "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}", - "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}" ), Arguments.arguments( "test with broken json for scientific notation", "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"", - "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"" + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"" ), Arguments.arguments( "test with normal json for boolean in all lower case", "{\"serializedStr\":\"dink\",\"boolValue\":true,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":false }\"}", - "{\"serializedStr\":\"dink\",\"boolValue\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":\"xxxx\" }\"}" + "{\"serializedStr\":\"dink\",\"boolValue\":true,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":false }\"}" ), Arguments.arguments( "test with normal json for boolean in all capital case", "{\"serializedStr\":\"dink\",\"boolValue\":TRUE,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":FALSE }\"}", - "{\"serializedStr\":\"dink\",\"boolValue\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":\"xxxx\" }\"}" + "{\"serializedStr\":\"dink\",\"boolValue\":TRUE,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":FALSE }\"}" ), Arguments.arguments( "test with normal json for boolean in first capital case", "{\"serializedStr\":\"dink\",\"boolValue\":True,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":False }\"}", - "{\"serializedStr\":\"dink\",\"boolValue\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":\"xxxx\" }\"}" + "{\"serializedStr\":\"dink\",\"boolValue\":True,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":False }\"}" ) ); } - } diff --git a/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilderTest.java b/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilderTest.java new file mode 100644 index 0000000..ab287a1 --- /dev/null +++ b/ejmask-extensions/src/test/java/com/ebay/ejmask/extenstion/builder/json/JsonNumericFieldPatternBuilderTest.java @@ -0,0 +1,185 @@ +package com.ebay.ejmask.extenstion.builder.json; + +import com.ebay.ejmask.api.PatternEntity; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +/** + * @author fsun1 + */ +public class JsonNumericFieldPatternBuilderTest { + + public static final JsonNumericFieldPatternBuilder instance = new JsonNumericFieldPatternBuilder(); + public static final String[] fieldNames = new String[]{"firstName", "lastName", "number", "boolValue"}; + + + /** + * Test of buildPattern method, of class JsonFieldPatternBuilder. + */ + @Test + public void testBuildPattern() { + int visibleCharacters = 12; + String result = instance.buildPattern(visibleCharacters, fieldNames); + Assertions.assertEquals("\\\"(firstName|lastName|number|boolValue)(\\\\*\\\"\\s*:\\s*\\\\*)(-?\\b\\d+(\\.\\d+)?(e-?\\d+)?\\b)([^\\\"]{1,2})", result); + } + + /** + * Test of buildPattern method, of class JsonFieldPatternBuilder. + */ + @Test + public void testBuildPattern_without_visible_characters() { + int visibleCharacters = 0; + Assertions.assertThrows(IllegalArgumentException.class, () -> instance.buildPattern(visibleCharacters, fieldNames)); + } + + /** + * Test of buildReplacement method, of class JsonFieldPatternBuilder. + */ + @Test + public void testBuildReplacement() { + int visibleCharacters = 0; + String result = instance.buildReplacement(visibleCharacters, fieldNames); + Assertions.assertEquals("\"$1$2\"xxxx\"$6", result); + } + + @ParameterizedTest + @MethodSource("dataForTestMatch") + public void testMatch(String name, String data, String expected) { + String regex = instance.buildPattern(2, fieldNames); + String replacement = instance.buildReplacement(2, fieldNames); + Pattern pattern = Pattern.compile(regex); + String result = pattern.matcher(data).replaceAll(replacement); + Assertions.assertEquals(expected, result); + } + + @ParameterizedTest + @MethodSource("dataForTestMatch") + public void testMatchForPatternList(String name, String data, String expected) { + List patternEntityList = instance.buildPatternEntities(2, fieldNames); + String result = data; + for (PatternEntity patternEntity : patternEntityList) { + Pattern pattern = Pattern.compile(patternEntity.getPatternTemplate()); + result = pattern.matcher(result).replaceAll(patternEntity.getReplacementTemplate()); + } + Assertions.assertEquals(expected, result); + } + + static Stream dataForTestMatch() { + return Stream.of( + Arguments.arguments( + "test with normal json", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}" + + ), + Arguments.arguments( + "test with empty values", + "{\"firstName\":\"\",\"lastName\":null,\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\":\"\",\"lastName\":null,\"nonSensitiveData\":\"firstName\"}" + + ), + Arguments.arguments( + "test with space", + "{\"firstName\" : \"sensitive data\", \"lastName\" :\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\" : \"sensitive data\", \"lastName\" :\"sensitive data\",\"nonSensitiveData\":\"firstName\"}" + + ), + Arguments.arguments( + "test with line break", + "{\n" + + " \"firstName\": \"sensitive data\",\n" + + " \"lastName\": \"sensitive data\",\n" + + " \"nonSensitiveData\": \"firstName\"\n" + + "}", + "{\n" + + " \"firstName\": \"sensitive data\",\n" + + " \"lastName\": \"sensitive data\",\n" + + " \"nonSensitiveData\": \"firstName\"\n" + + "}" + ), + Arguments.arguments( + "test with broken json", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data" + ), + Arguments.arguments( + "test with normal json", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}", + "{\"firstName\":\"sensitive data\",\"lastName\":\"sensitive data\",\"nonSensitiveData\":\"firstName\"}" + ), + Arguments.arguments( + "test with json encoded json", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\\",\\\"nonSensitiveData\\\":\\\"firstName\\\"}" + ), + Arguments.arguments( + "test with double json encoded json", + "{\\\\\\\"firstName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"lastName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}", + "{\\\\\\\"firstName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"lastName\\\\\\\":\\\\\\\"sensitive data\\\\\\\",\\\\\\\"nonSensitiveData\\\\\\\":\\\\\\\"firstName\\\\\\\"}" + ), + Arguments.arguments( + "test with encoded broken json", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data" + ), + Arguments.arguments( + "test with encoded broken json 2", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\", + "{\\\"firstName\\\":\\\"sensitive data\\\",\\\"lastName\\\":\\\"sensitive data\\" + ), + Arguments.arguments( + "test with normal json for boolean in all lower case", + "{\"serializedStr\":\"dink\",\"boolValue\":true,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":false }\"}", + "{\"serializedStr\":\"dink\",\"boolValue\":true,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":false }\"}" + ), + Arguments.arguments( + "test with normal json for boolean in all capital case", + "{\"serializedStr\":\"dink\",\"boolValue\":TRUE,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":FALSE }\"}", + "{\"serializedStr\":\"dink\",\"boolValue\":TRUE,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":FALSE }\"}" + ), + Arguments.arguments( + "test with normal json for boolean in first capital case", + "{\"serializedStr\":\"dink\",\"boolValue\":True,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":False }\"}", + "{\"serializedStr\":\"dink\",\"boolValue\":True,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"boolValue\\\\\\\":False }\"}" + ), + Arguments.arguments( + "test with normal json for integer", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"}", + "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + ), + Arguments.arguments( + "test with broken json for integer", + "{\"serializedStr\":\"dink\",\"number\":123975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":123975 }\"", + "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"" + ), + Arguments.arguments( + "test with normal json for flot", + "{\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", + "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + ), + Arguments.arguments( + "test with broken json for flot", + "\"serializedStr\":\"dink\",\"number\":123.975,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-123.975 }\"}", + "\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + ), + Arguments.arguments( + "test with normal json for scientific notation", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"}", + "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"}" + ), + Arguments.arguments( + "test with broken json for scientific notation", + "{\"serializedStr\":\"dink\",\"number\":0.123e10,\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":-0.123e10 }\"", + "{\"serializedStr\":\"dink\",\"number\":\"xxxx\",\"serializedStringNumber\":\"{\\\\\\\"serializedStr\\\\\\\":\\\\\\\"dink\\\\\\\", \\\\\\\"number\\\\\\\":\"xxxx\" }\"" + ) + ); + } + +}