|
25 | 25 |
|
26 | 26 | import mockit.Expectations; |
27 | 27 | import mockit.Mocked; |
28 | | -import org.junit.After; |
29 | | -import org.junit.Assert; |
30 | | -import org.junit.Before; |
| 28 | +import org.junit.jupiter.api.AfterEach; |
31 | 29 | import org.junit.jupiter.api.Assertions; |
| 30 | +import org.junit.jupiter.api.BeforeEach; |
32 | 31 | import org.junit.jupiter.api.Test; |
33 | 32 |
|
34 | 33 | public class PlainAuthWithEmptyPasswordAndLdapTest extends TestWithFeService { |
@@ -58,73 +57,63 @@ private void setCheckPassword(boolean res) { |
58 | 57 | } |
59 | 58 |
|
60 | 59 | @Test |
61 | | - public void testPlainPasswordAuthWithNonEmptyPassword() throws Exception { |
62 | | - System.out.println("1.0 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
| 60 | + public void testPlainPasswordAuthWithAllowEmptyPassDefault() throws Exception { |
63 | 61 | setLdapUserExist(true); |
64 | 62 | setCheckPassword(true); |
65 | 63 |
|
66 | | - //test with true value and non-empty pass: login is allowed |
67 | | - LdapConfig.ldap_allow_empty_pass = true; |
68 | | - Assert.assertTrue(LdapConfig.ldap_allow_empty_pass); |
69 | | - System.out.println("1.1 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
70 | | - Env.getCurrentEnv().getAuth().checkPlainPassword("user1.1", IP, "testPass", null); |
71 | | - |
72 | | - //test with false value and non-empty pass: login is allowed |
73 | | - LdapConfig.ldap_allow_empty_pass = false; |
74 | | - Assert.assertFalse(LdapConfig.ldap_allow_empty_pass); |
75 | | - System.out.println("1.2 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
| 64 | + //running test with non-specified value - ldap_allow_empty_pass should be true |
| 65 | + //empty pass - success |
| 66 | + Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); |
| 67 | + Env.getCurrentEnv().getAuth().checkPlainPassword("user1.1", IP, "", null); |
| 68 | + //non empty pass - success |
| 69 | + Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); |
76 | 70 | Env.getCurrentEnv().getAuth().checkPlainPassword("user1.2", IP, "testPass", null); |
77 | 71 | } |
78 | 72 |
|
79 | 73 |
|
80 | 74 | @Test |
81 | | - public void testPlainPasswordAuthWithEmptyPasswordAllowed() throws Exception { |
82 | | - System.out.println("2.0 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
| 75 | + public void testPlainPasswordAuthWithAllowEmptyPassTrue() throws Exception { |
83 | 76 | setLdapUserExist(true); |
84 | 77 | setCheckPassword(true); |
85 | 78 |
|
86 | | - System.out.println("2.1 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
87 | | - //test default (ldap_allow_empty_pass=true) and empty pass: login is allowed |
88 | | - Assert.assertTrue(LdapConfig.ldap_allow_empty_pass); |
| 79 | + //running test with specified value - ldap_allow_empty_pass is be true |
| 80 | + LdapConfig.ldap_allow_empty_pass = true; |
| 81 | + |
| 82 | + //empty pass - success |
| 83 | + Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); |
89 | 84 | Env.getCurrentEnv().getAuth().checkPlainPassword("user2.1", IP, "", null); |
90 | 85 |
|
91 | | - //test with true and empty pass: login is allowed |
92 | | - LdapConfig.ldap_allow_empty_pass = true; |
93 | | - System.out.println("2.2 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
94 | | - Assert.assertTrue(LdapConfig.ldap_allow_empty_pass); |
95 | | - Env.getCurrentEnv().getAuth().checkPlainPassword("user2.2", IP, "", null); |
| 86 | + //non empty pass - success |
| 87 | + Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass); |
| 88 | + Env.getCurrentEnv().getAuth().checkPlainPassword("user2.2", IP, "testPass", null); |
96 | 89 | } |
97 | 90 |
|
98 | 91 | @Test |
99 | | - public void testPlainPasswordAuthWithEmptyPasswordProhibitted() throws Exception { |
100 | | - System.out.println("3.0 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
| 92 | + public void testPlainPasswordAuthWithAllowEmptyPassFalse() throws Exception { |
101 | 93 | setLdapUserExist(true); |
102 | 94 | setCheckPassword(true); |
103 | 95 |
|
104 | | - //test with false and empty pass: login is not allowed |
| 96 | + //running test with specified value - ldap_allow_empty_pass is false |
105 | 97 | LdapConfig.ldap_allow_empty_pass = false; |
106 | | - System.out.println("3.1 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
107 | | - Assert.assertFalse(LdapConfig.ldap_allow_empty_pass); |
108 | | - Assertions.assertThrows(AuthenticationException.class, () -> { |
109 | | - Env.getCurrentEnv().getAuth().checkPlainPassword("user3.1", IP, null, null); |
110 | | - }); |
111 | 98 |
|
112 | | - //test with false and null pass: login is not allowed |
113 | | - LdapConfig.ldap_allow_empty_pass = false; |
114 | | - System.out.println("3.2 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
115 | | - Assert.assertFalse(LdapConfig.ldap_allow_empty_pass); |
| 99 | + //empty pass - failure |
| 100 | + Assertions.assertFalse(LdapConfig.ldap_allow_empty_pass); |
116 | 101 | Assertions.assertThrows(AuthenticationException.class, () -> { |
117 | | - Env.getCurrentEnv().getAuth().checkPlainPassword("user3.2", IP, "", null); |
| 102 | + Env.getCurrentEnv().getAuth().checkPlainPassword("user3.1", IP, "", null); |
118 | 103 | }); |
| 104 | + |
| 105 | + //non empty pass - success |
| 106 | + Assertions.assertFalse(LdapConfig.ldap_allow_empty_pass); |
| 107 | + Env.getCurrentEnv().getAuth().checkPlainPassword("user3.2", IP, "testPass", null); |
119 | 108 | } |
120 | 109 |
|
121 | | - @After |
| 110 | + @AfterEach |
122 | 111 | public void tearDown() { |
123 | 112 | System.out.println("4.0 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
124 | 113 | LdapConfig.ldap_allow_empty_pass = true; // restoring default value for other tests |
125 | 114 | } |
126 | 115 |
|
127 | | - @Before |
| 116 | + @BeforeEach |
128 | 117 | public void setUp() { |
129 | 118 | System.out.println("5.0 [" + LdapConfig.ldap_allow_empty_pass + "]"); |
130 | 119 | LdapConfig.ldap_allow_empty_pass = true; //restoring default value for other tests |
|
0 commit comments