<commit_before>/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. Camunda licenses this file to you under the Apache License,
 * Version 2.0; you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://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.
 */
package org.camunda.bpm.engine.test.standalone.identity;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;

import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.exception.NullValueException;
import org.camunda.bpm.engine.identity.CheckPasswordAgainstPolicyResult;
import org.camunda.bpm.engine.identity.PasswordPolicy;
import org.camunda.bpm.engine.identity.PasswordPolicyRule;
import org.camunda.bpm.engine.impl.identity.DefaultPasswordPolicyImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyDigitRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyLengthRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyLowerCaseRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicySpecialCharacterRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyUpperCaseRuleImpl;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * @author <NAME>
 */
public class DefaultPasswordPolicyTest {

  @Rule
  public ProcessEngineRule rule = new ProcessEngineRule();

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  protected IdentityService identityService;

  // enforces a minimum length of 10 characters, at least one upper, one
  // lower case, one digit and one special character
  protected PasswordPolicy policy = new DefaultPasswordPolicyImpl();

  @Before
  public void init() {
    identityService = rule.getIdentityService();

    rule.getProcessEngineConfiguration()
      .setPasswordPolicy(new DefaultPasswordPolicyImpl())
      .setDisablePasswordPolicy(false);
  }

  @After
  public void resetProcessEngineConfig() {
    rule.getProcessEngineConfiguration()
      .setPasswordPolicy(null)
      .setDisablePasswordPolicy(true);
  }

  @Test
  public void testGoodPassword() {
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy(policy, "<PASSWORD>");
    assertThat(result.getViolatedRules().size(), is(0));
    assertThat(result.getFulfilledRules().size(), is(5));
    assertThat(result.isValid(), is(true));
  }

  @Test
  public void testPasswordWithoutLowerCase() {
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy(policy, "<PASSWORD>");
    checkThatPasswordWasInvalid(result);

    PasswordPolicyRule rule = result.getViolatedRules().get(0);
    assertThat(rule.getPlaceholder(), is(PasswordPolicyLowerCaseRuleImpl.PLACEHOLDER));
    assertThat(rule, instanceOf(PasswordPolicyLowerCaseRuleImpl.class));
  }

  @Test
  public void testPasswordWithoutUpperCase() {
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy(policy, "<PASSWORD>");
    checkThatPasswordWasInvalid(result);

    PasswordPolicyRule rule = result.getViolatedRules().get(0);
    assertThat(rule.getPlaceholder(), is(PasswordPolicyUpperCaseRuleImpl.PLACEHOLDER));
    assertThat(rule, instanceOf(PasswordPolicyUpperCaseRuleImpl.class));
  }
<commit_msg>test(engine): add test to check password without passing policy<commit_after>/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright
 * ownership. Camunda licenses this file to you under the Apache License,
 * Version 2.0; you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://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.
 */
package org.camunda.bpm.engine.test.standalone.identity;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;

import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.exception.NullValueException;
import org.camunda.bpm.engine.identity.CheckPasswordAgainstPolicyResult;
import org.camunda.bpm.engine.identity.PasswordPolicy;
import org.camunda.bpm.engine.identity.PasswordPolicyRule;
import org.camunda.bpm.engine.impl.identity.DefaultPasswordPolicyImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyDigitRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyLengthRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyLowerCaseRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicySpecialCharacterRuleImpl;
import org.camunda.bpm.engine.impl.identity.PasswordPolicyUpperCaseRuleImpl;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * @author <NAME>
 */
public class DefaultPasswordPolicyTest {

  @Rule
  public ProcessEngineRule rule = new ProcessEngineRule();

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  protected IdentityService identityService;

  // enforces a minimum length of 10 characters, at least one upper, one
  // lower case, one digit and one special character
  protected PasswordPolicy policy = new DefaultPasswordPolicyImpl();

  @Before
  public void init() {
    identityService = rule.getIdentityService();

    rule.getProcessEngineConfiguration()
      .setPasswordPolicy(new DefaultPasswordPolicyImpl())
      .setDisablePasswordPolicy(false);
  }

  @After
  public void resetProcessEngineConfig() {
    rule.getProcessEngineConfiguration()
      .setPasswordPolicy(null)
      .setDisablePasswordPolicy(true);
  }

  @Test
  public void testGoodPassword() {
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy(policy, "<PASSWORD>");
    assertThat(result.getViolatedRules().size(), is(0));
    assertThat(result.getFulfilledRules().size(), is(5));
    assertThat(result.isValid(), is(true));
  }

  @Test
  public void shouldCheckValidPassword_WithoutPassingPolicy() {
    // given

    // then
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy("<PASSWORD>");

    // when
    assertThat(result, notNullValue());
  }

  @Test
  public void testPasswordWithoutLowerCase() {
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy(policy, "<PASSWORD>");
    checkThatPasswordWasInvalid(result);

    PasswordPolicyRule rule = result.getViolatedRules().get(0);
    assertThat(rule.getPlaceholder(), is(PasswordPolicyLowerCaseRuleImpl.PLACEHOLDER));
    assertThat(rule, instanceOf(PasswordPolicyLowerCaseRuleImpl.class));
  }

  @Test
  public void testPasswordWithoutUpperCase() {
    CheckPasswordAgainstPolicyResult result = identityService.checkPasswordAgainstPolicy(policy, "<PASSWORD>");
    checkThatPasswordWasInvalid(result);

    PasswordPolicyRule rule = result.getViolatedRules().get(0);
    assertThat(rule.getPlaceholder(), is(PasswordPolicyUpperCaseRuleImpl.PLACEHOLDER));
    assertThat(rule, instanceOf(PasswordPolicyUpperCaseRuleImpl.class));
  }

{'fraction_non_alphanumeric': 0.0901252067091897, 'fraction_numerical': 0.0023623907394283014, 'mean_word_length': 5.4192570128885516, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7326262', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2271, 'n_words': 556}