KEYCLOAK-13097 fix UserStorageTest - add cleanup after test

This commit is contained in:
vramik 2020-02-26 10:07:37 +01:00 committed by Hynek Mlnařík
parent b19355dd76
commit e2bd99e9e4
3 changed files with 16 additions and 5 deletions

View file

@ -60,8 +60,8 @@ public class UserMapStorage implements UserLookupProvider, UserStorageProvider,
private static final Logger log = Logger.getLogger(UserMapStorage.class); private static final Logger log = Logger.getLogger(UserMapStorage.class);
protected Map<String, String> userPasswords; protected final Map<String, String> userPasswords;
protected ConcurrentMap<String, Set<String>> userGroups; protected final ConcurrentMap<String, Set<String>> userGroups;
protected ComponentModel model; protected ComponentModel model;
protected KeycloakSession session; protected KeycloakSession session;
protected EditMode editMode; protected EditMode editMode;

View file

@ -48,8 +48,8 @@ public class UserMapStorageFactory implements UserStorageProviderFactory<UserMap
configProperties.add(attr); configProperties.add(attr);
} }
protected Map<String, String> userPasswords = new ConcurrentHashMap<>(); private final Map<String, String> userPasswords = new ConcurrentHashMap<>();
protected ConcurrentMap<String, Set<String>> userGroups = new ConcurrentHashMap<>(); private final ConcurrentMap<String, Set<String>> userGroups = new ConcurrentHashMap<>();
@Override @Override
public List<ProviderConfigProperty> getConfigProperties() { public List<ProviderConfigProperty> getConfigProperties() {
@ -80,4 +80,9 @@ public class UserMapStorageFactory implements UserStorageProviderFactory<UserMap
public void close() { public void close() {
} }
public void clear() {
userPasswords.clear();
userGroups.clear();
}
} }

View file

@ -67,6 +67,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.keycloak.models.UserModel.RequiredAction.UPDATE_PROFILE; import static org.keycloak.models.UserModel.RequiredAction.UPDATE_PROFILE;
import org.keycloak.provider.ProviderFactory;
import static org.keycloak.storage.UserStorageProviderModel.CACHE_POLICY; import static org.keycloak.storage.UserStorageProviderModel.CACHE_POLICY;
import static org.keycloak.storage.UserStorageProviderModel.EVICTION_DAY; import static org.keycloak.storage.UserStorageProviderModel.EVICTION_DAY;
import static org.keycloak.storage.UserStorageProviderModel.EVICTION_HOUR; import static org.keycloak.storage.UserStorageProviderModel.EVICTION_HOUR;
@ -142,7 +143,7 @@ public class UserStorageTest extends AbstractAuthTest {
} }
@After @After
public void removeTestUser() throws URISyntaxException, IOException { public void afterTestCleanUp() throws URISyntaxException, IOException {
testingClient.server().run(session -> { testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test"); RealmModel realm = session.realms().getRealmByName("test");
if (realm == null) { if (realm == null) {
@ -154,6 +155,11 @@ public class UserStorageTest extends AbstractAuthTest {
session.userLocalStorage().removeUser(realm, user); session.userLocalStorage().removeUser(realm, user);
session.userCache().clear(); session.userCache().clear();
} }
//we need to clear userPasswords and userGroups from UserMapStorageFactory
UserMapStorageFactory userMapStorageFactory = (UserMapStorageFactory) session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, UserMapStorageFactory.PROVIDER_ID);
Assert.assertNotNull(userMapStorageFactory);
userMapStorageFactory.clear();
}); });
} }