This is an automated email from the ASF dual-hosted git repository.

dhavalshah9131 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new 2fcef7bae RANGER-5368:Improve unit test for TestPamLoginModule (#700)
2fcef7bae is described below

commit 2fcef7bae90dd97ade501874e5626ab5a857a687
Author: Bhaavesh Amol Amre <[email protected]>
AuthorDate: Fri Oct 24 19:03:25 2025 +0530

    RANGER-5368:Improve unit test for TestPamLoginModule (#700)
---
 .../unix/jaas/TestPamLoginModule.java              | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git 
a/unixauthclient/src/test/java/org/apache/ranger/authentication/unix/jaas/TestPamLoginModule.java
 
b/unixauthclient/src/test/java/org/apache/ranger/authentication/unix/jaas/TestPamLoginModule.java
index 22cc637ef..851e13688 100644
--- 
a/unixauthclient/src/test/java/org/apache/ranger/authentication/unix/jaas/TestPamLoginModule.java
+++ 
b/unixauthclient/src/test/java/org/apache/ranger/authentication/unix/jaas/TestPamLoginModule.java
@@ -23,6 +23,7 @@
 import org.junit.jupiter.api.TestMethodOrder;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.jvnet.libpam.PAM;
+import org.jvnet.libpam.PAMException;
 import org.jvnet.libpam.UnixUser;
 import org.mockito.Mockito;
 import org.mockito.junit.jupiter.MockitoExtension;
@@ -96,16 +97,31 @@ public void 
test02_commit_addsPrincipal_and_logout_clears_without_realPam() thro
     }
 
     @Test
-    public void test03_login_throwsLoginException_withRealPam() throws 
Exception {
+    public void test03_login_fullFlow_throwsFailedLoginException() throws 
Exception {
         PamLoginModule      m       = new PamLoginModule();
         Subject             subject = new Subject();
         Map<String, Object> opts    = new HashMap<>();
         opts.put(PamLoginModule.SERVICE_KEY, "sshd");
         CallbackHandler cb = creds("alice", "bad");
         m.initialize(subject, cb, new HashMap<>(), opts);
-        setField(m, "options", opts);
+
+        setField(m, "subject", subject);
         setField(m, "callbackHandler", cb);
-        assertThrows(LoginException.class, m::login);
+        setField(m, "options", opts);
+
+        PAM mockPam = Mockito.mock(PAM.class);
+        Mockito.when(mockPam.authenticate(Mockito.eq("alice"), 
Mockito.eq("bad")))
+                .thenThrow(new PAMException("Authentication failed"));
+
+        setField(m, "pam", mockPam);
+
+        Method obtainUserAndPassword = 
PamLoginModule.class.getDeclaredMethod("obtainUserAndPassword");
+        obtainUserAndPassword.setAccessible(true);
+        obtainUserAndPassword.invoke(m);
+
+        Method performLogin = 
PamLoginModule.class.getDeclaredMethod("performLogin");
+        performLogin.setAccessible(true);
+        assertThrows(FailedLoginException.class, () -> 
invokeAndRethrowLoginException(m, performLogin));
     }
 
     @Test

Reply via email to