From 25e8e9b85fa95a83634f12fd93a319df6d026718 Mon Sep 17 00:00:00 2001 From: Ian Duffy Date: Fri, 2 Aug 2013 09:28:48 +0100 Subject: [PATCH] General cleanup, source formatting, remove whitespace Signed-off-by: Abhinandan Prateek --- .../api/command/LdapCreateAccount.java | 16 +- .../api/command/LdapListAllUsersCmd.java | 3 +- .../api/command/LdapListConfigurationCmd.java | 2 +- .../api/command/LdapUserSearchCmd.java | 3 +- .../cloudstack/ldap/LdapAuthenticator.java | 9 +- .../cloudstack/ldap/LdapConfiguration.java | 8 +- .../cloudstack/ldap/LdapConfigurationVO.java | 2 +- .../cloudstack/ldap/LdapContextFactory.java | 41 +- .../apache/cloudstack/ldap/LdapManager.java | 2 + .../cloudstack/ldap/LdapUserManager.java | 47 +- .../org/apache/cloudstack/ldap/LdapUtils.java | 2 +- .../ldap/BasicNamingEnumerationImpl.groovy | 32 +- .../ldap/LdapAddConfigurationCmdSpec.groovy | 93 ++-- .../ldap/LdapAuthenticatorSpec.groovy | 101 ++-- .../ldap/LdapConfigurationDaoImplSpec.groovy | 5 +- .../ldap/LdapConfigurationResponseSpec.groovy | 35 +- .../ldap/LdapConfigurationSpec.groovy | 226 ++++---- .../ldap/LdapConfigurationVOSpec.groovy | 23 +- .../ldap/LdapContextFactorySpec.groovy | 108 ++-- .../ldap/LdapCreateAccountCmdSpec.groovy | 192 +++---- .../LdapDeleteConfigurationCmdSpec.groovy | 51 +- .../ldap/LdapListAllUsersCmdSpec.groovy | 62 +-- .../ldap/LdapListConfigurationCmdSpec.groovy | 117 ++--- .../ldap/LdapManagerImplSpec.groovy | 490 +++++++++--------- .../ldap/LdapSearchUserCmdSpec.groovy | 28 +- .../ldap/LdapUserManagerSpec.groovy | 198 ++++--- .../ldap/LdapUserResponseSpec.groovy | 61 ++- .../cloudstack/ldap/LdapUserSpec.groovy | 69 ++- .../cloudstack/ldap/LdapUtilsSpec.groovy | 36 +- ...oLdapUserMatchingQueryExceptionSpec.groovy | 1 - .../ldap/NoSuchLdapUserExceptionSpec.groovy | 1 - .../src/com/cloud/configuration/Config.java | 13 +- setup/db/db/schema-410to420.sql | 83 ++- ui/dictionary.jsp | 2 +- ui/scripts/autoscaler.js | 2 +- ui/scripts/sharedFunctions.js | 2 +- ui/scripts/system.js | 64 +-- ui/scripts/ui-custom/accountsWizard.js | 2 +- ui/scripts/ui-custom/installWizard.js | 7 +- ui/scripts/ui/dialog.js | 56 +- ui/scripts/ui/widgets/listView.js | 10 +- ui/scripts/ui/widgets/multiEdit.js | 4 +- ui/scripts/zoneWizard.js | 69 +-- 43 files changed, 1183 insertions(+), 1195 deletions(-) diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java index 47e5bf41ce2..87944b0942a 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccount.java @@ -92,15 +92,15 @@ public class LdapCreateAccount extends BaseCmd { public void execute() throws ServerApiException { updateCallContext(); try { - LdapUser user = _ldapManager.getUser(username); + final LdapUser user = _ldapManager.getUser(username); validateUser(user); - UserAccount userAccount = _accountService.createUserAccount( + final UserAccount userAccount = _accountService.createUserAccount( username, generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, accountName, accountType, domainId, networkDomain, details, accountUUID, userUUID); if (userAccount != null) { - AccountResponse response = _responseGenerator + final AccountResponse response = _responseGenerator .createUserAccountResponse(userAccount); response.setResponseName(getCommandName()); setResponseObject(response); @@ -108,7 +108,7 @@ public class LdapCreateAccount extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account"); } - } catch (NamingException e) { + } catch (final NamingException e) { throw new ServerApiException( ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, "No LDAP user exists with the username of " + username); @@ -117,11 +117,11 @@ public class LdapCreateAccount extends BaseCmd { private String generatePassword() throws ServerApiException { try { - SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG"); - byte bytes[] = new byte[20]; + final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG"); + final byte bytes[] = new byte[20]; randomGen.nextBytes(bytes); return Base64.encode(bytes).toString(); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password"); } @@ -142,7 +142,7 @@ public class LdapCreateAccount extends BaseCmd { "Account Name: " + accountName + ", Domain Id:" + domainId); } - private boolean validateUser(LdapUser user) throws ServerApiException { + private boolean validateUser(final LdapUser user) throws ServerApiException { if (user.getEmail() == null) { throw new ServerApiException( ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, username diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java index c5cecc7e3fa..c371cffb6e6 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListAllUsersCmd.java @@ -51,7 +51,8 @@ public class LdapListAllUsersCmd extends BaseListCmd { _ldapManager = ldapManager; } - private List createLdapUserResponse(List users) { + private List createLdapUserResponse( + final List users) { final List ldapResponses = new ArrayList(); for (final LdapUser user : users) { final LdapUserResponse ldapResponse = _ldapManager diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java index 7abfefea6d0..3d9323da6f9 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java @@ -59,7 +59,7 @@ public class LdapListConfigurationCmd extends BaseListCmd { } private List createLdapConfigurationResponses( - List configurations) { + final List configurations) { final List responses = new ArrayList(); for (final LdapConfigurationVO resource : configurations) { final LdapConfigurationResponse configurationResponse = _ldapManager diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java index 735988299be..e72371c113e 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapUserSearchCmd.java @@ -54,7 +54,8 @@ public class LdapUserSearchCmd extends BaseListCmd { _ldapManager = ldapManager; } - private List createLdapUserResponse(List users) { + private List createLdapUserResponse( + final List users) { final List ldapUserResponses = new ArrayList(); if (users != null) { for (final LdapUser user : users) { diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java index fdea9b6c594..559a9794b2d 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapAuthenticator.java @@ -20,7 +20,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.cloudstack.api.command.LdapListConfigurationCmd; import org.apache.log4j.Logger; import com.cloud.server.auth.DefaultUserAuthenticator; @@ -58,7 +57,7 @@ public class LdapAuthenticator extends DefaultUserAuthenticator { s_logger.debug("Unable to find user with " + username + " in domain " + domainId); return false; - } else if (isLdapConfigurationPresent()) { + } else if (_ldapManager.isLdapEnabled()) { return _ldapManager.canAuthenticate(username, password); } else { return false; @@ -69,10 +68,4 @@ public class LdapAuthenticator extends DefaultUserAuthenticator { public String encode(final String password) { return password; } - - private boolean isLdapConfigurationPresent() { - return _ldapManager.listConfigurations( - new LdapListConfigurationCmd(_ldapManager)).second() > 0; - } - } diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java index c0b4a3253d8..5e56c21bfb0 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfiguration.java @@ -118,12 +118,8 @@ public class LdapConfiguration { public boolean getSSLStatus() { boolean sslStatus = false; - String dbValueForSSLStatus = _configDao.getValue("ldap.ssl.enabled"); - if (dbValueForSSLStatus != null) { - sslStatus = dbValueForSSLStatus == "false" ? false : true; - } - if (getTrustStore() == null || getTrustStorePassword() == null) { - sslStatus = false; + if (getTrustStore() != null && getTrustStorePassword() != null) { + sslStatus = true; } return sslStatus; } diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java index 0b548f32ccd..98e42f8af40 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapConfigurationVO.java @@ -60,7 +60,7 @@ public class LdapConfigurationVO implements InternalIdentity { return port; } - public void setId(long id) { + public void setId(final long id) { this.id = id; } } \ No newline at end of file diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java index c971b70c352..ceeed6862fb 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapContextFactory.java @@ -71,14 +71,25 @@ public class LdapContextFactory { return createInitialDirContext(principal, password, false); } + private void enableSSL(final Hashtable environment) { + final boolean sslStatus = _ldapConfiguration.getSSLStatus(); + + if (sslStatus) { + s_logger.info("LDAP SSL enabled."); + environment.put(Context.SECURITY_PROTOCOL, "ssl"); + System.setProperty("javax.net.ssl.trustStore", + _ldapConfiguration.getTrustStore()); + System.setProperty("javax.net.ssl.trustStorePassword", + _ldapConfiguration.getTrustStorePassword()); + } + } + private Hashtable getEnvironment(final String principal, final String password, final String providerUrl, final boolean isSystemContext) { final String factory = _ldapConfiguration.getFactory(); final String url = providerUrl == null ? _ldapConfiguration .getProviderUrl() : providerUrl; - final String authentication = _ldapConfiguration.getAuthentication(); - final boolean sslStatus = _ldapConfiguration.getSSLStatus(); final Hashtable environment = new Hashtable(); @@ -87,19 +98,8 @@ public class LdapContextFactory { environment.put("com.sun.jndi.ldap.read.timeout", "500"); environment.put("com.sun.jndi.ldap.connect.pool", "true"); - if (sslStatus) { - environment.put(Context.SECURITY_PROTOCOL, "ssl"); - System.setProperty("javax.net.ssl.trustStore", - _ldapConfiguration.getTrustStore()); - System.setProperty("javax.net.ssl.trustStorePassword", - _ldapConfiguration.getTrustStorePassword()); - } - - if ("none".equals(authentication) && !isSystemContext) { - environment.put(Context.SECURITY_AUTHENTICATION, "simple"); - } else { - environment.put(Context.SECURITY_AUTHENTICATION, authentication); - } + enableSSL(environment); + setAuthentication(environment, isSystemContext); if (principal != null) { environment.put(Context.SECURITY_PRINCIPAL, principal); @@ -112,6 +112,17 @@ public class LdapContextFactory { return environment; } + private void setAuthentication(final Hashtable environment, + final boolean isSystemContext) { + final String authentication = _ldapConfiguration.getAuthentication(); + + if ("none".equals(authentication) && !isSystemContext) { + environment.put(Context.SECURITY_AUTHENTICATION, "simple"); + } else { + environment.put(Context.SECURITY_AUTHENTICATION, authentication); + } + } + public void testConnection(final String providerUrl) throws NamingException { try { createBindContext(providerUrl); diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java index eb4332dc2e7..683822d31f4 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java @@ -47,6 +47,8 @@ public interface LdapManager extends PluggableService { List getUsers() throws NoLdapUserMatchingQueryException; + boolean isLdapEnabled(); + Pair, Integer> listConfigurations( LdapListConfigurationCmd cmd); diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java index f522503f5ba..7494346856a 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUserManager.java @@ -58,6 +58,36 @@ public class LdapUserManager { return new LdapUser(username, email, firstname, lastname, principal); } + private String generateSearchFilter(final String username) { + final StringBuilder userObjectFilter = new StringBuilder(); + userObjectFilter.append("(objectClass="); + userObjectFilter.append(_ldapConfiguration.getUserObject()); + userObjectFilter.append(")"); + + final StringBuilder usernameFilter = new StringBuilder(); + usernameFilter.append("("); + usernameFilter.append(_ldapConfiguration.getUsernameAttribute()); + usernameFilter.append("="); + usernameFilter.append((username == null ? "*" : username)); + usernameFilter.append(")"); + + final StringBuilder memberOfFilter = new StringBuilder(); + if (_ldapConfiguration.getSearchGroupPrinciple() != null) { + memberOfFilter.append("(memberof="); + memberOfFilter.append(_ldapConfiguration.getSearchGroupPrinciple()); + memberOfFilter.append(")"); + } + + final StringBuilder result = new StringBuilder(); + result.append("(&"); + result.append(userObjectFilter); + result.append(usernameFilter); + result.append(memberOfFilter); + result.append(")"); + + return result.toString(); + } + public LdapUser getUser(final String username, final DirContext context) throws NamingException { final NamingEnumeration result = searchUsers(username, @@ -104,20 +134,7 @@ public class LdapUserManager { controls.setReturningAttributes(_ldapConfiguration .getReturnAttributes()); - final String userObjectFilter = "(objectClass=" - + _ldapConfiguration.getUserObject() + ")"; - final String usernameFilter = "(" - + _ldapConfiguration.getUsernameAttribute() + "=" - + (username == null ? "*" : username) + ")"; - String memberOfFilter = ""; - if (_ldapConfiguration.getSearchGroupPrinciple() != null) { - memberOfFilter = "(memberof=" - + _ldapConfiguration.getSearchGroupPrinciple() + ")"; - } - - final String filter = "(&" + userObjectFilter + usernameFilter - + memberOfFilter + ")"; - - return context.search(_ldapConfiguration.getBaseDn(), filter, controls); + return context.search(_ldapConfiguration.getBaseDn(), + generateSearchFilter(username), controls); } } \ No newline at end of file diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java index ff8c88c0e24..e1f999b72df 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapUtils.java @@ -23,7 +23,7 @@ import javax.naming.directory.Attributes; public final class LdapUtils { public static String escapeLDAPSearchFilter(final String filter) { final StringBuilder sb = new StringBuilder(); - for (char character : filter.toCharArray()) { + for (final char character : filter.toCharArray()) { switch (character) { case '\\': sb.append("\\5c"); diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy index ab7e22ac4ec..67d52722ba1 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/BasicNamingEnumerationImpl.groovy @@ -16,24 +16,18 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import javax.naming.NamingEnumeration -import javax.naming.NamingException -import javax.naming.directory.SearchResult +import java.util.LinkedList; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.SearchResult; class BasicNamingEnumerationImpl implements NamingEnumeration { private LinkedList items = new LinkedList(); - @Override - public boolean hasMoreElements() { - return items.size != 0; - } - - @Override - public Object nextElement() { - SearchResult result = items.getFirst(); - items.removeFirst(); - return result; + public void add(SearchResult item) { + items.add(item) } @Override @@ -45,12 +39,20 @@ class BasicNamingEnumerationImpl implements NamingEnumeration { return hasMoreElements(); } + @Override + public boolean hasMoreElements() { + return items.size != 0; + } + @Override public Object next() throws NamingException { return nextElement(); } - public void add(SearchResult item) { - items.add(item) + @Override + public Object nextElement() { + SearchResult result = items.getFirst(); + items.removeFirst(); + return result; } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy index 3dcb23f0328..18df10dbfa4 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAddConfigurationCmdSpec.groovy @@ -16,74 +16,69 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import com.cloud.exception.InvalidParameterValueException -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.api.command.LdapAddConfigurationCmd -import org.apache.cloudstack.api.response.LdapConfigurationResponse -import org.apache.cloudstack.ldap.LdapManager class LdapAddConfigurationCmdSpec extends spock.lang.Specification { - def "Test successful response from execute"() { - given: - def ldapManager = Mock(LdapManager) - ldapManager.addConfiguration(_, _) >> new LdapConfigurationResponse("localhost", 389) - def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) - when: - ldapAddConfigurationCmd.execute() - then: - ldapAddConfigurationCmd.responseObject.hostname == "localhost" - ldapAddConfigurationCmd.responseObject.port == 389 + def "Test failed response from execute"() { + given: "We have an LDAP manager, no configuration and a LdapAddConfigurationCmd" + def ldapManager = Mock(LdapManager) + ldapManager.addConfiguration(_, _) >> { throw new InvalidParameterValueException() } + def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) + when: "LdapAddCofnigurationCmd is executed" + ldapAddConfigurationCmd.execute() + then: "an exception is thrown" + thrown ServerApiException } - def "Test failed response from execute"() { - given: - def ldapManager = Mock(LdapManager) - ldapManager.addConfiguration(_, _) >> { throw new InvalidParameterValueException() } + def "Test getEntityOwnerId is 1"() { + given: "We have an LdapManager and LdapConfigurationCmd" + def ldapManager = Mock(LdapManager) + def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) + when: "Get Entity Owner Id is called" + long ownerId = ldapAddConfigurationCmd.getEntityOwnerId() + then: "1 is returned" + ownerId == 1 + } + + def "Test successful response from execute"() { + given: "We have an LDAP Manager that has a configuration and a LdapAddConfigurationCmd" + def ldapManager = Mock(LdapManager) + ldapManager.addConfiguration(_, _) >> new LdapConfigurationResponse("localhost", 389) def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) - when: + when: "LdapAddConfigurationCmd is executed" ldapAddConfigurationCmd.execute() - then: - thrown ServerApiException + then: "the responseObject should have the hostname localhost and port 389" + ldapAddConfigurationCmd.responseObject.hostname == "localhost" + ldapAddConfigurationCmd.responseObject.port == 389 + } + + def "Test successful return of getCommandName"() { + given: "We have an LdapManager and LdapConfigurationCmd" + def ldapManager = Mock(LdapManager) + def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) + when: "Get Command Name is called" + String commandName = ldapAddConfigurationCmd.getCommandName() + then: "ldapconfigurationresponse is returned" + commandName == "ldapconfigurationresponse" } def "Test successful setting of hostname"() { - given: + given: "We have an LdapManager and LdapAddConfigurationCmd" def ldapManager = Mock(LdapManager) def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) - when: + when: "The hostname is set" ldapAddConfigurationCmd.setHostname("localhost") - then: + then: "Get hostname returns the set hostname" ldapAddConfigurationCmd.getHostname() == "localhost" } def "Test successful setting of port"() { - given: + given: "We have an LdapManager and LdapAddConfigurationCmd" def ldapManager = Mock(LdapManager) def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) - when: + when: "The port is set" ldapAddConfigurationCmd.setPort(389) - then: - ldapAddConfigurationCmd.getPort() == 389 - } - - def "Test getEntityOwnerId is 0"() { - given: - def ldapManager = Mock(LdapManager) - def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) - when: - long ownerId = ldapAddConfigurationCmd.getEntityOwnerId() - then: - ownerId == 1 - } - - def "Test successful return of getCommandName"() { - given: - def ldapManager = Mock(LdapManager) - def ldapAddConfigurationCmd = new LdapAddConfigurationCmd(ldapManager) - when: - String commandName = ldapAddConfigurationCmd.getCommandName() - then: - commandName == "ldapconfigurationresponse" + then: "Get port returns the port" + ldapAddConfigurationCmd.getPort() == 389 } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy index 573f88cd1b4..a055fbc080b 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy @@ -16,75 +16,78 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import com.cloud.user.UserAccountVO -import com.cloud.user.dao.UserAccountDao -import com.cloud.utils.Pair -import org.apache.cloudstack.ldap.LdapAuthenticator -import org.apache.cloudstack.ldap.LdapConfigurationVO -import org.apache.cloudstack.ldap.LdapManager class LdapAuthenticatorSpec extends spock.lang.Specification { def "Test a failed authentication due to user not being found within cloudstack"() { - given: + given: "We have an LdapManager, userAccountDao and ldapAuthenticator and the user doesn't exist within cloudstack." LdapManager ldapManager = Mock(LdapManager) UserAccountDao userAccountDao = Mock(UserAccountDao) userAccountDao.getUserAccount(_, _) >> null def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) - when: + when: "A user authentications" def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - then: - result == false - } - - def "Test failed authentication due to ldap not being configured"() { - given: - def ldapManager = Mock(LdapManager) - List ldapConfigurationList = new ArrayList() - Pair, Integer> ldapConfigurations = new Pair, Integer>(); - ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size()) - ldapManager.listConfigurations(_) >> ldapConfigurations - - UserAccountDao userAccountDao = Mock(UserAccountDao) - userAccountDao.getUserAccount(_, _) >> new UserAccountVO() - - def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) - when: - def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - then: - result == false + then: "their authentication fails" + result == false } def "Test failed authentication due to ldap bind being unsuccessful"() { - given: + given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator" + def ldapManager = Mock(LdapManager) + ldapManager.isLdapEnabled() >> true + ldapManager.canAuthenticate(_, _) >> false - def ldapManager = Mock(LdapManager) - List ldapConfigurationList = new ArrayList() - ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389)) - Pair, Integer> ldapConfigurations = new Pair, Integer>(); - ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size()) - ldapManager.listConfigurations(_) >> ldapConfigurations - ldapManager.canAuthenticate(_, _) >> false + UserAccountDao userAccountDao = Mock(UserAccountDao) + userAccountDao.getUserAccount(_, _) >> new UserAccountVO() + def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) - UserAccountDao userAccountDao = Mock(UserAccountDao) - userAccountDao.getUserAccount(_, _) >> new UserAccountVO() - def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) + when: "The user authenticates with an incorrect password" + def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - when: - def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - - then: - result == false + then: "their authentication fails" + result == false } + def "Test failed authentication due to ldap not being configured"() { + given: "We have an LdapManager, A configured LDAP server, a userAccountDao and LdapAuthenticator" + def ldapManager = Mock(LdapManager) + ldapManager.isLdapEnabled() >> false + + UserAccountDao userAccountDao = Mock(UserAccountDao) + userAccountDao.getUserAccount(_, _) >> new UserAccountVO() + + def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) + when: "The user authenticates" + def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) + then: "their authentication fails" + result == false + } + + def "Test successful authentication"() { + given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator" + def ldapManager = Mock(LdapManager) + ldapManager.isLdapEnabled() >> true + ldapManager.canAuthenticate(_, _) >> true + + UserAccountDao userAccountDao = Mock(UserAccountDao) + userAccountDao.getUserAccount(_, _) >> new UserAccountVO() + def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) + + when: "The user authenticates with an incorrect password" + def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) + + then: "their authentication passes" + result == true + } + def "Test that encode doesn't change the input"() { - given: - LdapManager ldapManager = Mock(LdapManager) + given: "We have an LdapManager, userAccountDao and LdapAuthenticator" + LdapManager ldapManager = Mock(LdapManager) UserAccountDao userAccountDao = Mock(UserAccountDao) def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) - when: + when: "a users password is encoded" def result = ldapAuthenticator.encode("password") - then: + then: "it doesn't change" result == "password" } -} \ No newline at end of file +} diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy index 191b6098214..02de0f59f33 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationDaoImplSpec.groovy @@ -16,13 +16,12 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.dao.LdapConfigurationDaoImpl class LdapConfigurationDaoImplSpec extends spock.lang.Specification { def "Test setting up of a LdapConfigurationDao"() { - given: + given: "We have an LdapConfigurationDao implementation" def ldapConfigurationDaoImpl = new LdapConfigurationDaoImpl(); - expect: + expect: "that hostnameSearch and listAllConfigurationsSearch is configured" ldapConfigurationDaoImpl.hostnameSearch != null; ldapConfigurationDaoImpl.listAllConfigurationsSearch != null } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy index 4e6bebb488f..cc9de9b3e5f 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationResponseSpec.groovy @@ -16,34 +16,33 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.api.response.LdapConfigurationResponse class LdapConfigurationResponseSpec extends spock.lang.Specification { def "Testing succcessful setting of LdapConfigurationResponse hostname"() { - given: + given: "We have a LdapConfigurationResponse" LdapConfigurationResponse response = new LdapConfigurationResponse(); - when: + when: "The hostname is set" response.setHostname("localhost"); - then: - response.getHostname() == "localhost"; - } - - def "Testing successful setting of LdapConfigurationResponse port"() { - given: - LdapConfigurationResponse response = new LdapConfigurationResponse() - when: - response.setPort(389) - then: - response.getPort() == 389 + then: "Get hostname should return the set value" + response.getHostname() == "localhost"; } def "Testing successful setting of LdapConfigurationResponse hostname and port via constructor"() { - given: - LdapConfigurationResponse response - when: + given: "We have a LdapConfiguration response" + LdapConfigurationResponse response + when: "both hostname and port are set by constructor" response = new LdapConfigurationResponse("localhost", 389) - then: + then: "Get hostname and port should return the set values." response.getHostname() == "localhost" response.getPort() == 389 } + + def "Testing successful setting of LdapConfigurationResponse port"() { + given: "We have a LdapConfigurationResponse" + LdapConfigurationResponse response = new LdapConfigurationResponse() + when: "The port is set" + response.setPort(389) + then: "Get port should return the set value" + response.getPort() == 389 + } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy index a867fd6706e..c8555a9b95b 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationSpec.groovy @@ -16,166 +16,200 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import com.cloud.configuration.dao.ConfigurationDao -import com.cloud.utils.Pair -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.ldap.LdapConfiguration -import org.apache.cloudstack.ldap.LdapConfigurationVO -import org.apache.cloudstack.ldap.LdapManager - -import javax.naming.directory.SearchControls class LdapConfigurationSpec extends spock.lang.Specification { - def "Test that providerUrl successfully returns a URL when a configuration is available"() { - given: - def configDao = Mock(ConfigurationDao) + def "Test that get search group principle returns successfully"() { + given: "We have a ConfigDao with a value for ldap.search.group.principle and an LdapConfiguration" + def configDao = Mock(ConfigurationDao) + configDao.getValue("ldap.search.group.principle") >> "cn=cloudstack,cn=users,dc=cloudstack,dc=org" + def ldapManager = Mock(LdapManager) + LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - def ldapManager = Mock(LdapManager) - List ldapConfigurationList = new ArrayList() - ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389)) - Pair, Integer> result = new Pair, Integer>(); - result.set(ldapConfigurationList, ldapConfigurationList.size()) - ldapManager.listConfigurations(_) >> result + when: "A request is made to get the search group principle" + String result = ldapConfiguration.getSearchGroupPrinciple(); - LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + then: "The result holds the same value configDao did" + result == "cn=cloudstack,cn=users,dc=cloudstack,dc=org" + } - when: - String providerUrl = ldapConfiguration.getProviderUrl() - - then: - providerUrl == "ldap://localhost:389" + def "Test that getAuthentication returns none"() { + given: "We have a ConfigDao, LdapManager and LdapConfiguration" + def configDao = Mock(ConfigurationDao) + def ldapManager = Mock(LdapManager) + def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + when: "Get authentication is called" + String authentication = ldapConfiguration.getAuthentication() + then: "none should be returned" + authentication == "none" } def "Test that getAuthentication returns simple"() { - given: + given: "We have a configDao, LdapManager and LdapConfiguration with bind principle and password set" def configDao = Mock(ConfigurationDao) def ldapManager = Mock(LdapManager) def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) configDao.getValue("ldap.bind.password") >> "password" configDao.getValue("ldap.bind.principal") >> "cn=rmurphy,dc=cloudstack,dc=org" - when: + when: "Get authentication is called" String authentication = ldapConfiguration.getAuthentication() - then: - authentication == "simple" + then: "authentication should be set to simple" + authentication == "simple" } - def "Test that getAuthentication returns none"() { - given: - def configDao = Mock(ConfigurationDao) - def ldapManager = Mock(LdapManager) - def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: - String authentication = ldapConfiguration.getAuthentication() - then: - authentication == "none" + def "Test that getBaseDn returns dc=cloudstack,dc=org"() { + given: "We have a ConfigDao, LdapManager and ldapConfiguration with a baseDn value set." + def configDao = Mock(ConfigurationDao) + configDao.getValue("ldap.basedn") >> "dc=cloudstack,dc=org" + def ldapManager = Mock(LdapManager) + def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + when: "Get basedn is called" + String baseDn = ldapConfiguration.getBaseDn(); + then: "The set baseDn should be returned" + baseDn == "dc=cloudstack,dc=org" } def "Test that getEmailAttribute returns mail"() { - given: + given: "Given that we have a ConfigDao, LdapManager and LdapConfiguration" def configDao = Mock(ConfigurationDao) configDao.getValue("ldap.email.attribute") >> "mail" def ldapManager = Mock(LdapManager) def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: + when: "Get Email Attribute is called" String emailAttribute = ldapConfiguration.getEmailAttribute() - then: - emailAttribute == "mail" + then: "mail should be returned" + emailAttribute == "mail" } - def "Test that getUsernameAttribute returns uid"() { - given: - def configDao = Mock(ConfigurationDao) - configDao.getValue("ldap.username.attribute") >> "uid" - def ldapManager = Mock(LdapManager) - def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: - String usernameAttribute = ldapConfiguration.getUsernameAttribute() - then: - usernameAttribute == "uid" + def "Test that getFactory returns com.sun.jndi.ldap.LdapCtxFactory"() { + given: "We have a ConfigDao, LdapManager and LdapConfiguration" + def configDao = Mock(ConfigurationDao) + def ldapManager = Mock(LdapManager) + def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + when: "Get Factory is scalled" + String factory = ldapConfiguration.getFactory(); + then: "com.sun.jndi.ldap.LdapCtxFactory is returned" + factory == "com.sun.jndi.ldap.LdapCtxFactory" } def "Test that getFirstnameAttribute returns givenname"() { - given: + given: "We have a ConfigDao, LdapManager and LdapConfiguration" def configDao = Mock(ConfigurationDao) configDao.getValue("ldap.firstname.attribute") >> "givenname" def ldapManager = Mock(LdapManager) def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: + when: "Get firstname attribute is called" String firstname = ldapConfiguration.getFirstnameAttribute() - then: + then: "givennam should be returned" firstname == "givenname" } def "Test that getLastnameAttribute returns givenname"() { - given: + given: "We have a ConfigDao, LdapManager and LdapConfiguration" def configDao = Mock(ConfigurationDao) configDao.getValue("ldap.lastname.attribute") >> "sn" def ldapManager = Mock(LdapManager) def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: + when: "Get Lastname Attribute is scalled " String lastname = ldapConfiguration.getLastnameAttribute() - then: - lastname == "sn" - } - - def "Test that getUserObject returns inetOrgPerson"() { - given: - def configDao = Mock(ConfigurationDao) - configDao.getValue("ldap.user.object") >> "inetOrgPerson" - def ldapManager = Mock(LdapManager) - def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: - String userObject = ldapConfiguration.getUserObject() - then: - userObject == "inetOrgPerson" + then: "sn should be returned" + lastname == "sn" } def "Test that getReturnAttributes returns the correct data"() { - given: - def configDao = Mock(ConfigurationDao) + given: "We have a ConfigDao, LdapManager and LdapConfiguration" + def configDao = Mock(ConfigurationDao) configDao.getValue("ldap.firstname.attribute") >> "givenname" configDao.getValue("ldap.lastname.attribute") >> "sn" configDao.getValue("ldap.username.attribute") >> "uid" configDao.getValue("ldap.email.attribute") >> "mail" def ldapManager = Mock(LdapManager) def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: + when: "Get return attributes is called" String[] returnAttributes = ldapConfiguration.getReturnAttributes() - then: + then: "An array containing uid, mail, givenname and sn is returned" returnAttributes == ["uid", "mail", "givenname", "sn"] } def "Test that getScope returns SearchControls.SUBTREE_SCOPE"() { - given: + given: "We have ConfigDao, LdapManager and LdapConfiguration" def configDao = Mock(ConfigurationDao) def ldapManager = Mock(LdapManager) def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: + when: "Get scope is called" int scope = ldapConfiguration.getScope() - then: - scope == SearchControls.SUBTREE_SCOPE; + then: "SearchControls.SUBTRE_SCOPE should be returned" + scope == SearchControls.SUBTREE_SCOPE; } - def "Test that getBaseDn returns dc=cloudstack,dc=org"() { - given: - def configDao = Mock(ConfigurationDao) - configDao.getValue("ldap.basedn") >> "dc=cloudstack,dc=org" - def ldapManager = Mock(LdapManager) - def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: - String baseDn = ldapConfiguration.getBaseDn(); - then: - baseDn == "dc=cloudstack,dc=org" + def "Test that getSSLStatus can be true"() { + given: "We have a ConfigDao with values for truststore and truststore password set" + def configDao = Mock(ConfigurationDao) + configDao.getValue("ldap.truststore") >> "/tmp/ldap.ts" + configDao.getValue("ldap.truststore.password") >> "password" + def ldapManager = Mock(LdapManager) + LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + + when: "A request is made to get the status of SSL" + boolean result = ldapConfiguration.getSSLStatus(); + + then: "The response should be true" + result == true + } + + def "Test that getTrustStorePassword resopnds"() { + given: "We have a ConfigDao with a value for truststore password" + def configDao = Mock(ConfigurationDao) + configDao.getValue("ldap.truststore.password") >> "password" + def ldapManager = Mock(LdapManager) + LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + + when: "A request is made to get the truststore password" + String result = ldapConfiguration.getTrustStorePassword() + + then: "The result is password" + result == "password"; + } + + def "Test that getUsernameAttribute returns uid"() { + given: "We have ConfigDao, LdapManager and LdapConfiguration" + def configDao = Mock(ConfigurationDao) + configDao.getValue("ldap.username.attribute") >> "uid" + def ldapManager = Mock(LdapManager) + def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + when: "Get Username Attribute is called" + String usernameAttribute = ldapConfiguration.getUsernameAttribute() + then: "uid should be returned" + usernameAttribute == "uid" } - def "Test that getFactory returns com.sun.jndi.ldap.LdapCtxFactory"() { - given: - def configDao = Mock(ConfigurationDao) - def ldapManager = Mock(LdapManager) - def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) - when: - String factory = ldapConfiguration.getFactory(); - then: - factory == "com.sun.jndi.ldap.LdapCtxFactory" + def "Test that getUserObject returns inetOrgPerson"() { + given: "We have a ConfigDao, LdapManager and LdapConfiguration" + def configDao = Mock(ConfigurationDao) + configDao.getValue("ldap.user.object") >> "inetOrgPerson" + def ldapManager = Mock(LdapManager) + def ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + when: "Get user object is called" + String userObject = ldapConfiguration.getUserObject() + then: "inetOrgPerson is returned" + userObject == "inetOrgPerson" + } + + def "Test that providerUrl successfully returns a URL when a configuration is available"() { + given: "We have a ConfigDao, LdapManager, LdapConfiguration" + def configDao = Mock(ConfigurationDao) + def ldapManager = Mock(LdapManager) + List ldapConfigurationList = new ArrayList() + ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389)) + Pair, Integer> result = new Pair, Integer>(); + result.set(ldapConfigurationList, ldapConfigurationList.size()) + ldapManager.listConfigurations(_) >> result + + LdapConfiguration ldapConfiguration = new LdapConfiguration(configDao, ldapManager) + + when: "A request is made to get the providerUrl" + String providerUrl = ldapConfiguration.getProviderUrl() + + then: "The providerUrl should be given." + providerUrl == "ldap://localhost:389" } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy index 66b3f44494d..b5d007e72f7 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapConfigurationVOSpec.groovy @@ -16,21 +16,20 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.LdapConfigurationVO class LdapConfigurationVOSpec extends spock.lang.Specification { def "Testing that the ID hostname and port is correctly set within the LDAP configuration VO"() { - given: "You have created an LDAP Configuration VO" - def configuration = new LdapConfigurationVO(hostname, port) - configuration.setId(id) - expect: "The id hostname and port is equal to the given data source" - configuration.getId() == id - configuration.getHostname() == hostname - configuration.getPort() == port - where: "The id, hostname and port is set to " - hostname << ["", null, "localhost"] - id << [0, 1000, -1000] - port << [0, 1000, -1000] + given: "You have created an LDAP Configuration VO" + def configuration = new LdapConfigurationVO(hostname, port) + configuration.setId(id) + expect: "The id hostname and port is equal to the given data source" + configuration.getId() == id + configuration.getHostname() == hostname + configuration.getPort() == port + where: "The id, hostname and port is set to " + hostname << ["", null, "localhost"] + id << [0, 1000, -1000] + port << [0, 1000, -1000] } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy index e9b3b6e9fa5..9d9ea659453 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy @@ -16,13 +16,7 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.LdapConfiguration -import org.apache.cloudstack.ldap.LdapContextFactory -import spock.lang.Shared - -import javax.naming.NamingException -import javax.naming.directory.SearchControls -import javax.naming.ldap.LdapContext +import spock.lang.Shared; class LdapContextFactorySpec extends spock.lang.Specification { @Shared @@ -53,82 +47,72 @@ class LdapContextFactorySpec extends spock.lang.Specification { username = "rmurphy" principal = "cn=" + username + "," + ldapConfiguration.getBaseDn() - password = "password" + password = "password" } - def "Test successfully creating a system environment with anon bind"() { - given: - def ldapContextFactory = new LdapContextFactory(ldapConfiguration) + def "Test succcessfully creating a initial context"() { + given: "We have a LdapContextFactory" + def ldapContextFactory = new LdapContextFactory(ldapConfiguration) + when: "A context attempts to bind and no Ldap server is avaiable" + ldapContextFactory.createInitialDirContext(null, null, true) + then: "An expection is thrown" + thrown NamingException + } - when: - def result = ldapContextFactory.getEnvironment(principal, password, null, false) + def "Test successful failed connection"() { + given: "We have a LdapContextFactory" + def ldapContextFactory = Spy(LdapContextFactory, constructorArgs: [ldapConfiguration]) + when: "Test connection is executed" + ldapContextFactory.testConnection(ldapConfiguration.getProviderUrl()) + then: "An exception is thrown" + thrown NamingException + } - then: - result['java.naming.provider.url'] == ldapConfiguration.getProviderUrl() - result['java.naming.factory.initial'] == ldapConfiguration.getFactory() - result['java.naming.security.principal'] == principal - result['java.naming.security.authentication'] == "simple" - result['java.naming.security.credentials'] == password + def "Test successfully binding as a user"() { + given: "We have a LdapContextFactory" + def ldapContextFactory = new LdapContextFactory(ldapConfiguration) + when: "A user attempts to bind and no LDAP server is avaiable" + ldapContextFactory.createUserContext(principal, password) + then: "An exception is thrown" + thrown NamingException } def "Test successfully creating a environment with username and password"() { - given: + given: "We have an LdapContextFactory" def ldapContextFactory = new LdapContextFactory(ldapConfiguration) - when: + when: "A request for an environment is made" def result = ldapContextFactory.getEnvironment(null, null, null, true) - then: + then: "The resulting values should be set" result['java.naming.provider.url'] == ldapConfiguration.getProviderUrl() result['java.naming.factory.initial'] == ldapConfiguration.getFactory() result['java.naming.security.principal'] == null result['java.naming.security.authentication'] == ldapConfiguration.getAuthentication() - result['java.naming.security.credentials'] == null + result['java.naming.security.credentials'] == null } - def "Test successfully binding as a user"() { - given: - def ldapContextFactory = new LdapContextFactory(ldapConfiguration) - when: - ldapContextFactory.createUserContext(principal, password) - then: - thrown NamingException + def "Test successfully creating a system environment with anon bind"() { + given: "We have an LdapContext Factory" + def ldapContextFactory = new LdapContextFactory(ldapConfiguration) + + when: "A request for an environment is made" + def result = ldapContextFactory.getEnvironment(principal, password, null, false) + + then: "The resulting values should be set" + result['java.naming.provider.url'] == ldapConfiguration.getProviderUrl() + result['java.naming.factory.initial'] == ldapConfiguration.getFactory() + result['java.naming.security.principal'] == principal + result['java.naming.security.authentication'] == "simple" + result['java.naming.security.credentials'] == password } def "Test successully binding as system"() { - given: + given: "We have a LdapContextFactory" def ldapContextFactory = new LdapContextFactory(ldapConfiguration) - when: + when: "A bind context attempts to bind and no Ldap server is avaiable" ldapContextFactory.createBindContext() - then: - thrown NamingException - } - - def "Test succcessfully creating a initial context"() { - given: - def ldapContextFactory = new LdapContextFactory(ldapConfiguration) - when: - ldapContextFactory.createInitialDirContext(null, null, true) - then: - thrown NamingException - } - - def "Test successful failed connection"() { - given: - def ldapContextFactory = Spy(LdapContextFactory, constructorArgs: [ldapConfiguration]) - when: - ldapContextFactory.testConnection(ldapConfiguration.getProviderUrl()) - then: - thrown NamingException - } - - def "Test successful connection"() { - given: - def ldapContextFactory = Spy(LdapContextFactory, constructorArgs: [ldapConfiguration]) - ldapContextFactory.createBindContext(_) >> Mock(LdapContext) - when: - ldapContextFactory.testConnection(ldapConfiguration.getProviderUrl()) - then: - notThrown NamingException + then: "An exception is thrown" + thrown NamingException } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy index 07056b0b85b..d2b2332b2c8 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy @@ -16,20 +16,6 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import com.cloud.exception.InvalidParameterValueException -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.api.command.LdapAddConfigurationCmd -import org.apache.cloudstack.api.response.LdapConfigurationResponse - -import org.apache.cloudstack.ldap.LdapUser; -import org.apache.cloudstack.ldap.LdapManager; - -import org.apache.cloudstack.api.command.LdapCreateAccount - -import com.cloud.user.AccountService; -import com.cloud.user.UserAccountVO; - -import javax.naming.NamingException class LdapCreateAccountCmdSpec extends spock.lang.Specification { /* @@ -47,108 +33,96 @@ class LdapCreateAccountCmdSpec extends spock.lang.Specification { thrown ServerApiException } */ - def "Test validation of a user"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - - def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService]) - - when: - def commandName = ldapCreateAccount.getCommandName() - - then: - commandName == "createaccountresponse" + def "Test command name"() { + given: "We have an LdapManager, AccountService and LdapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) + when: "Get command name is called" + def result = ldapCreateAccount.getCommandName() + then: "createaccountresponse is returned" + result == "createaccountresponse" } def "Test getEntityOwnerId is 1"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) + given: "We have an LdapManager, AccountService andL dapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) - def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService]) - when: - long ownerId = ldapCreateAccount.getEntityOwnerId() - then: - ownerId == 1 - } - - def "Test validate User"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService); - when: - def result = ldapCreateAccount.validateUser(new LdapUser("username","email","firstname","lastname","principal")) - then: - result == true - } - - def "Test validate User empty email"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) - when: - ldapCreateAccount.validateUser(new LdapUser("username",null,"firstname","lastname","principal")) - then: - thrown Exception - } - - def "Test validate User empty firstname"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) - when: - ldapCreateAccount.validateUser(new LdapUser("username","email",null,"lastname","principal")) - then: - thrown Exception - } - - def "Test validate User empty lastname"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) - when: - ldapCreateAccount.validateUser(new LdapUser("username","email","firstname",null,"principal")) - then: - thrown Exception - } - - def "Test failed password generation"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) - when: - def result = ldapCreateAccount.generatePassword() - then: - result != "" - result != null + def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService]) + when: "Get entity owner id is called" + long ownerId = ldapCreateAccount.getEntityOwnerId() + then: "1 is returned" + ownerId == 1 } def "Test password generation"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) - when: - def result = ldapCreateAccount.generatePassword() - then: - result != "" - result != null - } + given: "We have an LdapManager, AccountService and LdapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) + when: "A password is generated" + def result = ldapCreateAccount.generatePassword() + then: "The result shouldn't be null or empty" + result != "" + result != null + } - def "Test command name"() { - given: - LdapManager ldapManager = Mock(LdapManager) - AccountService accountService = Mock(AccountService) - def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) - when: - def result = ldapCreateAccount.getCommandName() - then: - result == "createaccountresponse" + def "Test validate User"() { + given: "We have an LdapManager, AccountService andL dapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService); + when: "a user with an username, email, firstname and lastname is validated" + def result = ldapCreateAccount.validateUser(new LdapUser("username","email","firstname","lastname","principal")) + then: "the result is true" + result == true + } + + def "Test validate User empty email"() { + given: "We have an LdapManager, AccountService andL dapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) + when: "A user with no email address attempts to validate" + ldapCreateAccount.validateUser(new LdapUser("username",null,"firstname","lastname","principal")) + then: "An exception is thrown" + thrown Exception + } + + def "Test validate User empty firstname"() { + given: "We have an LdapManager, AccountService andL dapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) + when: "A user with no firstname attempts to validate" + ldapCreateAccount.validateUser(new LdapUser("username","email",null,"lastname","principal")) + then: "An exception is thrown" + thrown Exception + } + + def "Test validate User empty lastname"() { + given: "We have an LdapManager, AccountService and LdapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + def ldapCreateAccount = new LdapCreateAccount(ldapManager, accountService) + when: "A user with no lastname attempts to validate" + ldapCreateAccount.validateUser(new LdapUser("username","email","firstname",null,"principal")) + then: "An exception is thown" + thrown Exception + } + + def "Test validation of a user"() { + given: "We have an LdapManager, AccountService andL dapCreateAccount" + LdapManager ldapManager = Mock(LdapManager) + AccountService accountService = Mock(AccountService) + + def ldapCreateAccount = Spy(LdapCreateAccount, constructorArgs: [ldapManager, accountService]) + + when: "Get command name is called" + def commandName = ldapCreateAccount.getCommandName() + + then: "createaccountresponse is returned" + commandName == "createaccountresponse" } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy index b7026898947..a8374b0224e 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapDeleteConfigurationCmdSpec.groovy @@ -16,53 +16,48 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import com.cloud.exception.InvalidParameterValueException -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.api.command.LdapDeleteConfigurationCmd -import org.apache.cloudstack.api.response.LdapConfigurationResponse -import org.apache.cloudstack.ldap.LdapManager class LdapDeleteConfigurationCmdSpec extends spock.lang.Specification { - def "Test successful response from execute"() { - given: - def ldapManager = Mock(LdapManager) - ldapManager.deleteConfiguration(_) >> new LdapConfigurationResponse("localhost") - def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager) - when: - ldapDeleteConfigurationCmd.execute() - then: - ldapDeleteConfigurationCmd.responseObject.hostname == "localhost" - } - def "Test failed response from execute"() { - given: - def ldapManager = Mock(LdapManager) + given: "We have an LdapManager and LdapDeleteConfigurationCmd" + def ldapManager = Mock(LdapManager) ldapManager.deleteConfiguration(_) >> { throw new InvalidParameterValueException() } def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager) - when: + when:"LdapDeleteConfigurationCmd is executed and no configuration exists" ldapDeleteConfigurationCmd.execute() - then: + then: "An exception is thrown" thrown ServerApiException } def "Test getEntityOwnerId is 1"() { - given: + given: "We have an LdapManager and LdapDeleteConfigurationCmd" def ldapManager = Mock(LdapManager) def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager) - when: + when: "Get entity owner id is called" long ownerId = ldapDeleteConfigurationCmd.getEntityOwnerId() - then: - ownerId == 1 + then: "1 is returned" + ownerId == 1 + } + + def "Test successful response from execute"() { + given: "We have an LdapManager and LdapDeleteConfigurationCmd" + def ldapManager = Mock(LdapManager) + ldapManager.deleteConfiguration(_) >> new LdapConfigurationResponse("localhost") + def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager) + when: "LdapDeleteConfigurationCmd is executed" + ldapDeleteConfigurationCmd.execute() + then: "The given configuration should be deleted and returned" + ldapDeleteConfigurationCmd.responseObject.hostname == "localhost" } def "Test successful return of getCommandName"() { - given: - def ldapManager = Mock(LdapManager) + given: "We have an LdapManager and LdapDeleteConfigurationCmd" + def ldapManager = Mock(LdapManager) def ldapDeleteConfigurationCmd = new LdapDeleteConfigurationCmd(ldapManager) - when: + when: "Get Command name is called" String commandName = ldapDeleteConfigurationCmd.getCommandName() - then: + then: "ldapconfigurationresponse is returned" commandName == "ldapconfigurationresponse" } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy index f6ade314cda..bb6845cb7bf 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListAllUsersCmdSpec.groovy @@ -16,57 +16,51 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.api.command.LdapListAllUsersCmd -import org.apache.cloudstack.api.response.LdapUserResponse -import org.apache.cloudstack.ldap.LdapManager -import org.apache.cloudstack.ldap.LdapUser -import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException class LdapListAllUsersCmdSpec extends spock.lang.Specification { - def "Test successful response from execute"() { - given: - def ldapManager = Mock(LdapManager) - List users = new ArrayList() - users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) - ldapManager.getUsers() >> users - LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") - ldapManager.createLdapUserResponse(_) >> response - def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager) - when: - ldapListAllUsersCmd.execute() - then: - ldapListAllUsersCmd.responseObject.getResponses().size() != 0 + def "Test getEntityOwnerId is 1"() { + given: "We have an LdapManager and LdapListAllUsersCmd" + def ldapManager = Mock(LdapManager) + def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager) + when: "Get entity owner id is called" + long ownerId = ldapListAllUsersCmd.getEntityOwnerId() + then: "a 1 should be returned" + ownerId == 1 } def "Test successful empty response from execute"() { - given: + given: "We have a LdapManager with no users and a LdapListAllUsersCmd" def ldapManager = Mock(LdapManager) ldapManager.getUsers() >> {throw new NoLdapUserMatchingQueryException()} def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager) - when: + when: "LdapListAllUsersCmd is executed" ldapListAllUsersCmd.execute() - then: - ldapListAllUsersCmd.responseObject.getResponses().size() == 0 + then: "An array of size 0 is returned" + ldapListAllUsersCmd.responseObject.getResponses().size() == 0 } - def "Test getEntityOwnerId is 1"() { - given: - def ldapManager = Mock(LdapManager) - def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager) - when: - long ownerId = ldapListAllUsersCmd.getEntityOwnerId() - then: - ownerId == 1 + def "Test successful response from execute"() { + given: "We have an LdapManager, one user and a LdapListAllUsersCmd" + def ldapManager = Mock(LdapManager) + List users = new ArrayList() + users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) + ldapManager.getUsers() >> users + LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") + ldapManager.createLdapUserResponse(_) >> response + def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager) + when: "LdapListAllUsersCmd is executed" + ldapListAllUsersCmd.execute() + then: "a list of size not 0 is returned" + ldapListAllUsersCmd.responseObject.getResponses().size() != 0 } def "Test successful return of getCommandName"() { - given: + given: "We have an LdapManager and a LdapListAllUsersCmd" def ldapManager = Mock(LdapManager) def ldapListAllUsersCmd = new LdapListAllUsersCmd(ldapManager) - when: + when: "Get command name is called" String commandName = ldapListAllUsersCmd.getCommandName() - then: + then: "ldapuserresponse is returned" commandName == "ldapuserresponse" } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy index d83b926806f..11226d78c5b 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapListConfigurationCmdSpec.groovy @@ -16,19 +16,36 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.api.command.LdapListConfigurationCmd -import org.apache.cloudstack.api.response.LdapConfigurationResponse -import org.apache.cloudstack.ldap.LdapConfigurationVO -import org.apache.cloudstack.ldap.LdapManager - -import com.cloud.utils.Pair class LdapListConfigurationCmdSpec extends spock.lang.Specification { + def "Test failed response from execute"() { + given: "We have an LdapManager and a LdapListConfigurationsCmd" + def ldapManager = Mock(LdapManager) + List ldapConfigurationList = new ArrayList() + Pair, Integer> ldapConfigurations = new Pair, Integer>(); + ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size()) + ldapManager.listConfigurations(_) >> ldapConfigurations + def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) + when: "LdapListConfigurationCmd is executed" + ldapListConfigurationCmd.execute() + then: "Its response object contains an array that is 0" + ldapListConfigurationCmd.getResponseObject().getResponses().size() == 0 + } + + def "Test getEntityOwnerId is 1"() { + given: "We have an LdapManager and ListLdapConfigurationCmd" + def ldapManager = Mock(LdapManager) + def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) + when: "Get entity owner id is called" + long ownerId = ldapListConfigurationCmd.getEntityOwnerId() + then: "a 1 is returned" + ownerId == 1 + } + def "Test successful response from execute"() { - given: - def ldapManager = Mock(LdapManager) + given: "We have an LdapManager with a configuration and a LdapListConfigurationsCmd" + def ldapManager = Mock(LdapManager) List ldapConfigurationList = new ArrayList() ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389)) Pair, Integer> ldapConfigurations = new Pair, Integer>(); @@ -36,65 +53,39 @@ class LdapListConfigurationCmdSpec extends spock.lang.Specification { ldapManager.listConfigurations(_) >> ldapConfigurations ldapManager.createLdapConfigurationResponse(_) >> new LdapConfigurationResponse("localhost", 389) def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) - when: + when: "LdapListConfigurationsCmd is executed" ldapListConfigurationCmd.execute() - then: - ldapListConfigurationCmd.getResponseObject().getResponses().size() != 0 - } - - def "Test failed response from execute"() { - given: - - def ldapManager = Mock(LdapManager) - List ldapConfigurationList = new ArrayList() - Pair, Integer> ldapConfigurations = new Pair, Integer>(); - ldapConfigurations.set(ldapConfigurationList, ldapConfigurationList.size()) - ldapManager.listConfigurations(_) >> ldapConfigurations - - def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) - when: - ldapListConfigurationCmd.execute() - then: - ldapListConfigurationCmd.getResponseObject().getResponses().size() == 0 - } - - def "Test successful setting of hostname"() { - given: - def ldapManager = Mock(LdapManager) - def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) - when: - ldapListConfigurationCmd.setHostname("localhost") - then: - ldapListConfigurationCmd.getHostname() == "localhost" - } - - def "Test successful setting of Port"() { - given: - def ldapManager = Mock(LdapManager) - def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) - when: - ldapListConfigurationCmd.setPort(389) - then: - ldapListConfigurationCmd.getPort() == 389 - } - - def "Test getEntityOwnerId is 0"() { - given: - def ldapManager = Mock(LdapManager) - def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) - when: - long ownerId = ldapListConfigurationCmd.getEntityOwnerId() - then: - ownerId == 1 + then: "Its response object contains an array that is not 0 in size" + ldapListConfigurationCmd.getResponseObject().getResponses().size() != 0 } def "Test successful return of getCommandName"() { - given: + given: "We have an LdapManager and LdapListConfigurationCmd" + def ldapManager = Mock(LdapManager) + def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) + when: "Get command name is called" + String commandName = ldapListConfigurationCmd.getCommandName() + then: "ldapconfigurationresponse is returned" + commandName == "ldapconfigurationresponse" + } + + def "Test successful setting of hostname"() { + given: "We have an LdapManager and LdapListConfigurationCmd" def ldapManager = Mock(LdapManager) def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) - when: - String commandName = ldapListConfigurationCmd.getCommandName() - then: - commandName == "ldapconfigurationresponse" + when: "The hostname is set" + ldapListConfigurationCmd.setHostname("localhost") + then: "Get hostname returns the set value" + ldapListConfigurationCmd.getHostname() == "localhost" + } + + def "Test successful setting of Port"() { + given: "We have an LdapManager and LdapListConfigurationCmd" + def ldapManager = Mock(LdapManager) + def ldapListConfigurationCmd = new LdapListConfigurationCmd(ldapManager) + when: "The port is set" + ldapListConfigurationCmd.setPort(389) + then: "Get port returns the set value" + ldapListConfigurationCmd.getPort() == 389 } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapManagerImplSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapManagerImplSpec.groovy index 548057cd932..74929193682 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapManagerImplSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapManagerImplSpec.groovy @@ -16,260 +16,299 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import javax.naming.NamingException -import javax.naming.ldap.InitialLdapContext - -import org.apache.cloudstack.api.command.LdapListConfigurationCmd -import org.apache.cloudstack.ldap.* -import org.apache.cloudstack.ldap.dao.LdapConfigurationDaoImpl - -import com.cloud.exception.InvalidParameterValueException -import com.cloud.utils.Pair class LdapManagerImplSpec extends spock.lang.Specification { - def "Test that addConfiguration fails when a duplicate configuration exists"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapConfigurationDao.findByHostname(_) >> new LdapConfigurationVO("localhost", 389) - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - ldapManager.addConfiguration("localhost", 389) - then: - thrown InvalidParameterValueException + def "Test failing of getUser due to bind issue"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext() >> { throw new NamingException() } + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "We search for a user but there is a bind issue" + ldapManager.getUser("rmurphy") + then: "an exception is thrown" + thrown NamingException } - def "Test that addConfiguration fails when a binding fails"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext(_) >> { throw new NamingException() } - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - ldapManager.addConfiguration("localhost", 389) - then: - thrown InvalidParameterValueException + def "Test failing of getUsers due to bind issue"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext() >> { throw new NamingException() } + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "We search for a group of users but there is a bind issue" + ldapManager.getUsers() + then: "An exception is thrown" + thrown NoLdapUserMatchingQueryException } - def "Test successfully addConfiguration"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext(_) >> null - ldapConfigurationDao.persist(_) >> null - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.addConfiguration("localhost", 389) - then: - result.hostname == "localhost" - result.port == 389 + def "Test failing of searchUsers due to a failure to bind"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext() >> { throw new NamingException() } + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "We search for users" + ldapManager.searchUsers("rmurphy") + then: "An exception is thrown" + thrown NoLdapUserMatchingQueryException } - def "Test successful failed result from deleteConfiguration due to configuration not existing"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapConfigurationDao.findByHostname(_) >> null - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - ldapManager.deleteConfiguration("localhost") - then: - thrown InvalidParameterValueException + def "Test LdapConfigurationResponse generation"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "A ldap configuration response is generated" + def result = ldapManager.createLdapConfigurationResponse(new LdapConfigurationVO("localhost", 389)) + then: "the result of the response should match the given LdapConfigurationVO" + result.hostname == "localhost" + result.port == 389 } - def "Test successful result from deleteConfiguration"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapConfigurationDao.findByHostname(_) >> { - def configuration = new LdapConfigurationVO("localhost", 389) - configuration.setId(0); - return configuration; - } - ldapConfigurationDao.remove(_) >> null - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.deleteConfiguration("localhost") - then: - result.hostname == "localhost" - result.port == 389 + def "Test LdapUserResponse generation"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "A ldap user response is generated" + def result = ldapManager.createLdapUserResponse(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) + then: "TThe result of the response should match the given ldap user" + result.username == "rmurphy" + result.email == "rmurphy@test.com" + result.firstname == "Ryan" + result.lastname == "Murphy" + result.principal == "cn=rmurphy,dc=cloudstack,dc=org" } - def "Test successful failed result from canAuthenticate due to user not found"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - def ldapManager = Spy(LdapManagerImpl, constructorArgs: [ldapConfigurationDao, ldapContextFactory, ldapUserManager]) - ldapManager.getUser(_) >> { throw new NamingException() } - when: - def result = ldapManager.canAuthenticate("rmurphy", "password") - then: - result == false + def "Test success getUsers"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext() >> null + List users = new ArrayList<>(); + users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) + ldapUserManager.getUsers(_) >> users; + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "We search for a group of users" + def result = ldapManager.getUsers() + then: "A list greater than 0 is returned" + result.size() > 0; + } + + def "Test success of getUser"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext() >> null + ldapUserManager.getUser(_, _) >> new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "We search for a user" + def result = ldapManager.getUser("rmurphy") + then: "The user is returned" + result.username == "rmurphy" + result.email == "rmurphy@test.com" + result.firstname == "Ryan" + result.lastname == "Murphy" + result.principal == "cn=rmurphy,dc=cloudstack,dc=org" + } + + def "Test successful closing of context"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "The context is closed" + def context = Mock(InitialLdapContext) + ldapManager.closeContext(context) + then: "The context is null" + context.defaultInitCtx == null } def "Test successful failed result from canAuthenticate due to bad password"() { - given: + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) def ldapContextFactory = Mock(LdapContextFactory) ldapContextFactory.createUserContext(_, _) >> { throw new NamingException() } def ldapUserManager = Mock(LdapUserManager) def ldapManager = Spy(LdapManagerImpl, constructorArgs: [ldapConfigurationDao, ldapContextFactory, ldapUserManager]) ldapManager.getUser(_) >> { new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") } - when: + when: "The user attempts to authenticate with a bad password" def result = ldapManager.canAuthenticate("rmurphy", "password") - then: - result == false + then: "The authentication fails" + result == false } - def "Test successful result from canAuthenticate"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - ldapContextFactory.createUserContext(_, _) >> null - def ldapUserManager = Mock(LdapUserManager) - def ldapManager = Spy(LdapManagerImpl, constructorArgs: [ldapConfigurationDao, ldapContextFactory, ldapUserManager]) - ldapManager.getUser(_) >> { new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") } - when: - def result = ldapManager.canAuthenticate("rmurphy", "password") - then: - result == true + def "Test successful failed result from canAuthenticate due to user not found"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + def ldapManager = Spy(LdapManagerImpl, constructorArgs: [ldapConfigurationDao, ldapContextFactory, ldapUserManager]) + ldapManager.getUser(_) >> { throw new NamingException() } + when: "The user attempts to authenticate and the user is not found" + def result = ldapManager.canAuthenticate("rmurphy", "password") + then: "the authentication fails" + result == false } - def "Test successful closing of context"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def context = Mock(InitialLdapContext) - ldapManager.closeContext(context) - then: - context.defaultInitCtx == null + def "Test successful failed result from deleteConfiguration due to configuration not existing"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapConfigurationDao.findByHostname(_) >> null + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "A ldap configuration that doesn't exist is deleted" + ldapManager.deleteConfiguration("localhost") + then: "A exception is thrown" + thrown InvalidParameterValueException } def "Test successful failing to close of context"() { - given: + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) def ldapContextFactory = Mock(LdapContextFactory) def ldapUserManager = Mock(LdapUserManager) def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: + when: "The context is closed" def context = Mock(InitialLdapContext) context.close() >> { throw new NamingException() } ldapManager.closeContext(context) - then: - context.defaultInitCtx == null + then: "An exception is thrown" + context.defaultInitCtx == null } - def "Test LdapConfigurationResponse generation"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.createLdapConfigurationResponse(new LdapConfigurationVO("localhost", 389)) - then: - result.hostname == "localhost" - result.port == 389 + def "Test successful result from canAuthenticate"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + ldapContextFactory.createUserContext(_, _) >> null + def ldapUserManager = Mock(LdapUserManager) + def ldapManager = Spy(LdapManagerImpl, constructorArgs: [ldapConfigurationDao, ldapContextFactory, ldapUserManager]) + ldapManager.getUser(_) >> { new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") } + when: "A user authenticates" + def result = ldapManager.canAuthenticate("rmurphy", "password") + then: "The result is true" + result == true } - def "Test LdapUserResponse generation"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.createLdapUserResponse(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) - then: - result.username == "rmurphy" - result.email == "rmurphy@test.com" - result.firstname == "Ryan" - result.lastname == "Murphy" - result.principal == "cn=rmurphy,dc=cloudstack,dc=org" + def "Test successful result from deleteConfiguration"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapConfigurationDao.findByHostname(_) >> { + def configuration = new LdapConfigurationVO("localhost", 389) + configuration.setId(0); + return configuration; + } + ldapConfigurationDao.remove(_) >> null + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "A ldap configuration is deleted" + def result = ldapManager.deleteConfiguration("localhost") + then: "The deleted configuration is returned" + result.hostname == "localhost" + result.port == 389 + } + + def "Test successful result from searchUsers"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext() >> null; + + List users = new ArrayList(); + users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) + ldapUserManager.getUsers(_, _) >> users; + + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "We search for users" + def result = ldapManager.searchUsers("rmurphy"); + then: "A list of atleast 1 is returned" + result.size() > 0; + } + + def "Test successfully addConfiguration"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext(_) >> null + ldapConfigurationDao.persist(_) >> null + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "A ldap configuration is added" + def result = ldapManager.addConfiguration("localhost", 389) + then: "the resulting object contain the given hostname and port" + result.hostname == "localhost" + result.port == 389 + } + + def "Test that addConfiguration fails when a binding fails"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapContextFactory.createBindContext(_) >> { throw new NamingException() } + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "A configuration is added that can not be binded" + ldapManager.addConfiguration("localhost", 389) + then: "An exception is thrown" + thrown InvalidParameterValueException + } + + def "Test that addConfiguration fails when a duplicate configuration exists"() { + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + ldapConfigurationDao.findByHostname(_) >> new LdapConfigurationVO("localhost", 389) + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "a configuration that already exists is added" + ldapManager.addConfiguration("localhost", 389) + then: "An exception is thrown" + thrown InvalidParameterValueException } def "Test that getCommands isn't empty"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.getCommands() - then: - result.size() > 0 + given: "We have an LdapConfigurationDao, LdapContextFactory, LdapUserManager and LdapManager" + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: "Get commands is called" + def result = ldapManager.getCommands() + then: "it must have atleast 1 command" + result.size() > 0 } - def "Test failing of getUser due to bind issue"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext() >> { throw new NamingException() } - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - ldapManager.getUser("rmurphy") - then: - thrown NamingException - } + def "Testing of isLdapEnabled"() { + given: + def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) + def ldapContextFactory = Mock(LdapContextFactory) + def ldapUserManager = Mock(LdapUserManager) + List ldapConfigurationList = new ArrayList() + ldapConfigurationList.add(new LdapConfigurationVO("localhost", 389)) + Pair, Integer> configurations = new Pair, Integer>(); + configurations.set(ldapConfigurationList, ldapConfigurationList.size()) + ldapConfigurationDao.searchConfigurations(_, _) >> configurations + def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) + when: + def result = ldapManager.isLdapEnabled(); + then: + result == true; + } - def "Test success of getUser"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext() >> null - ldapUserManager.getUser(_, _) >> new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.getUser("rmurphy") - then: - result.username == "rmurphy" - result.email == "rmurphy@test.com" - result.firstname == "Ryan" - result.lastname == "Murphy" - result.principal == "cn=rmurphy,dc=cloudstack,dc=org" - } - - def "Test failing of getUsers due to bind issue"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext() >> { throw new NamingException() } - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - ldapManager.getUsers() - then: - thrown NoLdapUserMatchingQueryException - } - - def "Test success getUsers"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext() >> null - List users = new ArrayList<>(); - users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) - ldapUserManager.getUsers(_) >> users; - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.getUsers() - then: - result.size() > 0; - } - - def "Testing of listConfigurations"() { + def "Testing of listConfigurations"() { given: def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) def ldapContextFactory = Mock(LdapContextFactory) @@ -282,38 +321,7 @@ class LdapManagerImplSpec extends spock.lang.Specification { def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) when: def result = ldapManager.listConfigurations(new LdapListConfigurationCmd()) - then: - result.second() > 0 - } - - def "Test failing of searchUsers due to a failure to bind"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext() >> { throw new NamingException() } - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - ldapManager.searchUsers("rmurphy") - then: - thrown NoLdapUserMatchingQueryException - } - - def "Test successful result from searchUsers"() { - given: - def ldapConfigurationDao = Mock(LdapConfigurationDaoImpl) - def ldapContextFactory = Mock(LdapContextFactory) - def ldapUserManager = Mock(LdapUserManager) - ldapContextFactory.createBindContext() >> null; - - List users = new ArrayList(); - users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) - ldapUserManager.getUsers(_, _) >> users; - - def ldapManager = new LdapManagerImpl(ldapConfigurationDao, ldapContextFactory, ldapUserManager) - when: - def result = ldapManager.searchUsers("rmurphy"); - then: - result.size() > 0; + then: + result.second() > 0 } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy index b23d7c2d02f..4bc5ca8787e 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapSearchUserCmdSpec.groovy @@ -16,27 +16,16 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.api.ServerApiException -import org.apache.cloudstack.api.command.LdapUserSearchCmd -import org.apache.cloudstack.api.response.LdapUserResponse -import org.apache.cloudstack.ldap.LdapManager -import org.apache.cloudstack.ldap.LdapUser -import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException class LdapSearchUserCmdSpec extends spock.lang.Specification { - def "Test successful response from execute"() { + def "Test getEntityOwnerId is 1"() { given: def ldapManager = Mock(LdapManager) - List users = new ArrayList() - users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) - ldapManager.searchUsers(_) >> users - LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") - ldapManager.createLdapUserResponse(_) >> response def ldapUserSearchCmd = new LdapUserSearchCmd(ldapManager) when: - ldapUserSearchCmd.execute() + long ownerId = ldapUserSearchCmd.getEntityOwnerId() then: - ldapUserSearchCmd.responseObject.getResponses().size() != 0 + ownerId == 1 } def "Test successful empty response from execute"() { @@ -50,14 +39,19 @@ class LdapSearchUserCmdSpec extends spock.lang.Specification { ldapUserSearchCmd.responseObject.getResponses().size() == 0 } - def "Test getEntityOwnerId is 0"() { + def "Test successful response from execute"() { given: def ldapManager = Mock(LdapManager) + List users = new ArrayList() + users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org")) + ldapManager.searchUsers(_) >> users + LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org") + ldapManager.createLdapUserResponse(_) >> response def ldapUserSearchCmd = new LdapUserSearchCmd(ldapManager) when: - long ownerId = ldapUserSearchCmd.getEntityOwnerId() + ldapUserSearchCmd.execute() then: - ownerId == 1 + ldapUserSearchCmd.responseObject.getResponses().size() != 0 } def "Test successful return of getCommandName"() { diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy index 2d31aa6251d..d13f0e80163 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserManagerSpec.groovy @@ -16,16 +16,10 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.LdapConfiguration -import org.apache.cloudstack.ldap.LdapUserManager -import spock.lang.Shared +import javax.naming.directory.Attributes; +import javax.naming.directory.SearchResult; -import javax.naming.NamingException -import javax.naming.directory.Attribute -import javax.naming.directory.Attributes -import javax.naming.directory.SearchControls -import javax.naming.directory.SearchResult -import javax.naming.ldap.LdapContext +import spock.lang.Shared; class LdapUserManagerSpec extends spock.lang.Specification { @@ -47,6 +41,55 @@ class LdapUserManagerSpec extends spock.lang.Specification { @Shared private def principal + private def createContext() { + + Attributes attributes = createUserAttributes(username, email, firstname, lastname) + SearchResult searchResults = createSearchResult(attributes) + def searchUsersResults = new BasicNamingEnumerationImpl() + searchUsersResults.add(searchResults); + + def context = Mock(LdapContext) + context.search(_, _, _) >> searchUsersResults; + + return context + } + + private SearchResult createSearchResult(attributes) { + def search = Mock(SearchResult) + + search.getName() >> "cn=" + attributes.getAt("uid").get(); + + search.getAttributes() >> attributes + + return search + } + + private Attributes createUserAttributes(String username, String email, String firstname, String lastname) { + def attributes = Mock(Attributes) + + def nameAttribute = Mock(Attribute) + nameAttribute.getId() >> "uid" + nameAttribute.get() >> username + attributes.get("uid") >> nameAttribute + + def mailAttribute = Mock(Attribute) + mailAttribute.getId() >> "mail" + mailAttribute.get() >> email + attributes.get("mail") >> mailAttribute + + def givennameAttribute = Mock(Attribute) + givennameAttribute.getId() >> "givenname" + givennameAttribute.get() >> firstname + attributes.get("givenname") >> givennameAttribute + + def snAttribute = Mock(Attribute) + snAttribute.getId() >> "sn" + snAttribute.get() >> lastname + attributes.get("sn") >> snAttribute + + return attributes + } + def setupSpec() { ldapConfiguration = Mock(LdapConfiguration) @@ -62,146 +105,97 @@ class LdapUserManagerSpec extends spock.lang.Specification { email = "rmurphy@test.com" firstname = "Ryan" lastname = "Murphy" - principal = "cn=" + username + "," + ldapConfiguration.getBaseDn() - } - - def "Test that a newly created Ldap User Manager is not null"() { - given: "You have created a new Ldap user manager object" - def result = new LdapUserManager(); - expect: "The result is not null" - result != null + principal = "cn=" + username + "," + ldapConfiguration.getBaseDn() } def "Test successfully creating an Ldap User from Search result"() { - given: - def attributes = createUserAttributes(username, email, firstname, lastname) + given: "We have attributes, a search and a user manager" + def attributes = createUserAttributes(username, email, firstname, lastname) def search = createSearchResult(attributes) def userManager = new LdapUserManager(ldapConfiguration) def result = userManager.createUser(search) - expect: + expect: "The crated user the data supplied from LDAP" result.username == username result.email == email result.firstname == firstname result.lastname == lastname - result.principal == principal - } - - def "Test successfully returning an Ldap user from a get user request"() { - given: - - def userManager = new LdapUserManager(ldapConfiguration) - - when: - def result = userManager.getUser(username, createContext()) - - then: - result.username == username - result.email == email - result.firstname == firstname - result.lastname == lastname - result.principal == principal + result.principal == principal } def "Test successfully returning a list from get users"() { - given: + given: "We have a LdapUserManager" def userManager = new LdapUserManager(ldapConfiguration) - when: + when: "A request for users is made" def result = userManager.getUsers(username, createContext()) - then: + then: "A list of users is returned" result.size() == 1 } def "Test successfully returning a list from get users when no username is given"() { - given: + given: "We have a LdapUserManager" def userManager = new LdapUserManager(ldapConfiguration) - when: + when: "Get users is called without a username" def result = userManager.getUsers(createContext()) - then: - result.size() == 1 - } - - def "Test successfully throwing an exception when no users are found with getUser"() { - given: - - def searchUsersResults = new BasicNamingEnumerationImpl() - - def context = Mock(LdapContext) - context.search(_, _, _) >> searchUsersResults; - - def userManager = new LdapUserManager(ldapConfiguration) - - when: - def result = userManager.getUser(username, context) - - then: - thrown NamingException + then: "All users are returned" + result.size() == 1 } def "Test successfully returning a NamingEnumeration from searchUsers"() { - given: - def userManager = new LdapUserManager(ldapConfiguration) + given: "We have a LdapUserManager" + def userManager = new LdapUserManager(ldapConfiguration) - when: + when: "We search for users" def result = userManager.searchUsers(createContext()) - then: + then: "A list of users are returned." result.next().getName() + "," + ldapConfiguration.getBaseDn() == principal } - private def createContext() { + def "Test successfully returning an Ldap user from a get user request"() { + given: "We have a LdapUserMaanger" - Attributes attributes = createUserAttributes(username, email, firstname, lastname) - SearchResult searchResults = createSearchResult(attributes) - def searchUsersResults = new BasicNamingEnumerationImpl() - searchUsersResults.add(searchResults); + def userManager = new LdapUserManager(ldapConfiguration) - def context = Mock(LdapContext) - context.search(_, _, _) >> searchUsersResults; + when: "A request for a user is made" + def result = userManager.getUser(username, createContext()) - return context + then: "The user is returned" + result.username == username + result.email == email + result.firstname == firstname + result.lastname == lastname + result.principal == principal } - private SearchResult createSearchResult(attributes) { - def search = Mock(SearchResult) + def "Test successfully throwing an exception when no users are found with getUser"() { + given: "We have a seachResult of users and a User Manager" - search.getName() >> "cn=" + attributes.getAt("uid").get(); + def searchUsersResults = new BasicNamingEnumerationImpl() - search.getAttributes() >> attributes + def context = Mock(LdapContext) + context.search(_, _, _) >> searchUsersResults; - return search + def userManager = new LdapUserManager(ldapConfiguration) + + when: "a get user request is made and no user is found" + def result = userManager.getUser(username, context) + + then: "An exception is thrown." + thrown NamingException } - private Attributes createUserAttributes(String username, String email, String firstname, String lastname) { - def attributes = Mock(Attributes) - - def nameAttribute = Mock(Attribute) - nameAttribute.getId() >> "uid" - nameAttribute.get() >> username - attributes.get("uid") >> nameAttribute - - def mailAttribute = Mock(Attribute) - mailAttribute.getId() >> "mail" - mailAttribute.get() >> email - attributes.get("mail") >> mailAttribute - - def givennameAttribute = Mock(Attribute) - givennameAttribute.getId() >> "givenname" - givennameAttribute.get() >> firstname - attributes.get("givenname") >> givennameAttribute - - def snAttribute = Mock(Attribute) - snAttribute.getId() >> "sn" - snAttribute.get() >> lastname - attributes.get("sn") >> snAttribute - - return attributes + def "Test that a newly created Ldap User Manager is not null"() { + given: "You have created a new Ldap user manager object" + def result = new LdapUserManager(); + expect: "The result is not null" + result != null } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserResponseSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserResponseSpec.groovy index aa7d5a3c75d..2389a9d2d93 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserResponseSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserResponseSpec.groovy @@ -16,52 +16,51 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.api.response.LdapUserResponse class LdapUserResponseSpec extends spock.lang.Specification { def "Testing succcessful setting of LdapUserResponse email"() { - given: + given: "We have an LdapResponse" LdapUserResponse response = new LdapUserResponse(); - when: + when: "An email address is set" response.setEmail("rmurphy@test.com"); - then: - response.getEmail() == "rmurphy@test.com"; - } - - def "Testing successful setting of LdapUserResponse principal"() { - given: - LdapUserResponse response = new LdapUserResponse() - when: - response.setPrincipal("dc=cloudstack,dc=org") - then: - response.getPrincipal() == "dc=cloudstack,dc=org" - } - - def "Testing successful setting of LdapUserResponse username"() { - given: - LdapUserResponse response = new LdapUserResponse() - when: - response.setUsername("rmurphy") - then: - response.getUsername() == "rmurphy" + then: "Get email should return that set email" + response.getEmail() == "rmurphy@test.com"; } def "Testing successful setting of LdapUserResponse firstname"() { - given: - LdapUserResponse response = new LdapUserResponse() - when: + given: "We have an LdapUserResponse" + LdapUserResponse response = new LdapUserResponse() + when: "A firstname is set" response.setFirstname("Ryan") - then: + then: "gGet Firstname returns the set value" response.getFirstname() == "Ryan" } def "Testing successful setting of LdapUserResponse lastname"() { - given: + given: "We have an LdapUserResponse" LdapUserResponse response = new LdapUserResponse() - when: + when: "A lastname is set" response.setLastname("Murphy") - then: - response.getLastname() == "Murphy" + then: "Get lastname is returned" + response.getLastname() == "Murphy" + } + + def "Testing successful setting of LdapUserResponse principal"() { + given: "We have an LdapResponse" + LdapUserResponse response = new LdapUserResponse() + when: "A principal is set" + response.setPrincipal("dc=cloudstack,dc=org") + then: "Get principled returns the set value" + response.getPrincipal() == "dc=cloudstack,dc=org" + } + + def "Testing successful setting of LdapUserResponse username"() { + given: "We have an LdapUserResponse" + LdapUserResponse response = new LdapUserResponse() + when: "A username is set" + response.setUsername("rmurphy") + then: "Get username returns the set value." + response.getUsername() == "rmurphy" } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserSpec.groovy index 5519d7f5b13..65103521dfe 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUserSpec.groovy @@ -16,10 +16,43 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.LdapUser class LdapUserSpec extends spock.lang.Specification { + def "Testing LdapUsers hashCode generation"() { + given: + def userA = new LdapUser(usernameA, "", "", "", "") + expect: + userA.hashCode() == usernameA.hashCode() + where: + usernameA = "A" + } + + def "Testing that LdapUser successfully gives the correct result for a compare to"() { + given: "You have created two LDAP user objects" + def userA = new LdapUser(usernameA, "", "", "", "") + def userB = new LdapUser(usernameB, "", "", "", "") + expect: "That when compared the result is less than or equal to 0" + userA.compareTo(userB) <= 0 + where: "The following values are used" + usernameA | usernameB + "A" | "B" + "A" | "A" + } + + def "Testing that LdapUsers equality"() { + given: + def userA = new LdapUser(usernameA, "", "", "", "") + def userB = new LdapUser(usernameB, "", "", "", "") + expect: + userA.equals(userA) == true + userA.equals(new Object()) == false + userA.equals(userB) == false + where: + usernameA | usernameB + "A" | "B" + } + def "Testing that the username is correctly set with the ldap object"() { given: "You have created a LDAP user object with a username" def user = new LdapUser(username, "", "", "","") @@ -64,38 +97,4 @@ class LdapUserSpec extends spock.lang.Specification { where: "The username is set to " principal << ["", null, "cn=rmurphy,dc=cloudstack,dc=org"] } - - def "Testing that LdapUser successfully gives the correct result for a compare to"() { - given: "You have created two LDAP user objects" - def userA = new LdapUser(usernameA, "", "", "", "") - def userB = new LdapUser(usernameB, "", "", "", "") - expect: "That when compared the result is less than or equal to 0" - userA.compareTo(userB) <= 0 - where: "The following values are used" - usernameA | usernameB - "A" | "B" - "A" | "A" - } - - def "Testing that LdapUsers equality"() { - given: - def userA = new LdapUser(usernameA, "", "", "", "") - def userB = new LdapUser(usernameB, "", "", "", "") - expect: - userA.equals(userA) == true - userA.equals(new Object()) == false - userA.equals(userB) == false - where: - usernameA | usernameB - "A" | "B" - } - - def "Testing LdapUsers hashCode generation"() { - given: - def userA = new LdapUser(usernameA, "", "", "", "") - expect: - userA.hashCode() == usernameA.hashCode() - where: - usernameA = "A" - } } \ No newline at end of file diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUtilsSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUtilsSpec.groovy index 7fc05a95903..1825c39c2af 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUtilsSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapUtilsSpec.groovy @@ -16,22 +16,18 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.LdapUtils - -import javax.naming.directory.Attribute -import javax.naming.directory.Attributes class LdapUtilsSpec extends spock.lang.Specification { - def "Testing that a Ldap Search Filter is correctly escaped"() { - given: "You have some input from a user" + def "Testing than an attribute is not successfully returned"() { + given: "You have an attributes object with some attribute" + def attributes = Mock(Attributes) + attributes.get("uid") >> null - expect: "That the input is escaped" - LdapUtils.escapeLDAPSearchFilter(input) == result + when: "You get the attribute" + String foundValue = LdapUtils.getAttributeValue(attributes, "uid") - where: "The following inputs are given " - input | result - "Hi This is a test #çà" | "Hi This is a test #çà" - "Hi (This) = is * a \\ test # ç à ô \u0000" | "Hi \\28This\\29 = is \\2a a \\5c test # ç à ô \\00" + then: "Its value equals uid" + foundValue == null } def "Testing than an attribute is successfully returned"() { @@ -54,15 +50,15 @@ class LdapUtilsSpec extends spock.lang.Specification { "email" | "rmurphy@test.com" } - def "Testing than an attribute is not successfully returned"() { - given: "You have an attributes object with some attribute" - def attributes = Mock(Attributes) - attributes.get("uid") >> null + def "Testing that a Ldap Search Filter is correctly escaped"() { + given: "You have some input from a user" - when: "You get the attribute" - String foundValue = LdapUtils.getAttributeValue(attributes, "uid") + expect: "That the input is escaped" + LdapUtils.escapeLDAPSearchFilter(input) == result - then: "Its value equals uid" - foundValue == null + where: "The following inputs are given " + input | result + "Hi This is a test #çà" | "Hi This is a test #çà" + "Hi (This) = is * a \\ test # ç à ô \u0000" | "Hi \\28This\\29 = is \\2a a \\5c test # ç à ô \\00" } } diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoLdapUserMatchingQueryExceptionSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoLdapUserMatchingQueryExceptionSpec.groovy index 4c0cc4b688f..a3010126bf2 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoLdapUserMatchingQueryExceptionSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoLdapUserMatchingQueryExceptionSpec.groovy @@ -16,7 +16,6 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException class NoLdapUserMatchingQueryExceptionSpec extends spock.lang.Specification { def "Test that the query is correctly set within the No LDAP user matching query exception object"() { diff --git a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoSuchLdapUserExceptionSpec.groovy b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoSuchLdapUserExceptionSpec.groovy index dbdf646721d..84cc90867a1 100644 --- a/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoSuchLdapUserExceptionSpec.groovy +++ b/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/NoSuchLdapUserExceptionSpec.groovy @@ -16,7 +16,6 @@ // under the License. package groovy.org.apache.cloudstack.ldap -import org.apache.cloudstack.ldap.NoSuchLdapUserException; class NoSuchLdapUserExceptionSpec extends spock.lang.Specification { def "Test that the username is correctly set within the No such LDAP user exception object"() { diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index bc60d6c1c2e..8fc2637a1b2 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -424,7 +424,7 @@ public enum Config { // object store S3EnableRRS("Advanced", ManagementServer.class, Boolean.class, "s3.rrs.enabled", "false", "enable s3 reduced redundancy storage", null), - // Ldap + // Ldap LdapBasedn("Advanced", ManagementServer.class, String.class, "ldap.basedn", null, "Sets the basedn for LDAP", null), LdapBindPassword("Advanced", ManagementServer.class, String.class, "ldap.bind.password", null, "Sets the bind password for LDAP", null), LdapBindPrincipal("Advanced", ManagementServer.class, String.class, "ldap.bind.principal", null, "Sets the bind principal for LDAP", null), @@ -434,7 +434,6 @@ public enum Config { LdapUsernameAttribute("Advanced", ManagementServer.class, String.class, "ldap.username.attribute", "uid", "Sets the username attribute used within LDAP", null), LdapUserObject("Advanced", ManagementServer.class, String.class, "ldap.user.object", "inetOrgPerson", "Sets the object type of users within LDAP", null), LdapSearchGroupPrinciple("Advanced", ManagementServer.class, String.class, "ldap.search.group.principle", null, "Sets the principle of the group that users must be a member of", null), - LdapSSLEnabled("Advanced", ManagementServer.class, String.class, "ldap.ssl.enabled", "false", "Enables/Disables SSL support for LDAP", null), LdapTrustStore("Advanced", ManagementServer.class, String.class, "ldap.truststore", null, "Sets the path to the truststore to use for SSL", null), LdapTrustStorePassword("Advanced", ManagementServer.class, String.class, "ldap.truststore.password", null, "Sets the password for the truststore", null), @@ -446,15 +445,15 @@ public enum Config { BlacklistedRoutes("Advanced", VpcManager.class, String.class, "blacklisted.routes", null, "Routes that are blacklisted, can not be used for Static Routes creation for the VPC Private Gateway", "routes", ConfigurationParameterScope.zone.toString()), - + InternalLbVmServiceOfferingId("Advanced", ManagementServer.class, String.class, "internallbvm.service.offering", null, "Uuid of the service offering used by internal lb vm; if NULL - default system internal lb offering will be used", null), ExecuteInSequence("Advanced", ManagementServer.class, Boolean.class, "execute.in.sequence.hypervisor.commands", "false", "If set to true, StartCommand, StopCommand, CopyCommand will be synchronized on the agent side." + " If set to false, these commands become asynchronous. Default value is false.", null), - ExecuteInSequenceNetworkElementCommands("Advanced", NetworkManager.class, Boolean.class, "execute.in.sequence.network.element.commands", "false", "If set to true, DhcpEntryCommand, SavePasswordCommand, UserDataCommand, VmDataCommand will be synchronized on the agent side." + + ExecuteInSequenceNetworkElementCommands("Advanced", NetworkManager.class, Boolean.class, "execute.in.sequence.network.element.commands", "false", "If set to true, DhcpEntryCommand, SavePasswordCommand, UserDataCommand, VmDataCommand will be synchronized on the agent side." + " If set to false, these commands become asynchronous. Default value is false.", null), - + UCSSyncBladeInterval("Advanced", ManagementServer.class, Integer.class, "ucs.sync.blade.interval", "3600", "the interval cloudstack sync with UCS manager for available blades in case user remove blades from chassis without notifying CloudStack", null); - + private final String _category; private final Class _componentClass; private final Class _type; @@ -630,4 +629,4 @@ public enum Config { public static List getConfigListByScope(String scope) { return _scopeLevelConfigsMap.get(scope); } -} \ No newline at end of file +} diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 52772583752..43c6c74174e 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -98,7 +98,7 @@ CREATE TABLE `cloud`.`image_store` ( `uuid` varchar(255) COMMENT 'uuid of data store', `parent` varchar(255) COMMENT 'parent path for the storage server', `created` datetime COMMENT 'date the image store first signed on', - `removed` datetime COMMENT 'date removed if not null', + `removed` datetime COMMENT 'date removed if not null', `total_size` bigint unsigned COMMENT 'storage total size statistics', `used_bytes` bigint unsigned COMMENT 'storage available bytes statistics', PRIMARY KEY(`id`) @@ -116,7 +116,7 @@ CREATE TABLE `cloud`.`image_store_details` ( DROP VIEW IF EXISTS `cloud`.`image_store_view`; CREATE VIEW `cloud`.`image_store_view` AS - select + select image_store.id, image_store.uuid, image_store.name, @@ -138,9 +138,9 @@ CREATE VIEW `cloud`.`image_store_view` AS left join `cloud`.`image_store_details` ON image_store_details.store_id = image_store.id; - + -- here we have to allow null for store_id to accomodate baremetal case to search for ready templates since template state is only stored in this table --- FK also commented out due to this +-- FK also commented out due to this CREATE TABLE `cloud`.`template_store_ref` ( `id` bigint unsigned NOT NULL auto_increment, `store_id` bigint unsigned, @@ -150,7 +150,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( `job_id` varchar(255), `download_pct` int(10) unsigned, `size` bigint unsigned, - `store_role` varchar(255), + `store_role` varchar(255), `physical_size` bigint unsigned DEFAULT 0, `download_state` varchar(255), `error_str` varchar(255), @@ -162,7 +162,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( `is_copy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'indicates whether this was copied ', `update_count` bigint unsigned, `ref_cnt` bigint unsigned DEFAULT 0, - `updated` datetime, + `updated` datetime, PRIMARY KEY (`id`), -- CONSTRAINT `fk_template_store_ref__store_id` FOREIGN KEY `fk_template_store_ref__store_id` (`store_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE, INDEX `i_template_store_ref__store_id`(`store_id`), @@ -178,7 +178,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( -- ALTER TABLE `cloud`.`snapshots` DROP COLUMN `sechost_id`; -- change upload host_id FK to point to image_store table -ALTER TABLE `cloud`.`upload` DROP FOREIGN KEY `fk_upload__host_id`; +ALTER TABLE `cloud`.`upload` DROP FOREIGN KEY `fk_upload__host_id`; ALTER TABLE `cloud`.`upload` ADD CONSTRAINT `fk_upload__store_id` FOREIGN KEY(`host_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE; CREATE TABLE `cloud`.`snapshot_store_ref` ( @@ -193,11 +193,11 @@ CREATE TABLE `cloud`.`snapshot_store_ref` ( `physical_size` bigint unsigned DEFAULT 0, `parent_snapshot_id` bigint unsigned DEFAULT 0, `install_path` varchar(255), - `state` varchar(255) NOT NULL, - -- `removed` datetime COMMENT 'date removed if not null', + `state` varchar(255) NOT NULL, + -- `removed` datetime COMMENT 'date removed if not null', `update_count` bigint unsigned, `ref_cnt` bigint unsigned, - `updated` datetime, + `updated` datetime, `volume_id` bigint unsigned, PRIMARY KEY (`id`), INDEX `i_snapshot_store_ref__store_id`(`store_id`), @@ -222,11 +222,11 @@ CREATE TABLE `cloud`.`volume_store_ref` ( `local_path` varchar(255), `install_path` varchar(255), `url` varchar(255), - `state` varchar(255) NOT NULL, + `state` varchar(255) NOT NULL, `destroyed` tinyint(1) COMMENT 'indicates whether the volume_host entry was destroyed by the user or not', `update_count` bigint unsigned, `ref_cnt` bigint unsigned, - `updated` datetime, + `updated` datetime, PRIMARY KEY (`id`), CONSTRAINT `fk_volume_store_ref__store_id` FOREIGN KEY `fk_volume_store_ref__store_id` (`store_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE, INDEX `i_volume_store_ref__store_id`(`store_id`), @@ -554,12 +554,12 @@ ALTER TABLE `cloud`.`remote_access_vpn` ADD COLUMN `id` bigint unsigned NOT NULL ALTER TABLE `cloud`.`remote_access_vpn` ADD COLUMN `uuid` varchar(40) UNIQUE; -- START: support for LXC - + INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled) VALUES (UUID(), 'LXC', 'default', 50, 1); ALTER TABLE `cloud`.`physical_network_traffic_types` ADD COLUMN `lxc_network_label` varchar(255) DEFAULT 'cloudbr0' COMMENT 'The network name label of the physical device dedicated to this traffic on a LXC host'; - + UPDATE configuration SET value='KVM,XenServer,VMware,BareMetal,Ovm,LXC' WHERE name='hypervisor.list'; - + INSERT INTO `cloud`.`vm_template` (id, uuid, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones, hypervisor_type) VALUES (10, UUID(), 'routing-10', 'SystemVM Template (LXC)', 0, now(), 'SYSTEM', 0, 64, 1, 'http://download.cloud.com/templates/acton/acton-systemvm-02062012.qcow2.bz2', '2755de1f9ef2ce4d6f2bee2efbb4da92', 0, 'SystemVM Template (LXC)', 'QCOW2', 15, 0, 1, 'LXC'); @@ -609,10 +609,10 @@ CREATE TABLE `cloud`.`service_offering_details` ( CONSTRAINT `fk_service_offering_details__service_offering_id` FOREIGN KEY (`service_offering_id`) REFERENCES `service_offering`(`id`) ON DELETE CASCADE, CONSTRAINT UNIQUE KEY `uk_service_offering_id_name` (`service_offering_id`, `name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + DROP VIEW IF EXISTS `cloud`.`user_vm_view`; CREATE VIEW `cloud`.`user_vm_view` AS - select + select vm_instance.id id, vm_instance.name name, user_vm.display_name display_name, @@ -790,7 +790,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS DROP VIEW IF EXISTS `cloud`.`affinity_group_view`; CREATE VIEW `cloud`.`affinity_group_view` AS - select + select affinity_group.id id, affinity_group.name name, affinity_group.type type, @@ -824,7 +824,7 @@ CREATE VIEW `cloud`.`affinity_group_view` AS DROP VIEW IF EXISTS `cloud`.`host_view`; CREATE VIEW `cloud`.`host_view` AS - select + select host.id, host.uuid, host.name, @@ -892,10 +892,10 @@ CREATE VIEW `cloud`.`host_view` AS `cloud`.`async_job` ON async_job.instance_id = host.id and async_job.instance_type = 'Host' and async_job.job_status = 0; - + DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; CREATE VIEW `cloud`.`storage_pool_view` AS - select + select storage_pool.id, storage_pool.uuid, storage_pool.name, @@ -915,7 +915,7 @@ CREATE VIEW `cloud`.`storage_pool_view` AS cluster.cluster_type, data_center.id data_center_id, data_center.uuid data_center_uuid, - data_center.name data_center_name, + data_center.name data_center_name, data_center.networktype data_center_type, host_pod_ref.id pod_id, host_pod_ref.uuid pod_uuid, @@ -945,11 +945,11 @@ CREATE VIEW `cloud`.`storage_pool_view` AS `cloud`.`async_job` ON async_job.instance_id = storage_pool.id and async_job.instance_type = 'StoragePool' and async_job.job_status = 0; - + DROP VIEW IF EXISTS `cloud`.`domain_router_view`; CREATE VIEW `cloud`.`domain_router_view` AS - select + select vm_instance.id id, vm_instance.name name, account.id account_id, @@ -1048,7 +1048,7 @@ CREATE VIEW `cloud`.`domain_router_view` AS `cloud`.`async_job` ON async_job.instance_id = vm_instance.id and async_job.instance_type = 'DomainRouter' and async_job.job_status = 0; - + CREATE TABLE `cloud`.`external_cisco_vnmc_devices` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `uuid` varchar(255) UNIQUE, @@ -1133,7 +1133,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag DROP VIEW IF EXISTS `cloud`.`service_offering_view`; CREATE VIEW `cloud`.`service_offering_view` AS - select + select service_offering.id, disk_offering.uuid, disk_offering.name, @@ -1180,7 +1180,7 @@ UPDATE `cloud_usage`.`account` SET `default`=1 WHERE id IN (1,2); UPDATE `cloud`.`user` SET `cloud`.`user`.`default`=1 WHERE id IN (1,2); ALTER VIEW `cloud`.`user_view` AS - select + select user.id, user.uuid, user.username, @@ -1220,7 +1220,7 @@ ALTER VIEW `cloud`.`user_view` AS `cloud`.`async_job` ON async_job.instance_id = user.id and async_job.instance_type = 'User' and async_job.job_status = 0; - + DROP VIEW IF EXISTS `cloud`.`account_view`; CREATE VIEW `cloud`.`account_view` AS @@ -1773,7 +1773,7 @@ ALTER TABLE `cloud`.`account_details` MODIFY value varchar(255); DROP VIEW IF EXISTS `cloud`.`template_view`; CREATE VIEW `cloud`.`template_view` AS - select + select vm_template.id, vm_template.uuid, vm_template.unique_name, @@ -1814,7 +1814,7 @@ CREATE VIEW `cloud`.`template_view` AS domain.path domain_path, projects.id project_id, projects.uuid project_uuid, - projects.name project_name, + projects.name project_name, data_center.id data_center_id, data_center.uuid data_center_uuid, data_center.name data_center_name, @@ -1844,23 +1844,23 @@ CREATE VIEW `cloud`.`template_view` AS from `cloud`.`vm_template` inner join - `cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id + `cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id inner join `cloud`.`account` ON account.id = vm_template.account_id inner join `cloud`.`domain` ON domain.id = account.domain_id left join - `cloud`.`projects` ON projects.project_account_id = account.id + `cloud`.`projects` ON projects.project_account_id = account.id left join - `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id + `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id left join - `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id + `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id left join `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and template_store_ref.store_role = 'Image' left join - `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id + `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id left join - `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null + `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null left join `cloud`.`data_center` ON (image_store.data_center_id = data_center.id OR template_zone_ref.zone_id = data_center.id) left join @@ -1868,7 +1868,7 @@ CREATE VIEW `cloud`.`template_view` AS left join `cloud`.`resource_tags` ON resource_tags.resource_id = vm_template.id and (resource_tags.resource_type = 'Template' or resource_tags.resource_type='ISO'); - + INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.apiserver.address', 'http://localhost:8081', 'Specify the address at which the Midonet API server can be contacted (if using Midonet)'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.providerrouter.id', 'd7c5e6a3-e2f4-426b-b728-b7ce6a0448e5', 'Specifies the UUID of the Midonet provider router (if using Midonet)'); @@ -1890,7 +1890,7 @@ CREATE TABLE `cloud`.`account_vnet_map` ( ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN account_vnet_map_id bigint unsigned; ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD CONSTRAINT `fk_op_dc_vnet_alloc__account_vnet_map_id` FOREIGN KEY `fk_op_dc_vnet_alloc__account_vnet_map_id` (`account_vnet_map_id`) REFERENCES `account_vnet_map` (`id`); - + update `cloud`.`vm_template` set state='Allocated' where state is NULL; update `cloud`.`vm_template` set update_count=0 where update_count is NULL; @@ -1994,7 +1994,7 @@ CREATE TABLE `cloud`.`vm_disk_statistics` ( CONSTRAINT `fk_vm_disk_statistics__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; -insert into `cloud`.`vm_disk_statistics`(data_center_id,account_id,vm_id,volume_id) +insert into `cloud`.`vm_disk_statistics`(data_center_id,account_id,vm_id,volume_id) select volumes.data_center_id, volumes.account_id, vm_instance.id, volumes.id from volumes,vm_instance where vm_instance.vm_type="User" and vm_instance.state<>"Expunging" and volumes.instance_id=vm_instance.id order by vm_instance.id; DROP TABLE IF EXISTS `cloud_usage`.`vm_disk_statistics`; @@ -2102,7 +2102,7 @@ CREATE TABLE `cloud`.`external_stratosphere_ssp_credentials` ( DROP VIEW IF EXISTS `cloud`.`project_view`; CREATE VIEW `cloud`.`project_view` AS - select + select projects.id, projects.uuid, projects.name, @@ -2151,7 +2151,6 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ldap.user.object', 'inetOrgPerson', 'Sets the object type of users within LDAP'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ldap.basedn', NULL, 'Sets the basedn for LDAP'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ldap.search.group.principle', NULL, 'Sets the principle of the group that users must be a member of'); -INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ldap.ssl.enabled', 'false', 'Enables/Disables SSL support for LDAP'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ldap.truststore', NULL, 'Sets the path to the truststore to use for LDAP SSL'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ldap.truststore.password', NULL, 'Sets the password for the truststore'); @@ -2166,7 +2165,7 @@ CREATE TABLE `cloud`.`ldap_configuration` ( INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.loadbalancer.haproxy.max.conn', '4096', 'Load Balancer(haproxy) maximum number of concurrent connections(global max)'); ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `concurrent_connections` int(10) unsigned COMMENT 'Load Balancer(haproxy) maximum number of concurrent connections(global max)'; - + ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size` smallint(6) NOT NULL DEFAULT '0' COMMENT 'number of items being processed by the queue'; ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size_limit` smallint(6) NOT NULL DEFAULT '1' COMMENT 'max number of items the queue can process concurrently'; diff --git a/ui/dictionary.jsp b/ui/dictionary.jsp index 24c7e5e1f57..88de8c0cc83 100644 --- a/ui/dictionary.jsp +++ b/ui/dictionary.jsp @@ -515,7 +515,7 @@ dictionary = { 'label.edit.lb.rule': '', 'label.edit.network.details': '', 'label.edit.project.details': '', -'label.edit.tags': '', +'label.edit.tags': '', 'label.edit.traffic.type': '', 'label.edit.vpc': '', 'label.egress.rule': '', diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index b2aa56b05ff..9ae3fd5b1e4 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -1341,7 +1341,7 @@ array1.push("&interval=" + args.data.interval); array1.push("&scaleuppolicyids=" + args.scaleUpPolicyResponse.id); array1.push("&scaledownpolicyids=" + args.scaleDownPolicyResponse.id); - + $.ajax({ url: createURL('createAutoScaleVmGroup' + array1.join("")), dataType: 'json', diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js index a9df8967943..bd932c71303 100644 --- a/ui/scripts/sharedFunctions.js +++ b/ui/scripts/sharedFunctions.js @@ -715,7 +715,7 @@ var addGuestNetworkDialog = { return result; } -// Role Functions + // Role Functions function isAdmin() { return (g_role == 1); diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 569e978817b..56eaec36f99 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -6488,11 +6488,13 @@ selectedZoneObj.vmwaredcId = vmwaredcs[0].id; } }, - error: function(XMLHttpResponse) { //override default error handling: cloudStack.dialog.notice({ message: parseXMLHttpResponse(XMLHttpResponse)}); - if(parseXMLHttpResponse(XMLHttpResponse) == 'The given command does not exist or it is not available for user') - return; //do nothing - else - cloudStack.dialog.notice({ message: parseXMLHttpResponse(XMLHttpResponse)}); //pop up error dialog box if the error is not 'The given command does not exist or it is not available for user' + error: function(XMLHttpResponse) { //override default error handling: cloudStack.dialog.notice({ message: parseXMLHttpResponse(XMLHttpResponse)}); + if (parseXMLHttpResponse(XMLHttpResponse) == 'The given command does not exist or it is not available for user') + return; //do nothing + else + cloudStack.dialog.notice({ + message: parseXMLHttpResponse(XMLHttpResponse) + }); //pop up error dialog box if the error is not 'The given command does not exist or it is not available for user' } }); @@ -7425,17 +7427,17 @@ var systemvmObjs = json.listsystemvmsresponse.systemvm; if (systemvmObjs != null) { $.ajax({ - url: createURL("listHosts&listAll=true"), + url: createURL("listHosts&listAll=true"), success: function(json) { var hostObjs = json.listhostsresponse.host; for (var i = 0; i < systemvmObjs.length; i++) { - for (var k = 0; k < hostObjs.length; k++) { - if (hostObjs[k].name == systemvmObjs[i].name) { - systemvmObjs[i].agentstate = hostObjs[k].state; - break; - } - } - } + for (var k = 0; k < hostObjs.length; k++) { + if (hostObjs[k].name == systemvmObjs[i].name) { + systemvmObjs[i].agentstate = hostObjs[k].state; + break; + } + } + } args.response.success({ data: systemvmObjs }); @@ -10125,7 +10127,7 @@ notification: { poll: pollAsyncJobResult, interval: 4500, - desc: "Dedicate Pod" + desc: "Dedicate Pod" }, data: item @@ -11201,7 +11203,7 @@ $.ajax({ url: createURL("addCluster" + array1.join("")), dataType: "json", - type: "POST", + type: "POST", success: function(json) { var item = json.addclusterresponse.cluster[0]; clusterId = json.addclusterresponse.cluster[0].id; @@ -14116,14 +14118,14 @@ label: 'label.url' } }, - dataProvider: function(args) { - $.ajax({ - url: createURL('listUcsManager'), - data: { - zoneid: args.context.physicalResources[0].id - }, - success: function(json) { - /* + dataProvider: function(args) { + $.ajax({ + url: createURL('listUcsManager'), + data: { + zoneid: args.context.physicalResources[0].id + }, + success: function(json) { + /* json = //override json (for testing only) { "listucsmanagerreponse": { @@ -14138,11 +14140,13 @@ ] } }; - */ - var items = json.listucsmanagerreponse.ucsmanager; - args.response.success({ data: items }); - } - }); + */ + var items = json.listucsmanagerreponse.ucsmanager; + args.response.success({ + data: items + }); + } + }); }, actions: { add: { @@ -14363,8 +14367,8 @@ "bladedn": "sys/chassis-1/blade-2" } } - } - */ + } + */ args.response.success({ data: { associatedProfileDn: args.data.profiledn diff --git a/ui/scripts/ui-custom/accountsWizard.js b/ui/scripts/ui-custom/accountsWizard.js index 628cc348dcf..88cff581ccb 100644 --- a/ui/scripts/ui-custom/accountsWizard.js +++ b/ui/scripts/ui-custom/accountsWizard.js @@ -97,7 +97,7 @@ dataType: "json", async: false, success: function(json) { - if(json.ldapuserresponse.count > 0) { + if (json.ldapuserresponse.count > 0) { $(json.ldapuserresponse.LdapUser).each(function() { var result = $(""); result.append(""); diff --git a/ui/scripts/ui-custom/installWizard.js b/ui/scripts/ui-custom/installWizard.js index f7ed074e774..de4c0df162a 100644 --- a/ui/scripts/ui-custom/installWizard.js +++ b/ui/scripts/ui-custom/installWizard.js @@ -767,9 +767,10 @@ label: 'label.provider', select: function(args) { args.response.success({ - data: [ - { id: 'NFS', description: 'NFS' } - ] + data: [{ + id: 'NFS', + description: 'NFS' + }] }); } }, diff --git a/ui/scripts/ui/dialog.js b/ui/scripts/ui/dialog.js index 1ff54013f4a..7042c9514c1 100644 --- a/ui/scripts/ui/dialog.js +++ b/ui/scripts/ui/dialog.js @@ -38,11 +38,11 @@ createForm: function(args) { var $formContainer = $('
').addClass('form-container'); var $form = $('
').appendTo($formContainer) - .submit(function() { - $(this).closest('.ui-dialog').find('button.ok').click(); + .submit(function() { + $(this).closest('.ui-dialog').find('button.ok').click(); - return false; - }); + return false; + }); var createLabel = _l(args.form.createLabel); // Description text @@ -130,10 +130,10 @@ var field = args.form.fields[key]; var $formItem = $('
') - .addClass('form-item') - .attr({ - rel: key - }); + .addClass('form-item') + .attr({ + rel: key + }); if (field.isHidden != null) { if (typeof(field.isHidden) == 'boolean' && field.isHidden == true) @@ -167,10 +167,10 @@ // Label field var $name = $('
').addClass('name') - .appendTo($formItem) - .append( - $('