KEYCLOAK-10770 user-storage/{id}/sync should return 400 instead of 404

This commit is contained in:
Hisanobu Okuda 2019-07-04 17:45:35 +09:00 committed by Stian Thorgersen
parent 37b7b595a5
commit da49dbce2b
2 changed files with 33 additions and 1 deletions

View file

@ -142,8 +142,12 @@ public class UserStorageProviderResource {
syncResult = syncManager.syncAllUsers(session.getKeycloakSessionFactory(), realm.getId(), providerModel);
} else if ("triggerChangedUsersSync".equals(action)) {
syncResult = syncManager.syncChangedUsers(session.getKeycloakSessionFactory(), realm.getId(), providerModel);
} else if (action == null || action == "") {
logger.debug("Missing action");
throw new BadRequestException("Missing action");
} else {
throw new NotFoundException("Unknown action: " + action);
logger.debug("Unknown action: " + action);
throw new BadRequestException("Unknown action: " + action);
}
Map<String, Object> eventRep = new HashMap<>();

View file

@ -28,6 +28,7 @@ import org.junit.runners.MethodSorters;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.component.ComponentModel;
import org.keycloak.representations.idm.ComponentRepresentation;
import org.keycloak.representations.idm.SynchronizationResultRepresentation;
import org.keycloak.services.managers.UserStorageSyncManager;
import org.keycloak.storage.ldap.idm.model.LDAPObject;
import org.keycloak.models.KeycloakSessionFactory;
@ -47,6 +48,8 @@ import org.keycloak.testsuite.util.WaitUtils;
import static org.keycloak.testsuite.arquillian.DeploymentTargetModifier.AUTH_SERVER_CURRENT;
import javax.ws.rs.BadRequestException;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@ -355,4 +358,29 @@ public class LDAPSyncTest extends AbstractLDAPTest {
});
}
// KEYCLOAK-10770 user-storage/{id}/sync should return 400 instead of 404
@Test
public void test05SyncRestAPIMissingAction() {
ComponentRepresentation ldapRep = testRealm().components().component(ldapModelId).toRepresentation();
try {
SynchronizationResultRepresentation syncResultRep = adminClient.realm("test").userStorage().syncUsers( ldapModelId, null);
Assert.fail("Should throw 400");
} catch (Exception e) {
Assert.assertTrue(e instanceof BadRequestException);
}
}
// KEYCLOAK-10770 user-storage/{id}/sync should return 400 instead of 404
@Test
public void test06SyncRestAPIWrongAction() {
ComponentRepresentation ldapRep = testRealm().components().component(ldapModelId).toRepresentation();
try {
SynchronizationResultRepresentation syncResultRep = adminClient.realm("test").userStorage().syncUsers( ldapModelId, "wrong action");
Assert.fail("Should throw 400");
} catch (Exception e) {
Assert.assertTrue(e instanceof BadRequestException);
}
}
}