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 16b3442 continued struggling with test setup
16b3442 is described below
commit 16b344291bfbd972a0d89eb4c3e570c4618c1f79
Author: Cris Rockwell, College of LSA University of Michigan
<[email protected]>
AuthorDate: Thu Feb 25 17:49:45 2021 -0500
continued struggling with test setup
---
saml-handler/pom.xml | 33 ++++--
.../apache/sling/auth/saml2/impl/OsgiSamlTest.java | 9 +-
.../sling/auth/saml2/impl/SamlHandlerIT.java | 113 ++-------------------
saml-handler/src/test/resources/logback.xml | 30 ++++++
4 files changed, 67 insertions(+), 118 deletions(-)
diff --git a/saml-handler/pom.xml b/saml-handler/pom.xml
index 38e98e4..e01a576 100644
--- a/saml-handler/pom.xml
+++ b/saml-handler/pom.xml
@@ -35,7 +35,7 @@
<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>
+ <exam.version>4.13.3</exam.version>
<pax.vm.options>
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5015
</pax.vm.options>
@@ -95,14 +95,16 @@ which is licensed under the Apache-2.0 license.
</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>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.4.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
@@ -164,13 +166,15 @@ which is licensed under the Apache-2.0 license.
<scope>test</scope>
</dependency>
- <!-- Pax Exam -->
+ <!-- Sling Testing PaxExam -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>2.0.0</version>
+ <version>3.1.0</version>
<scope>test</scope>
</dependency>
+
+ <!-- Pax Exam -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
@@ -202,6 +206,13 @@ which is licensed under the Apache-2.0 license.
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ <scope>test</scope>
+ </dependency>
+
<!-- OPENSAML -->
<dependency>
<groupId>org.opensaml</groupId>
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 d1fc3a3..f137105 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
@@ -111,9 +111,12 @@ public class OsgiSamlTest {
@Test
public void test_authn_request(){
- BundleContext bundleContext = MockOsgi.newBundleContext();
-// MockResourceResolverFactory factory = new
MockResourceResolverFactory();
- ResourceResolverFactory mockFactory =
Mockito.mock(ResourceResolverFactory.class);
+ Saml2UserMgtService userMgtService = osgiContext.registerService(new
Saml2UserMgtServiceImpl());
+ AuthenticationHandlerSAML2Impl samlHandler =
osgiContext.registerInjectActivateService(new AuthenticationHandlerSAML2Impl());
+
+// BundleContext bundleContext = MockOsgi.newBundleContext();
+// MockResourceResolverFactory mockFactory = new
MockResourceResolverFactory();
+// ResourceResolverFactory mockFactory =
Mockito.mock(ResourceResolverFactory.class);
// MockOsgi.injectServices(mockFactory, bundleContext);
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
index 2c1bc9f..d2fc886 100644
---
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
@@ -20,147 +20,52 @@
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;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
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
+ HTTP_PORT = findFreePort();
+ DEST_HTTP_PORT = findFreePort();
SlingOptions.versionResolver.setVersionFromProject("org.apache.sling",
"org.apache.sling.auth.saml2");
return new Option[]{
+
systemProperty("org.osgi.service.http.port").value(String.valueOf(HTTP_PORT)),
baseConfiguration(),
slingQuickstart(),
+ junitBundles(),
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()
+ CoreOptions.mavenBundle("org.apache.felix",
"org.apache.felix.webconsole.plugins.ds", "2.0.8")
};
}
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()
+ slingQuickstartOakTar(workingDirectory, 8081) // from SlingOptions
);
}
-// @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(){
+ System.err.println("test log");
assertTrue(true);
}
}
diff --git a/saml-handler/src/test/resources/logback.xml
b/saml-handler/src/test/resources/logback.xml
new file mode 100644
index 0000000..b8b7262
--- /dev/null
+++ b/saml-handler/src/test/resources/logback.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<configuration>
+ <appender name="file" class="ch.qos.logback.core.FileAppender">
+ <file>target/test.log</file>
+ <append>true</append>
+ <encoder>
+ <pattern>%date level=%level thread=%thread logger=%logger
sourcefile=%file line=%line %mdc message=%msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="file"/>
+ </root>
+</configuration>
\ No newline at end of file