-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[enhance](auth) introduction of configuration property to prohibit login with empty LDAP password #61440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iaorekhov-1980
wants to merge
47
commits into
apache:master
Choose a base branch
from
iaorekhov-1980:feat/disable_ldap_empty_pass
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[enhance](auth) introduction of configuration property to prohibit login with empty LDAP password #61440
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
156c2fe
feat: add property to manage usage of empty pass for login
iaorekhov-1980 95ad00c
:
iaorekhov-1980 16c20ee
fix: fixing indentation
iaorekhov-1980 59c509c
fix: fix indentation
iaorekhov-1980 624c1cd
fix: improve test to restore property before test
iaorekhov-1980 1bd81e5
fix import order
iaorekhov-1980 1cc2f09
review: introduced changes suggested by copilot review
iaorekhov-1980 7be33e0
review: line was too long
iaorekhov-1980 01c9032
review: indentantion was fixed
iaorekhov-1980 ac6288d
review: introduced test for null values and checkPlainPassword() method
iaorekhov-1980 3752fb7
review: fix indents and imports
iaorekhov-1980 41c0f46
review: fix indents and imports
iaorekhov-1980 d104162
review: fix indents and imports v2
iaorekhov-1980 894618b
review: fixed imports v2
iaorekhov-1980 4ae7c48
review: fixed imports v3
iaorekhov-1980 b6fc118
review: fixed imports v3
iaorekhov-1980 19bdc4a
review: tests reworked v1
iaorekhov-1980 eed46fe
review: tests reworked v3
iaorekhov-1980 c2fc809
review: fixed imports v4
iaorekhov-1980 8fb47a5
review: fix tests for plain auth
iaorekhov-1980 8e28fb4
review: fix tests for plain auth v2
iaorekhov-1980 c5163f5
review: fix tests for plain auth v3
iaorekhov-1980 455cc18
review: fix tests for plain auth v4
iaorekhov-1980 335c3fd
review: fix tests for plain auth v4
iaorekhov-1980 434d325
review: fix tests for plain auth v5
iaorekhov-1980 1c4136a
review: fix tests for plain auth v6
iaorekhov-1980 174612e
review: fix tests for plain auth v7 - without mutable
iaorekhov-1980 1c3b4c3
review: fix tests for plain auth v7 - with mutable and junit5
iaorekhov-1980 411f5b5
review: fix tests for plain auth v8 - without spaces
iaorekhov-1980 501370e
fixing imports after rebase
iaorekhov-1980 e906e09
fixing tests to new mock framework after rebase
iaorekhov-1980 d6c2c30
fixing tests to new mock framework after rebase
iaorekhov-1980 84e3ee7
fixing imports after rebase
iaorekhov-1980 02fbec8
test: changed test approach for mockito
iaorekhov-1980 7c689f6
test: changed test approach for mockito v2
iaorekhov-1980 ff6e23c
test: changed test approach for mockito v3
iaorekhov-1980 05452e7
test: added debug
iaorekhov-1980 eb3dfe2
test: added debug v2
iaorekhov-1980 e191cc6
test: changed test approach for mockito v3 - correct method mocked
iaorekhov-1980 343022a
test: changed test approach for mockito v3 - correct method mocked v2
iaorekhov-1980 bfa93c3
test: changed test approach for mockito v3 - correct method mocked v3
iaorekhov-1980 08a436a
test: changed test approach for mockito v3 - correct method mocked v4
iaorekhov-1980 ea7eb0c
test: changed test approach for mockito v3 - use getLdapManager inste…
iaorekhov-1980 e168964
test: changed test approach for mockito v3 - refactor v1
iaorekhov-1980 f61764c
review: extra test case added
iaorekhov-1980 49f6f69
review: extra test case added v1
iaorekhov-1980 df9e737
review: extra test case added
iaorekhov-1980 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...src/test/java/org/apache/doris/mysql/privilege/PlainAuthWithEmptyPasswordAndLdapTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.doris.mysql.privilege; | ||
|
|
||
| import org.apache.doris.catalog.Env; | ||
| import org.apache.doris.common.AuthenticationException; | ||
| import org.apache.doris.common.LdapConfig; | ||
| import org.apache.doris.mysql.authenticate.ldap.LdapManager; | ||
| import org.apache.doris.utframe.TestWithFeService; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
|
|
||
|
|
||
| public class PlainAuthWithEmptyPasswordAndLdapTest extends TestWithFeService { | ||
| private static final String IP = "192.168.1.1"; | ||
|
|
||
| private LdapManager ldapManager = Mockito.mock(LdapManager.class); | ||
| private MockedStatic<Env> mockedEnv; | ||
|
|
||
| @Test | ||
| public void testPlainPasswordAuthWithAllowEmptyPassDefault() throws Exception { | ||
| //running test with non-specified value - ldap_allow_empty_pass should be true | ||
| //non empty pass - success | ||
| Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); | ||
| Env.getCurrentEnv().getAuth().checkPlainPassword("user1.2", IP, "testPass", null); | ||
| //empty pass - success | ||
| Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); | ||
| Env.getCurrentEnv().getAuth().checkPlainPassword("user1.1", IP, "", null); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testPlainPasswordAuthWithAllowEmptyPassTrue() throws Exception { | ||
| //running test with specified value - ldap_allow_empty_pass is be true | ||
| LdapConfig.ldap_allow_empty_pass = true; | ||
|
|
||
| //non empty pass - success | ||
| Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); | ||
| Env.getCurrentEnv().getAuth().checkPlainPassword("user2.2", IP, "testPass", null); | ||
| //empty pass - success | ||
| Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); | ||
| Env.getCurrentEnv().getAuth().checkPlainPassword("user2.1", IP, "", null); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPlainPasswordAuthWithAllowEmptyPassFalse() throws Exception { | ||
| //running test with specified value - ldap_allow_empty_pass is false | ||
| LdapConfig.ldap_allow_empty_pass = false; | ||
|
|
||
| //empty pass - failure | ||
| Assertions.assertFalse(LdapConfig.ldap_allow_empty_pass); | ||
| Assertions.assertThrows(AuthenticationException.class, () -> { | ||
| Env.getCurrentEnv().getAuth().checkPlainPassword("user3.1", IP, "", null); | ||
| }); | ||
|
|
||
| //non empty pass - success | ||
| Assertions.assertFalse(LdapConfig.ldap_allow_empty_pass); | ||
| Env.getCurrentEnv().getAuth().checkPlainPassword("user3.2", IP, "testPass", null); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| System.out.println("4.0 [" + LdapConfig.ldap_allow_empty_pass + "]"); | ||
| LdapConfig.ldap_allow_empty_pass = true; // restoring default value for other tests | ||
| mockedEnv.close(); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| LdapConfig.ldap_allow_empty_pass = true; // restoring default value for other tests | ||
| Auth realAuth = Env.getCurrentEnv().getAuth(); | ||
|
|
||
| mockedEnv = Mockito.mockStatic(Env.class); | ||
| Env mockedEnvInstance = Mockito.mock(Env.class); | ||
|
|
||
| Auth authSpy = Mockito.spy(realAuth); | ||
|
|
||
| Mockito.when(ldapManager.doesUserExist(Mockito.anyString())).thenReturn(true); | ||
| Mockito.when(ldapManager.checkUserPasswd( | ||
| Mockito.anyString(), Mockito.anyString(), | ||
| Mockito.anyString(), Mockito.any())).thenReturn(true); | ||
|
|
||
| Mockito.when(authSpy.getLdapManager()).thenReturn(ldapManager); | ||
|
|
||
| Mockito.when(mockedEnvInstance.getAuth()).thenReturn(authSpy); | ||
| mockedEnv.when(Env::getCurrentEnv).thenReturn(mockedEnvInstance); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.