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

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


The following commit(s) were added to 
refs/heads/SLING-9397/improve-test-coverage by this push:
     new d34aa25  added tests for issuer and nameIDpolicy
d34aa25 is described below

commit d34aa25f62fc0266b1f7004125c6b0dff2eb6c1b
Author: Cris Rockwell, College of LSA University of Michigan 
<[email protected]>
AuthorDate: Tue Mar 2 08:59:26 2021 -0500

    added tests for issuer and nameIDpolicy
---
 .../saml2/impl/AuthenticationHandlerSAML2Impl.java |  4 ++--
 .../impl/AuthenticationHandlerSAML2ImplTest.java   | 13 -------------
 .../apache/sling/auth/saml2/impl/OsgiSamlTest.java | 22 +++++++++++++++++++++-
 3 files changed, 23 insertions(+), 16 deletions(-)

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 81d3720..09e1bf5 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
@@ -368,13 +368,13 @@ public class AuthenticationHandlerSAML2Impl extends 
AbstractSamlHandler implemen
         return authnRequest;
     }
 
-    private Issuer buildIssuer() {
+    Issuer buildIssuer() {
         Issuer issuer = Helpers.buildSAMLObject(Issuer.class);
         issuer.setValue(this.getEntityID());
         return issuer;
     }
 
-    private NameIDPolicy buildNameIdPolicy() {
+    NameIDPolicy buildNameIdPolicy() {
         NameIDPolicy nameIDPolicy = 
Helpers.buildSAMLObject(NameIDPolicy.class);
         nameIDPolicy.setAllowCreate(true);
         nameIDPolicy.setFormat(NameIDType.TRANSIENT);
diff --git 
a/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
index 7684d16..1640125 100644
--- 
a/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
+++ 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/AuthenticationHandlerSAML2ImplTest.java
@@ -19,20 +19,13 @@
 
 package org.apache.sling.auth.saml2.impl;
 
-import org.apache.sling.auth.saml2.SAML2RuntimeException;
 import org.hamcrest.core.StringStartsWith;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.api.Invocation;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.hamcrest.Description;
 import org.junit.runner.RunWith;
-import org.opensaml.core.config.InitializationException;
-import org.opensaml.core.config.InitializationService;
-import org.opensaml.xmlsec.config.impl.JavaCryptoValidationInitializer;
-import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.powermock.core.classloader.annotations.PowerMockIgnore;
 import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -40,15 +33,9 @@ import org.powermock.modules.junit4.PowerMockRunner;
 import org.jmock.api.Action;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.sling.auth.saml2.Activator;
 import java.io.File;
-import java.security.Provider;
-import java.security.Security;
-
 import static 
org.apache.sling.auth.saml2.impl.AuthenticationHandlerSAML2Impl.TOKEN_FILENAME;
-
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 
 
 @RunWith(PowerMockRunner.class)
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 8b330de..226c844 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
@@ -23,6 +23,7 @@ package org.apache.sling.auth.saml2.impl;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.auth.core.spi.AuthenticationHandler;
 import org.apache.sling.auth.saml2.Helpers;
 import org.apache.sling.auth.saml2.Saml2UserMgtService;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
@@ -41,6 +42,7 @@ import org.opensaml.saml.common.xml.SAMLConstants;
 import org.opensaml.saml.saml2.core.ArtifactResponse;
 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.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -49,12 +51,15 @@ import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.apache.sling.auth.saml2.Activator;
+import org.osgi.service.component.ComponentContext;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.time.Instant;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Map;
 
 import static org.apache.sling.auth.saml2.Activator.initializeOpenSaml;
 import static org.junit.Assert.assertEquals;
@@ -142,7 +147,7 @@ public class OsgiSamlTest {
         assertEquals(samlHandler.getACSURL(), 
authnRequest.getAssertionConsumerServiceURL());
         assertTrue(authnRequest.getID().length()==33);
     }
-    
+
     @Test
     public void test_decodeHttpPostSamlResp(){
         SlingHttpServletRequest request = 
Mockito.mock(SlingHttpServletRequest.class);
@@ -167,6 +172,19 @@ public class OsgiSamlTest {
         assertEquals("urn:oasis:names:tc:SAML:2.0:protocol", 
response.getElementQName().getNamespaceURI());
     }
 
+    @Test
+    public void test_buildIssuer(){
+        Issuer issuer = samlHandler.buildIssuer();
+        assertEquals(samlHandler.getEntityID(), issuer.getValue());
+    }
+
+    @Test
+    public void test_buildNameIdPolicy(){
+        NameIDPolicy nameIDPolicy = samlHandler.buildNameIdPolicy();
+        assertTrue(nameIDPolicy.getAllowCreate());
+        assertEquals("urn:oasis:names:tc:SAML:2.0:nameid-format:transient", 
nameIDPolicy.getFormat());
+    }
+
     private void configureJaas() throws IOException {
         final ConfigurationAdmin configAdmin = 
osgiContext.getService(ConfigurationAdmin.class);
         Configuration jaasConfig = 
configAdmin.getConfiguration("org.apache.felix.jaas.Configuration.factory");
@@ -200,4 +218,6 @@ public class OsgiSamlTest {
         Dictionary<String, Object> serviceUserProps = new Hashtable<>();
         serviceUserProps.put("user.mapping",new 
String[]{"org.apache.sling.auth.saml2:Saml2UserMgtService=saml2-user-mgt"});
     }
+
+
 }

Reply via email to