-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adding 'single_word_only' option to obfuscate processor Signed-off-by: Utkarsh Agarwal <[email protected]> (cherry picked from commit 6d48efb) Co-authored-by: Utkarsh Agarwal <[email protected]>
- Loading branch information
1 parent
738936a
commit 10b94f1
Showing
4 changed files
with
62 additions
and
3 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
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
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
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 |
---|---|---|
|
@@ -76,13 +76,14 @@ private Record<Event> createRecord(String message) { | |
|
||
@BeforeEach | ||
void setup() { | ||
final ObfuscationProcessorConfig defaultConfig = new ObfuscationProcessorConfig("message", null, null, null, null); | ||
final ObfuscationProcessorConfig defaultConfig = new ObfuscationProcessorConfig("message", null, null, null, null, false); | ||
lenient().when(mockConfig.getSource()).thenReturn(defaultConfig.getSource()); | ||
lenient().when(mockConfig.getAction()).thenReturn(defaultConfig.getAction()); | ||
lenient().when(mockConfig.getPatterns()).thenReturn(defaultConfig.getPatterns()); | ||
lenient().when(mockConfig.getTarget()).thenReturn(defaultConfig.getTarget()); | ||
lenient().when(mockConfig.getObfuscateWhen()).thenReturn(null); | ||
lenient().when(mockConfig.getTagsOnMatchFailure()).thenReturn(List.of(UUID.randomUUID().toString())); | ||
lenient().when(mockConfig.getSingleWordOnly()).thenReturn(defaultConfig.getSingleWordOnly()); | ||
obfuscationProcessor = new ObfuscationProcessor(pluginMetrics, mockConfig, mockFactory, expressionEvaluator); | ||
} | ||
|
||
|
@@ -368,7 +369,7 @@ void testProcessorWithBaseNumberPattern(String message, String expected) { | |
Event data = editedRecords.get(0).getData(); | ||
assertThat(data.get("message", String.class), equalTo(expected)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"My email is [email protected],My email is ***", | ||
|
@@ -388,6 +389,49 @@ void testProcessorWithMultiplePatterns(String message, String expected) { | |
assertThat(data.get("message", String.class), equalTo(expected)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"My email is [email protected],%{EMAIL_ADDRESS},My email is ***", | ||
"testing this functionality, test, testing this functionality", | ||
"test this functionality, test, *** this functionality", | ||
"My IP is 1.1.1.1,%{IP_ADDRESS_V4},My IP is ***", | ||
"fd55555069-e7a9-11ee4111111111111111,%{CREDIT_CARD_NUMBER},fd55555069-e7a9-11ee4111111111111111", | ||
"4111111111111111,%{CREDIT_CARD_NUMBER},***", | ||
"visa4111111111111111,%{CREDIT_CARD_NUMBER},visa4111111111111111" | ||
}) | ||
void testProcessorWithSingleWordOnly(String message, String pattern, String expected) { | ||
when(mockConfig.getSingleWordOnly()).thenReturn(true); | ||
when(mockConfig.getPatterns()).thenReturn(List.of(pattern)); | ||
obfuscationProcessor = new ObfuscationProcessor(pluginMetrics, mockConfig, mockFactory, expressionEvaluator); | ||
|
||
final Record<Event> record = createRecord(message); | ||
final List<Record<Event>> editedRecords = (List<Record<Event>>) obfuscationProcessor.doExecute(Collections.singletonList(record)); | ||
|
||
assertThat(editedRecords.size(), equalTo(1)); | ||
Event data = editedRecords.get(0).getData(); | ||
assertThat(data.get("message", String.class), equalTo(expected)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"My email is [email protected],My email is ***", | ||
"My IP is 1.1.1.1,My IP is ***", | ||
"My IP is 1.1.1.1 and tracking id is fd55555069-e7a9-11ee4111111111111111,My IP is *** and tracking id is fd55555069-e7a9-11ee4111111111111111", | ||
"My IP is 1.1.1.1 and credit card number is 4111111111111111,My IP is *** and credit card number is ***", | ||
"My IP is 1.1.1.1 and credit card number is visa4111111111111111,My IP is *** and credit card number is visa4111111111111111" | ||
}) | ||
void testProcessorWithMultiplePatternsWithSingleWordOnly(String message, String expected) { | ||
when(mockConfig.getSingleWordOnly()).thenReturn(true); | ||
when(mockConfig.getPatterns()).thenReturn(List.of("%{EMAIL_ADDRESS}", "%{IP_ADDRESS_V4}", "%{CREDIT_CARD_NUMBER}")); | ||
obfuscationProcessor = new ObfuscationProcessor(pluginMetrics, mockConfig, mockFactory, expressionEvaluator); | ||
|
||
final Record<Event> record = createRecord(message); | ||
final List<Record<Event>> editedRecords = (List<Record<Event>>) obfuscationProcessor.doExecute(Collections.singletonList(record)); | ||
|
||
assertThat(editedRecords.size(), equalTo(1)); | ||
Event data = editedRecords.get(0).getData(); | ||
assertThat(data.get("message", String.class), equalTo(expected)); | ||
} | ||
|
||
@Test | ||
void testIsReadyForShutdown() { | ||
|