Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 70E70189D7 for ; Sat, 5 Sep 2015 04:02:43 +0000 (UTC) Received: (qmail 66802 invoked by uid 500); 5 Sep 2015 04:02:42 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 66591 invoked by uid 500); 5 Sep 2015 04:02:42 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 66029 invoked by uid 99); 5 Sep 2015 04:02:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Sep 2015 04:02:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BECA1E0571; Sat, 5 Sep 2015 04:02:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rajani@apache.org To: commits@cloudstack.apache.org Date: Sat, 05 Sep 2015 04:02:50 -0000 Message-Id: <71d4f23d894e450785de9de72d7b225c@git.apache.org> In-Reply-To: <9cc473e2a1dd4e46a387d1797058479f@git.apache.org> References: <9cc473e2a1dd4e46a387d1797058479f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/17] git commit: updated refs/heads/master to 5881035 CLOUDSTACK-8647: formatted LdapAuthenticatorSpec Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c2b36cb7 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c2b36cb7 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c2b36cb7 Branch: refs/heads/master Commit: c2b36cb7059e91f6f5e9292cda4bb283017708cc Parents: 36340d9 Author: Rajani Karuturi Authored: Thu Aug 27 16:18:47 2015 +0530 Committer: Rajani Karuturi Committed: Thu Aug 27 17:34:02 2015 +0530 ---------------------------------------------------------------------- .../ldap/LdapAuthenticatorSpec.groovy | 104 +++++++++---------- 1 file changed, 52 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2b36cb7/plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapAuthenticatorSpec.groovy ---------------------------------------------------------------------- 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 e38a031..435f972 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 @@ -27,80 +27,80 @@ import org.apache.cloudstack.ldap.LdapUser class LdapAuthenticatorSpec extends spock.lang.Specification { def "Test a failed authentication due to user not being found within cloudstack"() { - given: "We have an LdapManager, userAccountDao and ldapAuthenticator and the user doesn't exist within cloudstack." + 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: "A user authentications" + when: "A user authentications" def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - then: "their authentication fails" - result.first() == false + then: "their authentication fails" + result.first() == false } def "Test failed authentication due to ldap bind being unsuccessful"() { - given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator" - def ldapManager = Mock(LdapManager) - def ldapUser = Mock(LdapUser) - ldapUser.isDisabled() >> false - ldapManager.isLdapEnabled() >> true - ldapManager.getUser("rmurphy") >> ldapUser - ldapManager.canAuthenticate(_, _) >> false + given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator" + def ldapManager = Mock(LdapManager) + def ldapUser = Mock(LdapUser) + ldapUser.isDisabled() >> false + ldapManager.isLdapEnabled() >> true + ldapManager.getUser("rmurphy") >> ldapUser + 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: "The user authenticates with an incorrect password" + def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - then: "their authentication fails" - result.first() == false + then: "their authentication fails" + result.first() == 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 + 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() + 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.first() == false + def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) + when: "The user authenticates" + def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) + then: "their authentication fails" + result.first() == false } - def "Test successful authentication"() { - given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator" - def ldapManager = Mock(LdapManager) - def ldapUser = Mock(LdapUser) - ldapUser.isDisabled() >> false - ldapManager.isLdapEnabled() >> true - ldapManager.canAuthenticate(_, _) >> true - ldapManager.getUser("rmurphy") >> ldapUser + def "Test successful authentication"() { + given: "We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator" + def ldapManager = Mock(LdapManager) + def ldapUser = Mock(LdapUser) + ldapUser.isDisabled() >> false + ldapManager.isLdapEnabled() >> true + ldapManager.canAuthenticate(_, _) >> true + ldapManager.getUser("rmurphy") >> ldapUser - 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: "The user authenticates with an incorrect password" + def result = ldapAuthenticator.authenticate("rmurphy", "password", 0, null) - then: "their authentication passes" - result.first() == true - } + then: "their authentication passes" + result.first() == true + } def "Test that encode doesn't change the input"() { - given: "We have an LdapManager, userAccountDao and LdapAuthenticator" - LdapManager ldapManager = Mock(LdapManager) - UserAccountDao userAccountDao = Mock(UserAccountDao) - def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) - when: "a users password is encoded" - def result = ldapAuthenticator.encode("password") - then: "it doesn't change" - result == "password" + given: "We have an LdapManager, userAccountDao and LdapAuthenticator" + LdapManager ldapManager = Mock(LdapManager) + UserAccountDao userAccountDao = Mock(UserAccountDao) + def ldapAuthenticator = new LdapAuthenticator(ldapManager, userAccountDao) + when: "a users password is encoded" + def result = ldapAuthenticator.encode("password") + then: "it doesn't change" + result == "password" } }