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

cris pushed a commit to branch SLING-10193/test-coverage
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit a4615d85b0aae51d04a1bf3b3067499bd3b6cfd3
Author: Cris Rockwell, College of LSA University of Michigan 
<[email protected]>
AuthorDate: Sun Mar 14 19:10:48 2021 -0400

    continued doUserManagement testing
---
 saml-handler/pom.xml                               |  4 +-
 .../saml2/impl/AuthenticationHandlerSAML2Impl.java | 10 ++---
 .../org/apache/sling/auth/saml2/SamlHandlerIT.java |  1 +
 .../apache/sling/auth/saml2/impl/OsgiSamlTest.java | 48 +++++++++++++++++++++-
 4 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/saml-handler/pom.xml b/saml-handler/pom.xml
index 388febc..d165e2e 100644
--- a/saml-handler/pom.xml
+++ b/saml-handler/pom.xml
@@ -59,8 +59,8 @@ which is licensed under the Apache-2.0 license.
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-         <source>11</source>
-         <target>11</target>
+         <source>9</source>
+         <target>9</target>
         </configuration>
       </plugin>
       <plugin>
diff --git 
a/saml-handler/src/main/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2Impl.java
 
b/saml-handler/src/main/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2Impl.java
index 9117c5d..5be41e0 100644
--- 
a/saml-handler/src/main/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2Impl.java
+++ 
b/saml-handler/src/main/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2Impl.java
@@ -272,7 +272,7 @@ public class AuthenticationHandlerSAML2Impl extends 
AbstractSamlHandler implemen
         return false;
     }
 
-    private void doClassloading(){
+    void doClassloading(){
         // Classloading
         BundleWiring bundleWiring = 
FrameworkUtil.getBundle(AuthenticationHandlerSAML2Impl.class).adapt(BundleWiring.class);
         ClassLoader loader = bundleWiring.getClassLoader();
@@ -431,10 +431,10 @@ public class AuthenticationHandlerSAML2Impl extends 
AbstractSamlHandler implemen
      * End Privat attribution
      */
 
-    private User doUserManagement(final Assertion assertion) {
-        if (assertion.getAttributeStatements() == null ||
-                assertion.getAttributeStatements().get(0) == null ||
-                assertion.getAttributeStatements().get(0).getAttributes() == 
null) {
+    User doUserManagement(final Assertion assertion) {
+        if (assertion == null ||
+                assertion.getAttributeStatements().size() == 0 ||
+                
assertion.getAttributeStatements().get(0).getAttributes().size() == 0) {
             logger.warn("SAML Assertion Attribute Statement or Attributes was 
null ");
             return null;
         }
diff --git 
a/saml-handler/src/test/java/org/apache/sling/auth/saml2/SamlHandlerIT.java 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/SamlHandlerIT.java
index cf57d93..3683a07 100644
--- a/saml-handler/src/test/java/org/apache/sling/auth/saml2/SamlHandlerIT.java
+++ b/saml-handler/src/test/java/org/apache/sling/auth/saml2/SamlHandlerIT.java
@@ -29,6 +29,7 @@ import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.auth.core.AuthenticationSupport;
 import org.apache.sling.auth.core.spi.AuthenticationHandler;
+import org.apache.sling.auth.saml2.impl.AuthenticationHandlerSAML2Impl;
 import org.apache.sling.testing.paxexam.SlingOptions;
 import org.apache.sling.testing.paxexam.TestSupport;
 import org.junit.After;
diff --git 
a/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/OsgiSamlTest.java 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/OsgiSamlTest.java
index 6419a1a..4acfdd0 100644
--- 
a/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/OsgiSamlTest.java
+++ 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/OsgiSamlTest.java
@@ -20,13 +20,13 @@
 
 package org.apache.sling.auth.saml2.impl;
 
-import 
org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.auth.saml2.Helpers;
 import org.apache.sling.auth.saml2.Saml2User;
 import org.apache.sling.auth.saml2.Saml2UserMgtService;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -34,20 +34,27 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opensaml.core.config.InitializationException;
+import org.opensaml.core.xml.XMLObjectBuilder;
+import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
 import org.opensaml.core.xml.schema.XSString;
 import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.saml.common.SAMLVersion;
 import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.saml2.core.Assertion;
+import org.opensaml.saml.saml2.core.Attribute;
+import org.opensaml.saml.saml2.core.AttributeStatement;
+import org.opensaml.saml.saml2.core.AttributeValue;
 import org.opensaml.saml.saml2.core.AuthnRequest;
 import org.opensaml.saml.saml2.core.Issuer;
 import org.opensaml.saml.saml2.core.NameIDPolicy;
 import org.opensaml.saml.saml2.core.Response;
 import org.opensaml.saml.saml2.metadata.Endpoint;
+import org.osgi.framework.BundleContext;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.time.Instant;
-
 import static org.apache.sling.auth.saml2.Activator.initializeOpenSaml;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -61,8 +68,10 @@ public class OsgiSamlTest {
 
     @Rule
     public final OsgiContext osgiContext = new OsgiContext();
+    BundleContext bundleContext;
     Saml2UserMgtService userMgtService;
     AuthenticationHandlerSAML2Impl samlHandler;
+    XMLObjectBuilder<XSString> valueBuilder;
 
     @BeforeClass
     public static void initializeOpenSAML(){
@@ -75,8 +84,14 @@ public class OsgiSamlTest {
 
     @Before
     public void setup(){
+        valueBuilder = 
XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilderOrThrow(XSString.TYPE_NAME);
         try {
+            bundleContext = MockOsgi.newBundleContext();
             ResourceResolverFactory mockFactory = 
Mockito.mock(ResourceResolverFactory.class);
+//            Saml2UserMgtService saml2UserMgtService = new 
Saml2UserMgtServiceImpl();
+//            MockOsgi.injectServices(mockFactory, bundleContext);
+//            MockOsgi.injectServices(saml2UserMgtService, bundleContext);
+//            MockOsgi.activate(saml2UserMgtService, bundleContext);
             osgiContext.registerService(ResourceResolverFactory.class, 
mockFactory);
             userMgtService = osgiContext.registerService(new 
Saml2UserMgtServiceImpl());
             samlHandler = osgiContext.registerInjectActivateService(new 
AuthenticationHandlerSAML2Impl());
@@ -122,6 +137,35 @@ public class OsgiSamlTest {
     }
 
     @Test
+    public void test_doUserManagement(){
+        // returns null
+        assertNull(samlHandler.doUserManagement(null));
+        Assertion assertion1 = Helpers.buildSAMLObject(Assertion.class);
+        assertNull(samlHandler.doUserManagement(assertion1));
+        Assertion assertion2 = Helpers.buildSAMLObject(Assertion.class);
+        
assertion2.getAttributeStatements().add(Helpers.buildSAMLObject(AttributeStatement.class));
+        assertNull(samlHandler.doUserManagement(assertion2));
+
+        // returns null
+        Assertion assertion3 = Helpers.buildSAMLObject(Assertion.class);
+        assertion3.setIssueInstant(Instant.ofEpochMilli(0));
+        assertion3.setVersion(SAMLVersion.VERSION_20);
+        assertion3.setID("ASSERTION_3");
+        AttributeStatement anyAttrStmt = 
Helpers.buildSAMLObject(AttributeStatement.class);
+        Attribute anyAttribute = Helpers.buildSAMLObject(Attribute.class);
+        anyAttribute.setName("anyKey");
+        final XSString value = 
valueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, 
XSString.TYPE_NAME);
+        value.setValue("bar");
+        anyAttribute.getAttributeValues().add(value);
+        anyAttrStmt.getAttributes().add(anyAttribute);
+        assertion3.getAttributeStatements().add(anyAttrStmt);
+
+//        userMgtService.
+//        assertNull(samlHandler.doUserManagement(assertion3));
+
+    }
+
+    @Test
     public void test_authn_request(){
         AuthnRequest authnRequest = samlHandler.buildAuthnRequest();
         assertNotNull(authnRequest);

Reply via email to