use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryService method testRulePatterns.
public String testRulePatterns(List<AnonymizationRule> rules, String input) {
String output = input;
for (AnonymizationRule rule : rules) {
String decodedRule = new String(Base64.getDecoder().decode(rule.getValue().getBytes()));
Pattern p = createAndCheckPattern(decodedRule);
Replacer replacer = p.replacer(rule.getReplacement());
output = replacer.replace(output);
}
return output;
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method createAccountTelemetryConfig.
private AccountTelemetryConfig createAccountTelemetryConfig() {
AccountTelemetryConfig config = new AccountTelemetryConfig();
List<AnonymizationRule> defaultRules = new ArrayList<>();
defaultRules.add(createRule("\\b([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-\\._]*[A-Za-z0-9])@(([A-Za-z0-9]|" + "[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])\\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])\\b", "email@redacted.host"));
defaultRules.add(createRule("\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}", "XXXX-XXXX-XXXX-XXXX"));
defaultRules.add(createRule("\\d{3}[^\\w]\\d{2}[^\\w]\\d{4}", "XXX-XX-XXXX"));
defaultRules.add(createRule("FPW\\:\\s+[\\w|\\W].*", "FPW: [REDACTED]"));
defaultRules.add(createRule("cdpHashedPassword=.*[']", "[CDP PWD ATTRS REDACTED]"));
config.setRules(defaultRules);
return config;
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method testRulePatternWithInvalidPattern.
@Test
public void testRulePatternWithInvalidPattern() {
// GIVEN
String input = "My email card number is: 1111-2222-3333-4444";
List<AnonymizationRule> rules = new ArrayList<>();
AnonymizationRule rule = new AnonymizationRule();
rule.setReplacement("[REDACTED]");
String pattern = "\\d{8}[^[[";
String encodedPattern = new String(Base64.getEncoder().encode(pattern.getBytes()));
rule.setValue(encodedPattern);
rules.add(rule);
// THEN
assertThrows(BadRequestException.class, () -> {
// WHEN
underTest.testRulePatterns(rules, input);
});
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method testDefaultRules.
@Test
public void testDefaultRules() {
// GIVEN
// WHEN
AccountTelemetry result = underTest.createDefaultAccuontTelemetry();
// THEN
for (AnonymizationRule rule : result.getRules()) {
testPatternWithOutput(rule, "str myemail@email.com", "email");
testPatternWithOutput(rule, "333-44-2222", "XXX-");
testPatternWithOutput(rule, "card number: 1111-2222-3333-4444", "XXXX-");
testPatternWithOutput(rule, "- FPW: secret", "FPW");
testPatternWithOutput(rule, "cdpHashedPassword='{SHA512}abcdef'", "[CDP");
}
assertThat(result.getFeatures().getClusterLogsCollection().isEnabled()).isEqualTo(false);
}
use of com.sequenceiq.common.api.telemetry.model.AnonymizationRule in project cloudbreak by hortonworks.
the class AccountTelemetryServiceTest method testRulePatternsNoMatch.
@Test
public void testRulePatternsNoMatch() {
// GIVEN
String input = "My email card number is: 1111-2222-3333-4444";
List<AnonymizationRule> rules = new ArrayList<>();
AnonymizationRule rule = new AnonymizationRule();
rule.setReplacement("[REDACTED]");
String pattern = "\\d{8}[^\\w]\\d{8}[^\\w]\\d{8}[^\\w]\\d{8}";
String encodedPattern = new String(Base64.getEncoder().encode(pattern.getBytes()));
rule.setValue(encodedPattern);
rules.add(rule);
String output = underTest.testRulePatterns(rules, input);
// THEN
assertEquals(input, output);
}
Aggregations