/*
 * Copyright © 2013-2019 camunda services GmbH and various authors (info@camunda.com)
 *
 * 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
 *
 *     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.api.passwordpolicy;

import org.camunda.bpm.engine.identity.User;
import org.camunda.bpm.engine.impl.pwpolicy.PasswordPolicyException;
import org.camunda.bpm.engine.impl.test.ResourceProcessEngineTestCase;
import org.camunda.bpm.engine.pwpolicy.PasswordPolicy;

/**
 * @author Miklas Boskamp
 */
public class CustomPasswordPolicyTest extends ResourceProcessEngineTestCase {

  public CustomPasswordPolicyTest() {
    super("org/camunda/bpm/engine/test/api/passwordpolicy/passwordpolicy.custom.camunda.cfg.xml");
  }

  @Override
  protected void tearDown() throws Exception {
    identityService.deleteUser("user");
  }

  public void testCustomPasswordPolicy() {
    PasswordPolicy policy = processEngineConfiguration.getPasswordPolicy();
    assertTrue(policy.getClass().isAssignableFrom(CustomPasswordPolicyImpl.class));
    assertEquals(2, policy.getRules().size());

    User user = identityService.newUser("user");

    // check password blacklist rule is invoked
    for (String password : CustomPasswordPolicyImpl.passwordBlacklist) {
      try {
        user.setPassword(password);
        identityService.saveUser(user);
        fail();
      } catch (PasswordPolicyException e) {
        assertEquals(policy.getRules(), e.getPolicyRules());
      }
    }

    // check consecutive digit rule is invoked
    try {
      user.setPassword("password42");
      identityService.saveUser(user);
      fail();
    } catch (PasswordPolicyException e) {
      assertEquals(policy.getRules(), e.getPolicyRules());
    }

    // check user is saved when password is policy compliant
    user.setPassword("this should work");
    identityService.saveUser(user);
  }
}
@@ -712,44 +712,359 @@
 ort 
-org.camunda.bpm.engine.identity.User
+static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fail;%0A%0Aimport org.camunda.bpm.engine.IdentityService;%0Aimport org.camunda.bpm.engine.identity.User;%0Aimport org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;%0Aimport org.camunda.bpm.engine.impl.pwpolicy.DefaultPasswordPolicyImpl
 ;%0Aim
@@ -1164,26 +1164,68 @@
 ine.
-impl.test.Resource
+pwpolicy.PasswordPolicy;%0Aimport org.camunda.bpm.engine.test.
 Proc
@@ -1233,23 +1233,19 @@
 ssEngine
-TestCas
+Rul
 e;%0Aimpor
@@ -1273,347 +1273,957 @@
 ine.
-pwpolicy.PasswordPolicy;%0A%0A/**%0A * @author Miklas Boskamp%0A */%0Apublic class CustomPasswordPolicyTest extends ResourceProcessEngineTestCase %7B%0A%0A  public CustomPasswordPolicyTest() %7B%0A    super(%22org/camunda/bpm/engine/test/api/p
+test.util.ProvidedProcessEngineRule;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0A%0A/**%0A * @author Miklas Boskamp%0A */%0Apublic class CustomPasswordPolicyTest %7B%0A%0A  @Rule%0A  public ProcessEngineRule engineRule = new ProvidedProcessEngineRule();%0A%0A  private ProcessEngineConfigurationImpl processEngineConfiguration;%0A  private IdentityService identityService;%0A%0A  @Before%0A  public void init() %7B%0A    identityService = engineRule.getIdentityService();%0A    processEngineConfiguration = engineRule.getProcessEngineConfiguration();%0A    processEngineConfiguration.setP
 assword
-p
+P
 olicy
-/p
+(new CustomP
 assword
-p
+P
 olicy
-.custom.camunda.cfg.xml%22);%0A  %7D%0A%0A  @Override%0A  protected void tearDown() throws Exception %7B
+Impl());%0A    processEngineConfiguration.setDisablePasswordPolicy(false);%0A  %7D%0A%0A  @After%0A  public void tearDown() %7B%0A    // reset configuration%0A    processEngineConfiguration.setPasswordPolicy(new DefaultPasswordPolicyImpl());%0A    processEngineConfiguration.setDisablePasswordPolicy(true);%0A    // reset database
 %0A   
@@ -2264,16 +2264,24 @@
 );%0A  %7D%0A%0A
+  @Test%0A
   public

Use programmatically configured engine in passwordpolicy test