Skip to content

Commit f17892a

Browse files
review: introduced test for null values and checkPlainPassword() method
1 parent 76a24b2 commit f17892a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

fe/fe-core/src/test/java/org/apache/doris/mysql/authenticate/ldap/LdapAuthenticatorTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.junit.Before;
3434
import org.junit.Test;
3535

36+
import static org.junit.jupiter.api.Assertions.assertThrows;
37+
3638
import java.io.IOException;
3739
import java.util.List;
3840

@@ -165,6 +167,53 @@ public void testEmptyPassword() throws IOException {
165167
Assert.assertFalse(response.isSuccess());
166168
}
167169

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+
168217
@After
169218
public void tearDown() {
170219
LdapConfig.ldap_allow_empty_pass = true; // restoring default value for other tests

0 commit comments

Comments
 (0)