You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ra...@apache.org on 2015/06/12 12:25:38 UTC
[1/3] git commit: updated refs/heads/master to 4900d15
Repository: cloudstack
Updated Branches:
refs/heads/master fd1ef5220 -> 4900d15e6
Fixed CLOUDSTACK-8551 Findbugs warning in LdapCreateAccountCmd.java
byte[].toString() would give reference to the array (ex: [B@6c521576 )
but not the original string. used new String() to get the text.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d46b658e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d46b658e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d46b658e
Branch: refs/heads/master
Commit: d46b658ec0a997d8e55cfc818dca2ad869447d46
Parents: 7ba2f22
Author: Rajani Karuturi <ra...@gmail.com>
Authored: Thu Jun 11 14:05:03 2015 +0530
Committer: Rajani Karuturi <ra...@gmail.com>
Committed: Thu Jun 11 14:05:03 2015 +0530
----------------------------------------------------------------------
.../api/command/LdapCreateAccountCmd.java | 5 +-
.../ldap/LdapCreateAccountCmdSpec.groovy | 205 ++++++++++---------
2 files changed, 111 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d46b658e/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
index d4564ff..1968f85 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
@@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.api.command;
+import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Map;
@@ -143,8 +144,8 @@ public class LdapCreateAccountCmd extends BaseCmd {
final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
final byte bytes[] = new byte[20];
randomGen.nextBytes(bytes);
- return Base64.encode(bytes).toString();
- } catch (final NoSuchAlgorithmException e) {
+ return new String(Base64.encode(bytes), "UTF-8");
+ } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password");
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d46b658e/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapCreateAccountCmdSpec.groovy
----------------------------------------------------------------------
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 5805e0b..c57cc78 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
@@ -37,120 +37,131 @@ import javax.naming.NamingException
class LdapCreateAccountCmdSpec extends spock.lang.Specification {
def "Test failure to retrive LDAP user"() {
- given: "We have an LdapManager, AccountService and LdapCreateAccountCmd and LDAP user that doesn't exist"
- LdapManager ldapManager = Mock(LdapManager)
- ldapManager.getUser(_) >> { throw new NoLdapUserMatchingQueryException() }
- AccountService accountService = Mock(AccountService)
- def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
- ldapCreateAccountCmd.getCurrentContext() >> Mock(CallContext)
- CallContext context = ldapCreateAccountCmd.getCurrentContext()
- when: "An an account is created"
- ldapCreateAccountCmd.execute()
- then: "It fails and an exception is thrown"
- thrown ServerApiException
+ given: "We have an LdapManager, AccountService and LdapCreateAccountCmd and LDAP user that doesn't exist"
+ LdapManager ldapManager = Mock(LdapManager)
+ ldapManager.getUser(_) >> { throw new NoLdapUserMatchingQueryException() }
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
+ ldapCreateAccountCmd.getCurrentContext() >> Mock(CallContext)
+ CallContext context = ldapCreateAccountCmd.getCurrentContext()
+ when: "An an account is created"
+ ldapCreateAccountCmd.execute()
+ then: "It fails and an exception is thrown"
+ thrown ServerApiException
}
- def "Test failed creation due to a null response from cloudstack account creater"() {
- given: "We have an LdapManager, AccountService and LdapCreateAccountCmd"
- LdapManager ldapManager = Mock(LdapManager)
- ldapManager.getUser(_) >> new LdapUser("rmurphy", "rmurphy@cloudstack.org", "Ryan", "Murphy", "cn=rmurphy,ou=engineering,dc=cloudstack,dc=org", "engineering")
- AccountService accountService = Mock(AccountService)
- def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
- ldapCreateAccountCmd.getCurrentContext() >> Mock(CallContext)
- ldapCreateAccountCmd.createCloudstackUserAccount(_) >> null
- when: "Cloudstack fail to create the user"
- ldapCreateAccountCmd.execute()
- then: "An exception is thrown"
- thrown ServerApiException
- }
+ def "Test failed creation due to a null response from cloudstack account creater"() {
+ given: "We have an LdapManager, AccountService and LdapCreateAccountCmd"
+ LdapManager ldapManager = Mock(LdapManager)
+ ldapManager.getUser(_) >> new LdapUser("rmurphy", "rmurphy@cloudstack.org", "Ryan", "Murphy", "cn=rmurphy,ou=engineering,dc=cloudstack,dc=org", "engineering")
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
+ ldapCreateAccountCmd.getCurrentContext() >> Mock(CallContext)
+ ldapCreateAccountCmd.createCloudstackUserAccount(_) >> null
+ when: "Cloudstack fail to create the user"
+ ldapCreateAccountCmd.execute()
+ then: "An exception is thrown"
+ thrown ServerApiException
+ }
def "Test command name"() {
- given: "We have an LdapManager, AccountService and LdapCreateAccountCmd"
- LdapManager ldapManager = Mock(LdapManager)
- AccountService accountService = Mock(AccountService)
- def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
- when: "Get command name is called"
- def result = ldapCreateAccountCmd.getCommandName()
- then: "createaccountresponse is returned"
- result == "createaccountresponse"
+ given: "We have an LdapManager, AccountService and LdapCreateAccountCmd"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
+ when: "Get command name is called"
+ def result = ldapCreateAccountCmd.getCommandName()
+ then: "createaccountresponse is returned"
+ result == "createaccountresponse"
}
def "Test getEntityOwnerId is 1"() {
- given: "We have an LdapManager, AccountService andL dapCreateAccount"
- LdapManager ldapManager = Mock(LdapManager)
- AccountService accountService = Mock(AccountService)
-
- def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
- when: "Get entity owner id is called"
- long ownerId = ldapCreateAccountCmd.getEntityOwnerId()
- then: "1 is returned"
- ownerId == 1
+ given: "We have an LdapManager, AccountService andL dapCreateAccount"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+
+ def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
+ when: "Get entity owner id is called"
+ long ownerId = ldapCreateAccountCmd.getEntityOwnerId()
+ then: "1 is returned"
+ ownerId == 1
}
def "Test password generation"() {
- given: "We have an LdapManager, AccountService and LdapCreateAccountCmd"
- LdapManager ldapManager = Mock(LdapManager)
- AccountService accountService = Mock(AccountService)
- def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
- when: "A password is generated"
- def result = ldapCreateAccountCmd.generatePassword()
- then: "The result shouldn't be null or empty"
- result != ""
- result != null
- }
+ given: "We have an LdapManager, AccountService and LdapCreateAccountCmd"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
+ when: "A password is generated"
+ def result = ldapCreateAccountCmd.generatePassword()
+ then: "The result shouldn't be null or empty"
+ result != ""
+ result != null
+ }
def "Test validate User"() {
- given: "We have an LdapManager, AccountService andL dapCreateAccount"
- LdapManager ldapManager = Mock(LdapManager)
- AccountService accountService = Mock(AccountService)
- def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService);
- when: "a user with an username, email, firstname and lastname is validated"
- def result = ldapCreateAccountCmd.validateUser(new LdapUser("username","email","firstname","lastname","principal","domain"))
- then: "the result is true"
- result == true
- }
+ given: "We have an LdapManager, AccountService andL dapCreateAccount"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService);
+ when: "a user with an username, email, firstname and lastname is validated"
+ def result = ldapCreateAccountCmd.validateUser(new LdapUser("username", "email", "firstname", "lastname", "principal", "domain"))
+ 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 ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
- when: "A user with no email address attempts to validate"
- ldapCreateAccountCmd.validateUser(new LdapUser("username",null,"firstname","lastname","principal","domain"))
- then: "An exception is thrown"
- thrown Exception
- }
+ given: "We have an LdapManager, AccountService andL dapCreateAccount"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
+ when: "A user with no email address attempts to validate"
+ ldapCreateAccountCmd.validateUser(new LdapUser("username", null, "firstname", "lastname", "principal", "domain"))
+ 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 ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
- when: "A user with no firstname attempts to validate"
- ldapCreateAccountCmd.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 LdapCreateAccountCmd"
- LdapManager ldapManager = Mock(LdapManager)
- AccountService accountService = Mock(AccountService)
- def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
- when: "A user with no lastname attempts to validate"
- ldapCreateAccountCmd.validateUser(new LdapUser("username","email","firstname",null,"principal","domain"))
- then: "An exception is thown"
- thrown Exception
- }
+ given: "We have an LdapManager, AccountService andL dapCreateAccount"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
+ when: "A user with no firstname attempts to validate"
+ ldapCreateAccountCmd.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 LdapCreateAccountCmd"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
+ when: "A user with no lastname attempts to validate"
+ ldapCreateAccountCmd.validateUser(new LdapUser("username", "email", "firstname", null, "principal", "domain"))
+ 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 ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
- when: "Get command name is called"
- def commandName = ldapCreateAccountCmd.getCommandName()
- then: "createaccountresponse is returned"
- commandName == "createaccountresponse"
+ given: "We have an LdapManager, AccountService andL dapCreateAccount"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = Spy(LdapCreateAccountCmd, constructorArgs: [ldapManager, accountService])
+ when: "Get command name is called"
+ def commandName = ldapCreateAccountCmd.getCommandName()
+ then: "createaccountresponse is returned"
+ commandName == "createaccountresponse"
+ }
+
+ def "Test generate password"() {
+ given: "We have an LdapManager, AccountService and LdapCreateAccount"
+ LdapManager ldapManager = Mock(LdapManager)
+ AccountService accountService = Mock(AccountService)
+ def ldapCreateAccountCmd = new LdapCreateAccountCmd(ldapManager, accountService)
+ when: "A random password is generated for a new account"
+ String password = ldapCreateAccountCmd.generatePassword()
+ then: "password should not be the array address but an actual encoded string. verifying length > 20 as the byte array size is 20"
+ password.length() > 20
}
}
[3/3] git commit: updated refs/heads/master to 4900d15
Posted by ra...@apache.org.
Merge branch 'CLOUDSTACK-8551' of https://github.com/karuturi/cloudstack
This closes #388
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4900d15e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4900d15e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4900d15e
Branch: refs/heads/master
Commit: 4900d15e6c6bdc8ef321dc1c56da2c33a9b6ce79
Parents: fd1ef52 d504305
Author: Rajani Karuturi <ra...@gmail.com>
Authored: Fri Jun 12 15:53:08 2015 +0530
Committer: Rajani Karuturi <ra...@gmail.com>
Committed: Fri Jun 12 15:53:08 2015 +0530
----------------------------------------------------------------------
.../api/command/LdapCreateAccountCmd.java | 5 +-
.../api/command/LdapImportUsersCmd.java | 6 +-
.../ldap/LdapCreateAccountCmdSpec.groovy | 205 ++++++++++---------
3 files changed, 114 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
[2/3] git commit: updated refs/heads/master to 4900d15
Posted by ra...@apache.org.
Fixed CLOUDSTACK-8551 findbugs issue in LdapImportUsersCmd.java
DM_DEFAULT_ENCODING issue. Used UTF-8
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d504305a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d504305a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d504305a
Branch: refs/heads/master
Commit: d504305a982c493a256ac463937dc1c3139ac30a
Parents: d46b658
Author: Rajani Karuturi <ra...@gmail.com>
Authored: Thu Jun 11 17:07:03 2015 +0530
Committer: Rajani Karuturi <ra...@gmail.com>
Committed: Thu Jun 11 17:07:03 2015 +0530
----------------------------------------------------------------------
.../org/apache/cloudstack/api/command/LdapImportUsersCmd.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d504305a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java
index b6c8656..63549f1 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapImportUsersCmd.java
@@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.api.command;
+import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
@@ -228,9 +229,8 @@ public class LdapImportUsersCmd extends BaseListCmd {
final SecureRandom randomGen = SecureRandom.getInstance("SHA1PRNG");
final byte bytes[] = new byte[20];
randomGen.nextBytes(bytes);
- String encodedPassword = new String(Base64.encode(bytes));
- return encodedPassword;
- } catch (final NoSuchAlgorithmException e) {
+ return new String(Base64.encode(bytes), "UTF-8");
+ } catch ( NoSuchAlgorithmException | UnsupportedEncodingException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate random password");
}
}