Fix AdminRecoveryTest to not break admin tests

This commit is contained in:
mposolda 2015-06-09 17:44:07 +02:00
parent 9a5ca4d367
commit e96ba202e9

View file

@ -24,11 +24,13 @@ import org.junit.Rule;
import org.junit.Test;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserCredentialValueModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserModel.RequiredAction;
import org.keycloak.offlineconfig.AdminRecovery;
import org.keycloak.offlineconfig.OfflineConfigException;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.testsuite.rule.KeycloakRule;
import org.keycloak.testsuite.rule.WebRule;
@ -39,7 +41,27 @@ import org.keycloak.testsuite.rule.WebRule;
*/
public class AdminRecoveryTest {
@ClassRule
public static KeycloakRule keycloakRule = new KeycloakRule();
public static KeycloakRule keycloakRule = new KeycloakRule() {
@Override
protected void after() {
// Need to reset admin user to default password and remove required action to not break next tests
update(new KeycloakSetup() {
@Override
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
UserModel adminUser = session.users().getUserByUsername("admin", adminstrationRealm);
UserCredentialModel password = UserCredentialModel.password("admin");
adminUser.updateCredential(password);
adminUser.removeRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD);
}
});
super.after();
}
};
@Rule
public WebRule webRule = new WebRule(this);