|
33 | 33 | import org.junit.Before; |
34 | 34 | import org.junit.Test; |
35 | 35 |
|
| 36 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 37 | + |
36 | 38 | import java.io.IOException; |
37 | 39 | import java.util.List; |
38 | 40 |
|
@@ -165,6 +167,53 @@ public void testEmptyPassword() throws IOException { |
165 | 167 | Assert.assertFalse(response.isSuccess()); |
166 | 168 | } |
167 | 169 |
|
| 170 | + @Test |
| 171 | + public void testNullPassword() throws IOException { |
| 172 | + setCheckPassword(true); |
| 173 | + setGetUserInDoris(true); |
| 174 | + AuthenticateRequest request = new AuthenticateRequest(USER_NAME, new ClearPassword(null), IP); |
| 175 | + //according to LdapManager:106 - login with null password is prohibitted at all |
| 176 | + //need to validate that with all possible options - login with null password is not allowed |
| 177 | + //test with default value - ldap_allow_empty_pass is true, password is null => no login |
| 178 | + AuthenticateResponse response = ldapAuthenticator.authenticate(request); |
| 179 | + Assert.assertFalse(response.isSuccess()); |
| 180 | + //test with true value - ldap_allow_empty_pass is true, password is null => no login |
| 181 | + LdapConfig.ldap_allow_empty_pass = true; |
| 182 | + response = ldapAuthenticator.authenticate(request); |
| 183 | + Assert.assertFalse(response.isSuccess()); |
| 184 | + //test with false value - ldap_allow_empty_pass is false, password is null => no login |
| 185 | + LdapConfig.ldap_allow_empty_pass = false; |
| 186 | + response = ldapAuthenticator.authenticate(request); |
| 187 | + Assert.assertFalse(response.isSuccess()); |
| 188 | + } |
| 189 | + |
| 190 | + @Test |
| 191 | + public void testAuthCheckPlainPasswordWithEmptyPassword() throws Exception { |
| 192 | + setLdapUserExist(true); |
| 193 | + setCheckPassword(true); |
| 194 | + |
| 195 | + //test default (ldap_allow_empty_pass=true) and empty pass: login is allowed |
| 196 | + Auth.checkPlainPassword(USER_NAME, IP, "", null); |
| 197 | + |
| 198 | + //test with true and empty pass: login is allowed |
| 199 | + LdapConfig.ldap_allow_empty_pass = true; |
| 200 | + Auth.checkPlainPassword(USER_NAME, IP, "", null); |
| 201 | + |
| 202 | + //test with true value and non-empty pass: login is allowed |
| 203 | + LdapConfig.ldap_allow_empty_pass = true; |
| 204 | + Auth.checkPlainPassword(USER_NAME, IP, "testPass", null); |
| 205 | + |
| 206 | + //test with false and empty pass: login is not allowed |
| 207 | + LdapConfig.ldap_allow_empty_pass = false; |
| 208 | + assertThrows(AuthenticationException.class, () -> { |
| 209 | + Auth.checkPlainPassword(USER_NAME, IP, "", null); |
| 210 | + }); |
| 211 | + |
| 212 | + //test with false value and non-empty pass: login is allowed |
| 213 | + LdapConfig.ldap_allow_empty_pass = false; |
| 214 | + Auth.checkPlainPassword(USER_NAME, IP, "testPass", null); |
| 215 | + } |
| 216 | + |
168 | 217 | @After |
169 | 218 | public void tearDown() { |
170 | 219 | LdapConfig.ldap_allow_empty_pass = true; // restoring default value for other tests |
|
0 commit comments