From b6b7c1151737afb78dd69e59472ea93d66e6e16b Mon Sep 17 00:00:00 2001 From: Sebastian Laskawiec Date: Tue, 15 Oct 2019 09:48:26 +0200 Subject: [PATCH] KEYCLOAK-11725 Removed VaultRealmModel from tests --- .../FilesPlainTextVaultProviderFactory.java | 6 +- .../PlainTextVaultProviderFactoryTest.java | 1187 +---------------- 2 files changed, 11 insertions(+), 1182 deletions(-) diff --git a/services/src/main/java/org/keycloak/vault/FilesPlainTextVaultProviderFactory.java b/services/src/main/java/org/keycloak/vault/FilesPlainTextVaultProviderFactory.java index c18cd93fa6..7ef731f4bc 100644 --- a/services/src/main/java/org/keycloak/vault/FilesPlainTextVaultProviderFactory.java +++ b/services/src/main/java/org/keycloak/vault/FilesPlainTextVaultProviderFactory.java @@ -30,7 +30,7 @@ public class FilesPlainTextVaultProviderFactory implements VaultProviderFactory logger.debug("Can not create a vault since it's disabled or not initialized correctly"); return null; } - return new FilesPlainTextVaultProvider(vaultPath, session.getContext().getRealm().getName()); + return new FilesPlainTextVaultProvider(vaultPath, getRealmName(session)); } @Override @@ -60,4 +60,8 @@ public class FilesPlainTextVaultProviderFactory implements VaultProviderFactory public String getId() { return PROVIDER_ID; } + + protected String getRealmName(KeycloakSession session) { + return session.getContext().getRealm().getName(); + } } diff --git a/services/src/test/java/org/keycloak/vault/PlainTextVaultProviderFactoryTest.java b/services/src/test/java/org/keycloak/vault/PlainTextVaultProviderFactoryTest.java index 3156949e7a..233ea31af3 100644 --- a/services/src/test/java/org/keycloak/vault/PlainTextVaultProviderFactoryTest.java +++ b/services/src/test/java/org/keycloak/vault/PlainTextVaultProviderFactoryTest.java @@ -4,31 +4,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.keycloak.Config; -import org.keycloak.common.enums.SslRequired; -import org.keycloak.component.ComponentModel; -import org.keycloak.models.AuthenticationExecutionModel; -import org.keycloak.models.AuthenticationFlowModel; -import org.keycloak.models.AuthenticatorConfigModel; -import org.keycloak.models.ClientModel; -import org.keycloak.models.ClientScopeModel; -import org.keycloak.models.GroupModel; -import org.keycloak.models.IdentityProviderMapperModel; -import org.keycloak.models.IdentityProviderModel; import org.keycloak.models.KeycloakSession; -import org.keycloak.models.OTPPolicy; -import org.keycloak.models.PasswordPolicy; -import org.keycloak.models.RealmModel; -import org.keycloak.models.RequiredActionProviderModel; -import org.keycloak.models.RequiredCredentialModel; -import org.keycloak.models.RoleModel; -import org.keycloak.models.WebAuthnPolicy; import org.keycloak.services.DefaultKeycloakSession; import org.keycloak.services.DefaultKeycloakSessionFactory; -import java.util.List; -import java.util.Map; -import java.util.Set; - import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -46,10 +25,13 @@ public class PlainTextVaultProviderFactoryTest { public void shouldInitializeVaultCorrectly() { //given VaultConfig config = new VaultConfig(Scenario.EXISTING.getAbsolutePathAsString()); - FilesPlainTextVaultProviderFactory factory = new FilesPlainTextVaultProviderFactory(); - KeycloakSession session = new DefaultKeycloakSession(new DefaultKeycloakSessionFactory()); - session.getContext().setRealm(new VaultRealmModel()); + FilesPlainTextVaultProviderFactory factory = new FilesPlainTextVaultProviderFactory() { + @Override + protected String getRealmName(KeycloakSession session) { + return "test"; + } + }; //when factory.init(config); @@ -87,1163 +69,6 @@ public class PlainTextVaultProviderFactoryTest { assertNull(provider); } - /** - * A whitebox implementation of the Realm model, which is needed to extract realm name. - * Please use only for testing {@link FilesPlainTextVaultProviderFactory}. - */ - private static class VaultRealmModel implements RealmModel { - - @Override - public String getId() { - return null; - } - - @Override - public RoleModel getRole(String name) { - return null; - } - - @Override - public RoleModel addRole(String name) { - return null; - } - - @Override - public RoleModel addRole(String id, String name) { - return null; - } - - @Override - public boolean removeRole(RoleModel role) { - return false; - } - - @Override - public Set getRoles() { - return null; - } - - @Override - public List getDefaultRoles() { - return null; - } - - @Override - public void addDefaultRole(String name) { - - } - - @Override - public void updateDefaultRoles(String... defaultRoles) { - - } - - @Override - public void removeDefaultRoles(String... defaultRoles) { - - } - - @Override - public String getName() { - return "test"; - } - - @Override - public void setName(String name) { - - } - - @Override - public String getDisplayName() { - return null; - } - - @Override - public void setDisplayName(String displayName) { - - } - - @Override - public String getDisplayNameHtml() { - return null; - } - - @Override - public void setDisplayNameHtml(String displayNameHtml) { - - } - - @Override - public boolean isEnabled() { - return false; - } - - @Override - public void setEnabled(boolean enabled) { - - } - - @Override - public SslRequired getSslRequired() { - return null; - } - - @Override - public void setSslRequired(SslRequired sslRequired) { - - } - - @Override - public boolean isRegistrationAllowed() { - return false; - } - - @Override - public void setRegistrationAllowed(boolean registrationAllowed) { - - } - - @Override - public boolean isRegistrationEmailAsUsername() { - return false; - } - - @Override - public void setRegistrationEmailAsUsername(boolean registrationEmailAsUsername) { - - } - - @Override - public boolean isRememberMe() { - return false; - } - - @Override - public void setRememberMe(boolean rememberMe) { - - } - - @Override - public boolean isEditUsernameAllowed() { - return false; - } - - @Override - public void setEditUsernameAllowed(boolean editUsernameAllowed) { - - } - - @Override - public boolean isUserManagedAccessAllowed() { - return false; - } - - @Override - public void setUserManagedAccessAllowed(boolean userManagedAccessAllowed) { - - } - - @Override - public void setAttribute(String name, String value) { - - } - - @Override - public void setAttribute(String name, Boolean value) { - - } - - @Override - public void setAttribute(String name, Integer value) { - - } - - @Override - public void setAttribute(String name, Long value) { - - } - - @Override - public void removeAttribute(String name) { - - } - - @Override - public String getAttribute(String name) { - return null; - } - - @Override - public Integer getAttribute(String name, Integer defaultValue) { - return null; - } - - @Override - public Long getAttribute(String name, Long defaultValue) { - return null; - } - - @Override - public Boolean getAttribute(String name, Boolean defaultValue) { - return null; - } - - @Override - public Map getAttributes() { - return null; - } - - @Override - public boolean isBruteForceProtected() { - return false; - } - - @Override - public void setBruteForceProtected(boolean value) { - - } - - @Override - public boolean isPermanentLockout() { - return false; - } - - @Override - public void setPermanentLockout(boolean val) { - - } - - @Override - public int getMaxFailureWaitSeconds() { - return 0; - } - - @Override - public void setMaxFailureWaitSeconds(int val) { - - } - - @Override - public int getWaitIncrementSeconds() { - return 0; - } - - @Override - public void setWaitIncrementSeconds(int val) { - - } - - @Override - public int getMinimumQuickLoginWaitSeconds() { - return 0; - } - - @Override - public void setMinimumQuickLoginWaitSeconds(int val) { - - } - - @Override - public long getQuickLoginCheckMilliSeconds() { - return 0; - } - - @Override - public void setQuickLoginCheckMilliSeconds(long val) { - - } - - @Override - public int getMaxDeltaTimeSeconds() { - return 0; - } - - @Override - public void setMaxDeltaTimeSeconds(int val) { - - } - - @Override - public int getFailureFactor() { - return 0; - } - - @Override - public void setFailureFactor(int failureFactor) { - - } - - @Override - public boolean isVerifyEmail() { - return false; - } - - @Override - public void setVerifyEmail(boolean verifyEmail) { - - } - - @Override - public boolean isLoginWithEmailAllowed() { - return false; - } - - @Override - public void setLoginWithEmailAllowed(boolean loginWithEmailAllowed) { - - } - - @Override - public boolean isDuplicateEmailsAllowed() { - return false; - } - - @Override - public void setDuplicateEmailsAllowed(boolean duplicateEmailsAllowed) { - - } - - @Override - public boolean isResetPasswordAllowed() { - return false; - } - - @Override - public void setResetPasswordAllowed(boolean resetPasswordAllowed) { - - } - - @Override - public String getDefaultSignatureAlgorithm() { - return null; - } - - @Override - public void setDefaultSignatureAlgorithm(String defaultSignatureAlgorithm) { - - } - - @Override - public boolean isRevokeRefreshToken() { - return false; - } - - @Override - public void setRevokeRefreshToken(boolean revokeRefreshToken) { - - } - - @Override - public int getRefreshTokenMaxReuse() { - return 0; - } - - @Override - public void setRefreshTokenMaxReuse(int revokeRefreshTokenCount) { - - } - - @Override - public int getSsoSessionIdleTimeout() { - return 0; - } - - @Override - public void setSsoSessionIdleTimeout(int seconds) { - - } - - @Override - public int getSsoSessionMaxLifespan() { - return 0; - } - - @Override - public void setSsoSessionMaxLifespan(int seconds) { - - } - - @Override - public int getSsoSessionIdleTimeoutRememberMe() { - return 0; - } - - @Override - public void setSsoSessionIdleTimeoutRememberMe(int seconds) { - - } - - @Override - public int getSsoSessionMaxLifespanRememberMe() { - return 0; - } - - @Override - public void setSsoSessionMaxLifespanRememberMe(int seconds) { - - } - - @Override - public int getOfflineSessionIdleTimeout() { - return 0; - } - - @Override - public void setOfflineSessionIdleTimeout(int seconds) { - - } - - @Override - public int getAccessTokenLifespan() { - return 0; - } - - @Override - public boolean isOfflineSessionMaxLifespanEnabled() { - return false; - } - - @Override - public void setOfflineSessionMaxLifespanEnabled(boolean offlineSessionMaxLifespanEnabled) { - - } - - @Override - public int getOfflineSessionMaxLifespan() { - return 0; - } - - @Override - public void setOfflineSessionMaxLifespan(int seconds) { - - } - - @Override - public void setAccessTokenLifespan(int seconds) { - - } - - @Override - public int getAccessTokenLifespanForImplicitFlow() { - return 0; - } - - @Override - public void setAccessTokenLifespanForImplicitFlow(int seconds) { - - } - - @Override - public int getAccessCodeLifespan() { - return 0; - } - - @Override - public void setAccessCodeLifespan(int seconds) { - - } - - @Override - public int getAccessCodeLifespanUserAction() { - return 0; - } - - @Override - public void setAccessCodeLifespanUserAction(int seconds) { - - } - - @Override - public Map getUserActionTokenLifespans() { - return null; - } - - @Override - public int getAccessCodeLifespanLogin() { - return 0; - } - - @Override - public void setAccessCodeLifespanLogin(int seconds) { - - } - - @Override - public int getActionTokenGeneratedByAdminLifespan() { - return 0; - } - - @Override - public void setActionTokenGeneratedByAdminLifespan(int seconds) { - - } - - @Override - public int getActionTokenGeneratedByUserLifespan() { - return 0; - } - - @Override - public void setActionTokenGeneratedByUserLifespan(int seconds) { - - } - - @Override - public int getActionTokenGeneratedByUserLifespan(String actionTokenType) { - return 0; - } - - @Override - public void setActionTokenGeneratedByUserLifespan(String actionTokenType, Integer seconds) { - - } - - @Override - public List getRequiredCredentials() { - return null; - } - - @Override - public void addRequiredCredential(String cred) { - - } - - @Override - public PasswordPolicy getPasswordPolicy() { - return null; - } - - @Override - public void setPasswordPolicy(PasswordPolicy policy) { - - } - - @Override - public OTPPolicy getOTPPolicy() { - return null; - } - - @Override - public void setOTPPolicy(OTPPolicy policy) { - - } - - @Override - public WebAuthnPolicy getWebAuthnPolicy() { - return null; - } - - @Override - public void setWebAuthnPolicy(WebAuthnPolicy policy) { - - } - - @Override - public RoleModel getRoleById(String id) { - return null; - } - - @Override - public List getDefaultGroups() { - return null; - } - - @Override - public void addDefaultGroup(GroupModel group) { - - } - - @Override - public void removeDefaultGroup(GroupModel group) { - - } - - @Override - public List getClients() { - return null; - } - - @Override - public ClientModel addClient(String name) { - return null; - } - - @Override - public ClientModel addClient(String id, String clientId) { - return null; - } - - @Override - public boolean removeClient(String id) { - return false; - } - - @Override - public ClientModel getClientById(String id) { - return null; - } - - @Override - public ClientModel getClientByClientId(String clientId) { - return null; - } - - @Override - public void updateRequiredCredentials(Set creds) { - - } - - @Override - public Map getBrowserSecurityHeaders() { - return null; - } - - @Override - public void setBrowserSecurityHeaders(Map headers) { - - } - - @Override - public Map getSmtpConfig() { - return null; - } - - @Override - public void setSmtpConfig(Map smtpConfig) { - - } - - @Override - public AuthenticationFlowModel getBrowserFlow() { - return null; - } - - @Override - public void setBrowserFlow(AuthenticationFlowModel flow) { - - } - - @Override - public AuthenticationFlowModel getRegistrationFlow() { - return null; - } - - @Override - public void setRegistrationFlow(AuthenticationFlowModel flow) { - - } - - @Override - public AuthenticationFlowModel getDirectGrantFlow() { - return null; - } - - @Override - public void setDirectGrantFlow(AuthenticationFlowModel flow) { - - } - - @Override - public AuthenticationFlowModel getResetCredentialsFlow() { - return null; - } - - @Override - public void setResetCredentialsFlow(AuthenticationFlowModel flow) { - - } - - @Override - public AuthenticationFlowModel getClientAuthenticationFlow() { - return null; - } - - @Override - public void setClientAuthenticationFlow(AuthenticationFlowModel flow) { - - } - - @Override - public AuthenticationFlowModel getDockerAuthenticationFlow() { - return null; - } - - @Override - public void setDockerAuthenticationFlow(AuthenticationFlowModel flow) { - - } - - @Override - public List getAuthenticationFlows() { - return null; - } - - @Override - public AuthenticationFlowModel getFlowByAlias(String alias) { - return null; - } - - @Override - public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) { - return null; - } - - @Override - public AuthenticationFlowModel getAuthenticationFlowById(String id) { - return null; - } - - @Override - public void removeAuthenticationFlow(AuthenticationFlowModel model) { - - } - - @Override - public void updateAuthenticationFlow(AuthenticationFlowModel model) { - - } - - @Override - public List getAuthenticationExecutions(String flowId) { - return null; - } - - @Override - public AuthenticationExecutionModel getAuthenticationExecutionById(String id) { - return null; - } - - @Override - public AuthenticationExecutionModel addAuthenticatorExecution(AuthenticationExecutionModel model) { - return null; - } - - @Override - public void updateAuthenticatorExecution(AuthenticationExecutionModel model) { - - } - - @Override - public void removeAuthenticatorExecution(AuthenticationExecutionModel model) { - - } - - @Override - public List getAuthenticatorConfigs() { - return null; - } - - @Override - public AuthenticatorConfigModel addAuthenticatorConfig(AuthenticatorConfigModel model) { - return null; - } - - @Override - public void updateAuthenticatorConfig(AuthenticatorConfigModel model) { - - } - - @Override - public void removeAuthenticatorConfig(AuthenticatorConfigModel model) { - - } - - @Override - public AuthenticatorConfigModel getAuthenticatorConfigById(String id) { - return null; - } - - @Override - public AuthenticatorConfigModel getAuthenticatorConfigByAlias(String alias) { - return null; - } - - @Override - public List getRequiredActionProviders() { - return null; - } - - @Override - public RequiredActionProviderModel addRequiredActionProvider(RequiredActionProviderModel model) { - return null; - } - - @Override - public void updateRequiredActionProvider(RequiredActionProviderModel model) { - - } - - @Override - public void removeRequiredActionProvider(RequiredActionProviderModel model) { - - } - - @Override - public RequiredActionProviderModel getRequiredActionProviderById(String id) { - return null; - } - - @Override - public RequiredActionProviderModel getRequiredActionProviderByAlias(String alias) { - return null; - } - - @Override - public List getIdentityProviders() { - return null; - } - - @Override - public IdentityProviderModel getIdentityProviderByAlias(String alias) { - return null; - } - - @Override - public void addIdentityProvider(IdentityProviderModel identityProvider) { - - } - - @Override - public void removeIdentityProviderByAlias(String alias) { - - } - - @Override - public void updateIdentityProvider(IdentityProviderModel identityProvider) { - - } - - @Override - public Set getIdentityProviderMappers() { - return null; - } - - @Override - public Set getIdentityProviderMappersByAlias(String brokerAlias) { - return null; - } - - @Override - public IdentityProviderMapperModel addIdentityProviderMapper(IdentityProviderMapperModel model) { - return null; - } - - @Override - public void removeIdentityProviderMapper(IdentityProviderMapperModel mapping) { - - } - - @Override - public void updateIdentityProviderMapper(IdentityProviderMapperModel mapping) { - - } - - @Override - public IdentityProviderMapperModel getIdentityProviderMapperById(String id) { - return null; - } - - @Override - public IdentityProviderMapperModel getIdentityProviderMapperByName(String brokerAlias, String name) { - return null; - } - - @Override - public ComponentModel addComponentModel(ComponentModel model) { - return null; - } - - @Override - public ComponentModel importComponentModel(ComponentModel model) { - return null; - } - - @Override - public void updateComponent(ComponentModel component) { - - } - - @Override - public void removeComponent(ComponentModel component) { - - } - - @Override - public void removeComponents(String parentId) { - - } - - @Override - public List getComponents(String parentId, String providerType) { - return null; - } - - @Override - public List getComponents(String parentId) { - return null; - } - - @Override - public List getComponents() { - return null; - } - - @Override - public ComponentModel getComponent(String id) { - return null; - } - - @Override - public String getLoginTheme() { - return null; - } - - @Override - public void setLoginTheme(String name) { - - } - - @Override - public String getAccountTheme() { - return null; - } - - @Override - public void setAccountTheme(String name) { - - } - - @Override - public String getAdminTheme() { - return null; - } - - @Override - public void setAdminTheme(String name) { - - } - - @Override - public String getEmailTheme() { - return null; - } - - @Override - public void setEmailTheme(String name) { - - } - - @Override - public int getNotBefore() { - return 0; - } - - @Override - public void setNotBefore(int notBefore) { - - } - - @Override - public boolean isEventsEnabled() { - return false; - } - - @Override - public void setEventsEnabled(boolean enabled) { - - } - - @Override - public long getEventsExpiration() { - return 0; - } - - @Override - public void setEventsExpiration(long expiration) { - - } - - @Override - public Set getEventsListeners() { - return null; - } - - @Override - public void setEventsListeners(Set listeners) { - - } - - @Override - public Set getEnabledEventTypes() { - return null; - } - - @Override - public void setEnabledEventTypes(Set enabledEventTypes) { - - } - - @Override - public boolean isAdminEventsEnabled() { - return false; - } - - @Override - public void setAdminEventsEnabled(boolean enabled) { - - } - - @Override - public boolean isAdminEventsDetailsEnabled() { - return false; - } - - @Override - public void setAdminEventsDetailsEnabled(boolean enabled) { - - } - - @Override - public ClientModel getMasterAdminClient() { - return null; - } - - @Override - public void setMasterAdminClient(ClientModel client) { - - } - - @Override - public boolean isIdentityFederationEnabled() { - return false; - } - - @Override - public boolean isInternationalizationEnabled() { - return false; - } - - @Override - public void setInternationalizationEnabled(boolean enabled) { - - } - - @Override - public Set getSupportedLocales() { - return null; - } - - @Override - public void setSupportedLocales(Set locales) { - - } - - @Override - public String getDefaultLocale() { - return null; - } - - @Override - public void setDefaultLocale(String locale) { - - } - - @Override - public GroupModel createGroup(String name) { - return null; - } - - @Override - public GroupModel createGroup(String id, String name) { - return null; - } - - @Override - public GroupModel getGroupById(String id) { - return null; - } - - @Override - public List getGroups() { - return null; - } - - @Override - public Long getGroupsCount(Boolean onlyTopGroups) { - return null; - } - - @Override - public Long getGroupsCountByNameContaining(String search) { - return null; - } - - @Override - public List getTopLevelGroups() { - return null; - } - - @Override - public List getTopLevelGroups(Integer first, Integer max) { - return null; - } - - @Override - public List searchForGroupByName(String search, Integer first, Integer max) { - return null; - } - - @Override - public boolean removeGroup(GroupModel group) { - return false; - } - - @Override - public void moveGroup(GroupModel group, GroupModel toParent) { - - } - - @Override - public List getClientScopes() { - return null; - } - - @Override - public ClientScopeModel addClientScope(String name) { - return null; - } - - @Override - public ClientScopeModel addClientScope(String id, String name) { - return null; - } - - @Override - public boolean removeClientScope(String id) { - return false; - } - - @Override - public ClientScopeModel getClientScopeById(String id) { - return null; - } - - @Override - public void addDefaultClientScope(ClientScopeModel clientScope, boolean defaultScope) { - - } - - @Override - public void removeDefaultClientScope(ClientScopeModel clientScope) { - - } - - @Override - public List getDefaultClientScopes(boolean defaultScope) { - return null; - } - } - /** * A whitebox implementation of the config. Please use only for testing {@link FilesPlainTextVaultProviderFactory}. */