Search in sources :

Example 6 with AnonymizationRule

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;
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) Pattern(jregex.Pattern) Replacer(jregex.Replacer)

Example 7 with AnonymizationRule

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;
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) AccountTelemetryConfig(com.sequenceiq.environment.configuration.telemetry.AccountTelemetryConfig) ArrayList(java.util.ArrayList)

Example 8 with AnonymizationRule

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);
    });
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with AnonymizationRule

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);
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) Test(org.junit.jupiter.api.Test)

Example 10 with AnonymizationRule

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);
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

AnonymizationRule (com.sequenceiq.common.api.telemetry.model.AnonymizationRule)11 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)6 AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)4 AccountTelemetryConfig (com.sequenceiq.environment.configuration.telemetry.AccountTelemetryConfig)2 Pattern (jregex.Pattern)2 Replacer (jregex.Replacer)2 CrnResourceDescriptor (com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor)1 RegionAwareCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Features (com.sequenceiq.common.api.telemetry.model.Features)1 AccountTelemetryRepository (com.sequenceiq.environment.telemetry.repository.AccountTelemetryRepository)1 Base64 (java.util.Base64)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 PatternSyntaxException (jregex.PatternSyntaxException)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1