Skip to content

Commit

Permalink
[KEYCLOAK-6111] 'Override User-Initiated Action Lifespan' admin GUI c…
Browse files Browse the repository at this point in the history
…an break realm configuration
  • Loading branch information
Bruno Oliveira committed Feb 9, 2018
1 parent 505cf5b commit b91998a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static java.util.Objects.nonNull;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
Expand Down Expand Up @@ -480,6 +482,7 @@ public Map<String, Integer> getUserActionTokenLifespans() {

getAttributes().entrySet().stream()
.filter(Objects::nonNull)
.filter(entry -> nonNull(entry.getValue()))
.filter(entry -> entry.getKey().startsWith(RealmAttributes.ACTION_TOKEN_GENERATED_BY_USER_LIFESPAN + "."))
.forEach(entry -> userActionTokens.put(entry.getKey().substring(RealmAttributes.ACTION_TOKEN_GENERATED_BY_USER_LIFESPAN.length() + 1), Integer.valueOf(entry.getValue())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class Form {
private WebElement cancel;

public void save() {
// guardAjax(save).click();
clickLink(save);
}

Expand All @@ -70,5 +69,11 @@ public static void setInputValue(WebElement input, String value) {
// TODO log warning
}
}
public WebElement saveBtn() {
return save;
}

public WebElement cancelBtn() {
return cancel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -140,6 +141,23 @@ public void testLifespanActionTokenPropagatedForVerifyEmailAndResetPassword() th

}

@Test
public void testButtonDisabledForEmptyAttributes() throws InterruptedException {
tokenSettingsPage.form().setOperation(VerifyEmailActionToken.TOKEN_TYPE, TIMEOUT, TimeUnit.DAYS);
tokenSettingsPage.form().save();
assertAlertSuccess();

loginToTestRealmConsoleAs(testUser);
driver.navigate().refresh();

tokenSettingsPage.navigateTo();
tokenSettingsPage.form().selectOperation(VerifyEmailActionToken.TOKEN_TYPE);
tokenSettingsPage.form().selectOperation(ResetCredentialsActionToken.TOKEN_TYPE);

assertFalse("Save button should be disabled", tokenSettingsPage.form().saveBtn().isEnabled());
assertFalse("Cancel button should be disabled", tokenSettingsPage.form().cancelBtn().isEnabled());
}

@Test
public void testLifespanActionTokenResetForVerifyEmail() throws InterruptedException {
tokenSettingsPage.form().setOperation(VerifyEmailActionToken.TOKEN_TYPE, TIMEOUT, TimeUnit.DAYS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,12 @@ module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http,

var oldCopy = angular.copy($scope.realm);
$scope.changed = false;

var refresh = function() {
Realm.get($scope.realm, function () {
$scope.changed = false;
});
};

$scope.$watch('realm', function() {
if (!angular.equals($scope.realm, oldCopy)) {
Expand All @@ -1108,6 +1114,10 @@ module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http,

$scope.$watch('actionLifespanId', function () {
$scope.actionTokenAttribute = TimeUnit2.asUnit($scope.realm.attributes['actionTokenGeneratedByUserLifespan.' + $scope.actionLifespanId]);
//Refresh and disable the button if attribute is empty
if (!$scope.actionTokenAttribute.toSeconds()) {
refresh();
}
}, true);

$scope.$watch('actionTokenAttribute', function () {
Expand Down

0 comments on commit b91998a

Please sign in to comment.