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

cris pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-saml2.git


The following commit(s) were added to refs/heads/master by this push:
     new 778fb3d  added tests for Saml2UserMgtServiceImpl NPE scenarios
778fb3d is described below

commit 778fb3d3121433b27a2e93d2ff1700ee996da584
Author: Cris Rockwell <[email protected]>
AuthorDate: Wed Jun 30 11:02:10 2021 -0400

    added tests for Saml2UserMgtServiceImpl NPE scenarios
---
 .../sling/auth/saml2/impl/Saml2UserMgtServiceImpl.java  |  8 ++++++++
 .../saml2/impl/AuthenticationHandlerSAML2ImplTest.java  | 17 ++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/auth/saml2/impl/Saml2UserMgtServiceImpl.java 
b/src/main/java/org/apache/sling/auth/saml2/impl/Saml2UserMgtServiceImpl.java
index e1abc18..c3fe2e0 100644
--- 
a/src/main/java/org/apache/sling/auth/saml2/impl/Saml2UserMgtServiceImpl.java
+++ 
b/src/main/java/org/apache/sling/auth/saml2/impl/Saml2UserMgtServiceImpl.java
@@ -85,6 +85,14 @@ public class Saml2UserMgtServiceImpl implements 
Saml2UserMgtService {
         return this.resourceResolver;
     }
 
+    void setResolverFactory(ResourceResolverFactory resourceResolverFactory){
+        this.resolverFactory = resourceResolverFactory;
+    }
+
+    ResourceResolverFactory getResolverFactory(){
+        return this.resolverFactory;
+    }
+
     @Override
     public void cleanUp() {
         resourceResolver.close();
diff --git 
a/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
 
b/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
index 895a242..9edb78a 100644
--- 
a/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
+++ 
b/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
@@ -23,6 +23,7 @@ import org.apache.jackrabbit.api.security.user.User;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.auth.core.spi.AuthenticationInfo;
 import org.hamcrest.core.StringStartsWith;
 import org.jmock.Expectations;
@@ -41,6 +42,7 @@ import java.io.UnsupportedEncodingException;
 import java.math.BigInteger;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
 import java.util.UUID;
 import static 
org.apache.sling.auth.saml2.impl.AuthenticationHandlerSAML2Impl.TOKEN_FILENAME;
 import static org.junit.Assert.assertEquals;
@@ -48,6 +50,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
 public class AuthenticationHandlerSAML2ImplTest {
@@ -79,14 +82,18 @@ public class AuthenticationHandlerSAML2ImplTest {
 
     @Test
     public void SamlUserMgtServiceImplNPETest() throws  Exception {
-        Saml2UserMgtServiceImpl saml2UserMgtService = 
Mockito.mock(Saml2UserMgtServiceImpl.class);
-        when(saml2UserMgtService.getResourceResolver()).thenReturn(null);
+        Saml2UserMgtServiceImpl saml2UserMgtService = new 
Saml2UserMgtServiceImpl();
+        ResourceResolverFactory resourceResolverFactory = 
Mockito.mock(ResourceResolverFactory.class);
+        
when(resourceResolverFactory.getServiceResourceResolver(any(HashMap.class))).thenReturn(null);
+        saml2UserMgtService.setResolverFactory(resourceResolverFactory);
         assertFalse(saml2UserMgtService.setUp());
 
-        Saml2UserMgtServiceImpl saml2UserMgtService2 = 
Mockito.mock(Saml2UserMgtServiceImpl.class);
+        Saml2UserMgtServiceImpl saml2UserMgtService2 = new 
Saml2UserMgtServiceImpl();
+        ResourceResolverFactory resourceResolverFactory2 = 
Mockito.mock(ResourceResolverFactory.class);
         ResourceResolver resourceResolver = 
Mockito.mock(ResourceResolver.class);
-        
when(saml2UserMgtService2.getResourceResolver()).thenReturn(resourceResolver);
-        assertFalse(saml2UserMgtService.setUp());
+        
when(resourceResolverFactory2.getServiceResourceResolver(any(HashMap.class))).thenReturn(resourceResolver);
+        saml2UserMgtService2.setResolverFactory(resourceResolverFactory2);
+        assertFalse(saml2UserMgtService2.setUp());
     }
 
     @Test

Reply via email to