@@ -37,6 +37,59 @@ class LdapAuthenticatorSpec extends spock.lang.Specification {
3737 result == false
3838 }
3939
40+ def " Test a failed authentication due to empty username" () {
41+ given : " We have an LdapManager, userAccountDao and ldapAuthenticator and the user doesn't exist within cloudstack."
42+ LdapManager ldapManager = Mock (LdapManager )
43+ ldapManager. isLdapEnabled() >> true
44+ ldapManager. canAuthenticate(_, _) >> true
45+
46+ UserAccountDao userAccountDao = Mock (UserAccountDao )
47+ userAccountDao. getUserAccount(_, _) >> new UserAccountVO ()
48+
49+ def ldapAuthenticator = new LdapAuthenticator (ldapManager, userAccountDao)
50+
51+ when : " A user authenticates"
52+ def result = ldapAuthenticator. authenticate(" " , " password" , 0 , null )
53+ then : " their authentication fails"
54+ result. first() == false
55+
56+ when : " A user authenticates"
57+ result = ldapAuthenticator. authenticate(null , " password" , 0 , null )
58+ then : " their authentication fails"
59+ result. first() == false
60+
61+ when : " A user authenticates"
62+ result = ldapAuthenticator. authenticate(null , null , 0 , null )
63+ then : " their authentication fails"
64+ result. first() == false
65+
66+ when : " A user authenticates"
67+ result = ldapAuthenticator. authenticate(" " , " " , 0 , null )
68+ then : " their authentication fails"
69+ result. first() == false
70+ }
71+
72+ def " Test failed authentication due to empty password" () {
73+ given : " We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator"
74+ def ldapManager = Mock (LdapManager )
75+ ldapManager. isLdapEnabled() >> true
76+ ldapManager. canAuthenticate(_, _) >> true
77+
78+ UserAccountDao userAccountDao = Mock (UserAccountDao )
79+ userAccountDao. getUserAccount(_, _) >> new UserAccountVO ()
80+ def ldapAuthenticator = new LdapAuthenticator (ldapManager, userAccountDao)
81+
82+ when : " The user authenticates with empty password"
83+ def result = ldapAuthenticator. authenticate(" rmurphy" , " " , 0 , null )
84+ then : " their authentication fails"
85+ result. first() == false
86+
87+ when : " The user authenticates with null password"
88+ result = ldapAuthenticator. authenticate(" rmurphy" , null , 0 , null )
89+ then : " their authentication fails"
90+ result. first() == false
91+ }
92+
4093 def " Test failed authentication due to ldap bind being unsuccessful" () {
4194 given : " We have an LdapManager, LdapConfiguration, userAccountDao and LdapAuthenticator"
4295 def ldapManager = Mock (LdapManager )
0 commit comments