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

commit 7c0b5af71dcfc7f173813762dc5b56e7a7c3810e
Author: Cris Rockwell, College of LSA University of Michigan 
<[email protected]>
AuthorDate: Tue Feb 23 18:05:13 2021 -0500

    Started PAX tests for saml-handler. IT tests seem inoperational in this 
commit
---
 saml-handler/pom.xml                               |  82 +++++++++-
 .../impl/AuthenticationHandlerSAML2ImplTest.java   |   5 +
 .../sling/auth/saml2/impl/SamlHandlerIT.java       | 166 +++++++++++++++++++++
 3 files changed, 250 insertions(+), 3 deletions(-)

diff --git a/saml-handler/pom.xml b/saml-handler/pom.xml
index 26ca217..caec5eb 100644
--- a/saml-handler/pom.xml
+++ b/saml-handler/pom.xml
@@ -35,6 +35,10 @@
     <sling.password>admin</sling.password>
     <bnd.baseline.skip>true</bnd.baseline.skip>
     <powermock.version>2.0.9</powermock.version>
+    <exam.version>4.11.0</exam.version>
+    <pax.vm.options>
+      -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5015
+    </pax.vm.options>
     <noticeStatement>This module includes modified code from 
webprofile-ref-project-v3 [1],
 which is licensed under the Apache-2.0 license.
 
@@ -47,12 +51,10 @@ which is licensed under the Apache-2.0 license.
         <groupId>biz.aQute.bnd</groupId>
         <artifactId>bnd-maven-plugin</artifactId>
       </plugin>
-
       <plugin>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling-maven-plugin</artifactId>
       </plugin>
-
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
@@ -61,7 +63,6 @@ which is licensed under the Apache-2.0 license.
          <target>11</target>
         </configuration>
       </plugin>
-
       <plugin>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
@@ -72,6 +73,37 @@ which is licensed under the Apache-2.0 license.
           </excludes>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>integration-test</goal>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
+          <systemProperties>
+            <property>
+              <name>bundle.filename</name>
+              <value>${basedir}/target/${project.build.finalName}.jar</value>
+            </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <configuration>
+          <redirectTestOutputToFile>true</redirectTestOutputToFile>
+          <includes>
+            <include>**/*IT.java</include>
+          </includes>
+        </configuration>
+      </plugin>
     </plugins> 
   </build>
 
@@ -101,6 +133,50 @@ which is licensed under the Apache-2.0 license.
       <version>2.12.0</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.clients</artifactId>
+      <version>2.0.8</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- Pax Exam -->
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.paxexam</artifactId>
+      <version>2.0.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam</artifactId>
+      <version>${exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-cm</artifactId>
+      <version>${exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-forked</artifactId>
+      <version>${exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <version>${exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-link-mvn</artifactId>
+      <version>${exam.version}</version>
+      <scope>test</scope>
+    </dependency>
 
 <!--    OPENSAML -->
     <dependency>
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 6aa8f83..0fc22bf 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
@@ -23,6 +23,7 @@ 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.Test;
 import org.hamcrest.Description;
 import org.junit.runner.RunWith;
@@ -32,7 +33,10 @@ import 
org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 import org.jmock.api.Action;
 import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
+import org.apache.sling.auth.saml2.AuthenticationHandlerSAML2Config;
 import static 
org.apache.sling.auth.saml2.impl.AuthenticationHandlerSAML2Impl.TOKEN_FILENAME;
 import static org.junit.Assert.assertEquals;
 
@@ -133,5 +137,6 @@ public class AuthenticationHandlerSAML2ImplTest {
             description.appendText("returns new File(root, arg0)");
         }
     }
+
 }
 
diff --git 
a/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/SamlHandlerIT.java
 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/SamlHandlerIT.java
new file mode 100644
index 0000000..2c1bc9f
--- /dev/null
+++ 
b/saml-handler/src/test/java/org/apache/sling/auth/saml2/impl/SamlHandlerIT.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.auth.saml2.impl;
+import org.apache.sling.testing.paxexam.SlingOptions;
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
+import org.ops4j.pax.exam.junit.PaxExamServer;
+
+import java.net.ServerSocket;
+import java.net.URI;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.apache.sling.testing.paxexam.SlingOptions.logback;
+import static 
org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+import static 
org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
+
+public class SamlHandlerIT extends TestSupport {
+
+    static int HTTP_PORT = 8080;
+    static int DEST_HTTP_PORT = 8484;
+    protected static OsgiConsoleClient CLIENT;
+    private final static int STARTUP_WAIT_SECONDS = 30;
+
+//    @ClassRule
+//    public static PaxExamServer serverRule = new PaxExamServer() {
+//        @Override
+//        protected void before() throws Exception {
+//            // Use a different port for each OSGi framework instance
+//            // that's started - they can overlap if the previous one
+//            // is not fully stopped when the next one starts.
+//            setHttpPort();
+//            super.before();
+//        }
+//    };
+
+//    static void setHttpPort() {
+//        try {
+//            final ServerSocket serverSocket = new ServerSocket(0);
+//            HTTP_PORT = serverSocket.getLocalPort();
+//            DEST_HTTP_PORT = serverSocket.getLocalPort();
+//            serverSocket.close();
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
+//    }
+// 
systemProperty("org.osgi.service.http.port").value(String.valueOf(HTTP_PORT)),
+    @Configuration
+    public Option[] configuration() {
+        // Patch versions of features provided by SlingOptions
+        SlingOptions.versionResolver.setVersionFromProject("org.apache.sling", 
"org.apache.sling.auth.saml2");
+        return new Option[]{
+            baseConfiguration(),
+            slingQuickstart(),
+            logback(),
+            // build artifact
+            testBundle("bundle.filename"), // from TestSupport
+            // testing
+            defaultOsgiConfigs(),
+            SlingOptions.webconsole(),
+            CoreOptions.mavenBundle("org.apache.felix", 
"org.apache.felix.webconsole.plugins.ds", "2.0.8"),
+            junitBundles()
+        };
+    }
+
+    protected Option slingQuickstart() {
+        final String workingDirectory = workingDirectory(); // from TestSupport
+//        setHttpPort();
+        HTTP_PORT = findFreePort();
+        DEST_HTTP_PORT = HTTP_PORT+1;
+        return composite(
+            slingQuickstartOakTar(workingDirectory, HTTP_PORT) // from 
SlingOptions
+        );
+    }
+
+    public static Option defaultOsgiConfigs() {
+        final String entityID = String.format("http://localhost:%d/";, 
HTTP_PORT);
+        final String destinationURL = 
String.format("http://localhost:%d/auth/realms/sling/protocol/saml";, 
DEST_HTTP_PORT);
+
+        return composite(
+            // Configure JAAS
+            factoryConfiguration("org.apache.felix.jaas.Configuration.factory")
+                .put("jaas.classname", 
"org.apache.sling.auth.saml2.sp.Saml2LoginModule")
+                .put("jaas.controlFlag", "Sufficient")
+                .put("jaas.realmName", "jackrabbit.oak")
+                .put("jaas.ranking", 110)
+                .asOption(),
+
+            // Repo Init
+            
factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+                .put("scripts", new String[]{
+"create service user saml2-user-mgt\n\nset ACL for saml2-user-mgt\n\nallow 
jcr:all on /home\n\nend\n\ncreate group sling-authors with path 
/home/groups/sling-authors"
+                })
+                .asOption(),
+
+            // Repo Init
+            
newConfiguration("org.apache.sling.engine.impl.auth.SlingAuthenticator")
+                .put("auth.annonymous", false)
+                .asOption(),
+
+            // Service User for User Management
+            
factoryConfiguration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended")
+                .put("user.mapping", new 
String[]{"org.apache.sling.auth.saml2:Saml2UserMgtService=saml2-user-mgt"})
+                .asOption(),
+
+            // SAML Settings
+            
factoryConfiguration("org.apache.sling.auth.saml2.AuthenticationHandlerSAML2")
+                .put("path", "/")
+                .put("entityID", entityID)
+                .put("acsPath", "/sp/consumer")
+                .put("saml2userIDAttr", "urn:oid:0.9.2342.19200300.100.1.1")
+                .put("saml2userHome", "/home/users/saml")
+                .put("saml2groupMembershipAttr", 
"urn:oid:2.16.840.1.113719.1.1.4.1.25")
+                .put("saml2IDPDestination", destinationURL)
+                .put("saml2SPEnabled", true)
+                .put("saml2SPEncryptAndSign", false)
+                .asOption()
+        );
+    }
+
+//    @BeforeClass
+//    public static void waitForSling() throws Exception {
+//        final URI url = new URI(String.format("http://localhost:%d";, 
HTTP_PORT));
+//        CLIENT = new OsgiConsoleClient(url, "admin", "admin");
+//
+//        CLIENT.waitExists("/", STARTUP_WAIT_SECONDS * 1000, 500);
+//
+//        
CLIENT.waitComponentRegistered(AuthenticationHandlerSAML2ImplTest.class.getName(),
 10 * 1000, 500);
+//
+//        // Verify stable status for a bit
+//        for(int i=0; i < 10 ; i++) {
+//            
CLIENT.waitComponentRegistered(AuthenticationHandlerSAML2ImplTest.class.getName(),
 1000, 100);
+//            Thread.sleep(100);
+//        }
+//    }
+
+    @Test
+    public void exampleTest(){
+        assertTrue(true);
+    }
+}

Reply via email to