You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ow...@apache.org on 2012/11/29 14:19:08 UTC
svn commit: r1415156 - in /cxf/fediz/trunk/plugins/jetty: pom.xml
src/test/java/org/apache/cxf/fediz/jetty/BrowserTest.java
src/test/resources/idpserver.xml
Author: owulff
Date: Thu Nov 29 13:19:07 2012
New Revision: 1415156
URL: http://svn.apache.org/viewvc?rev=1415156&view=rev
Log:
Finished unit test with idp/sts in embedded jetty as well as fedizhelloworld
Added:
cxf/fediz/trunk/plugins/jetty/src/test/resources/idpserver.xml
Modified:
cxf/fediz/trunk/plugins/jetty/pom.xml
cxf/fediz/trunk/plugins/jetty/src/test/java/org/apache/cxf/fediz/jetty/BrowserTest.java
Modified: cxf/fediz/trunk/plugins/jetty/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/jetty/pom.xml?rev=1415156&r1=1415155&r2=1415156&view=diff
==============================================================================
--- cxf/fediz/trunk/plugins/jetty/pom.xml (original)
+++ cxf/fediz/trunk/plugins/jetty/pom.xml Thu Nov 29 13:19:07 2012
@@ -21,13 +21,11 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
<version>${jetty.version}</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
@@ -39,6 +37,12 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-jsp</artifactId>
+ <version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -60,6 +64,41 @@
<version>4.2.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>net.htmlparser.jericho</groupId>
+ <artifactId>jericho-html</artifactId>
+ <version>3.2</version>
+ <scope>test</scope>
+ </dependency>
+
+<!--
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.2.1-b03</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.web</groupId>
+ <artifactId>jsp-impl</artifactId>
+ <version>2.2.2-b06</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.ext.tomcat</groupId>
+ <artifactId>jasper-el</artifactId>
+ <version>7.0.19.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.bundles</groupId>
+ <artifactId>jstl</artifactId>
+ <version>1.2_1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-servlet_3.0_spec</artifactId>
+ <version>1.0</version>
+ </dependency>
+ -->
+
</dependencies>
<build>
@@ -83,32 +122,69 @@
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.4</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Implementation-Title>Apache CXF Fediz</Implementation-Title>
- <Implementation-Vendor>The Apache Software Foundation</Implementation-Vendor>
- <Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
- <Implementation-Version>${project.version}</Implementation-Version>
- <Specification-Title>Apache CXF Fediz</Specification-Title>
- <Specification-Vendor>The Apache Software Foundation</Specification-Vendor>
- <Specification-Version>${project.version}</Specification-Version>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.4</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Implementation-Title>Apache CXF Fediz</Implementation-Title>
+ <Implementation-Vendor>The Apache Software Foundation</Implementation-Vendor>
+ <Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Specification-Title>Apache CXF Fediz</Specification-Title>
+ <Specification-Vendor>The Apache Software Foundation</Specification-Vendor>
+ <Specification-Version>${project.version}</Specification-Version>
- <Export-Package>
- org.apache.cxf.fediz.jetty.*;version="${project.version}"
+ <Export-Package>
+ org.apache.cxf.fediz.jetty.*;version="${project.version}"
</Export-Package>
- <Import-Package>
- !org.apache.cxf.fediz.jetty*,
- org.apache.cxf.fediz.core.*,
- *;resolution:=optional
+ <Import-Package>
+ !org.apache.cxf.fediz.jetty*,
+ org.apache.cxf.fediz.core.*,
+ *;resolution:=optional
</Import-Package>
- </instructions>
- </configuration>
- </plugin>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.1</version>
+ <executions>
+ <execution>
+ <id>copy-idp-sts</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>fediz-idp</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>fediz-idp-sts</artifactId>
+ <version>${project.version}</version>
+ <type>war</type>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ </artifactItems>
+ <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
+ <outputDirectory>target</outputDirectory>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
Modified: cxf/fediz/trunk/plugins/jetty/src/test/java/org/apache/cxf/fediz/jetty/BrowserTest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/jetty/src/test/java/org/apache/cxf/fediz/jetty/BrowserTest.java?rev=1415156&r1=1415155&r2=1415156&view=diff
==============================================================================
--- cxf/fediz/trunk/plugins/jetty/src/test/java/org/apache/cxf/fediz/jetty/BrowserTest.java (original)
+++ cxf/fediz/trunk/plugins/jetty/src/test/java/org/apache/cxf/fediz/jetty/BrowserTest.java Thu Nov 29 13:19:07 2012
@@ -22,23 +22,35 @@ package org.apache.cxf.fediz.jetty;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
+import java.util.ArrayList;
+import java.util.List;
+import net.htmlparser.jericho.FormField;
+import net.htmlparser.jericho.FormFields;
+import net.htmlparser.jericho.Source;
+
+import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.LaxRedirectStrategy;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Ignore;
public class BrowserTest {
@@ -47,9 +59,20 @@ public class BrowserTest {
@BeforeClass
- public static void init() {
+ public static void init() {
+ System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
+
+ System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
+
+ System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
+
+ System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
+ initIdp();
+ initWebApp();
+ }
+
+ private static void initWebApp() {
try {
- //Resource testServerConfig = Resource.newSystemResource("testserver.xml");
Resource testServerConfig = Resource.newSystemResource("fedserver.xml");
XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
server = (Server)configuration.configure();
@@ -59,6 +82,17 @@ public class BrowserTest {
}
}
+ private static void initIdp() {
+ try {
+ Resource testServerConfig = Resource.newSystemResource("idpserver.xml");
+ XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
+ server = (Server)configuration.configure();
+ server.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
@org.junit.Test
public void testStart() throws Exception {
System.out.println(System.getProperty("jetty.home"));
@@ -68,14 +102,14 @@ public class BrowserTest {
//Ignore still IDP/STS is mocked also
@org.junit.Test
- @Ignore
public void testGetSecureUrl() throws Exception {
String uri = "http://localhost:8080/fedizhelloworld/secure/fedservlet";
DefaultHttpClient httpclient = new DefaultHttpClient();
+ String user = "alice";
try {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("localhost", 9443),
- new UsernamePasswordCredentials("alice", "ecila"));
+ new UsernamePasswordCredentials(user, "ecila"));
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File("./target/test-classes/tomcat-idp.jks"));
@@ -95,16 +129,51 @@ public class BrowserTest {
HttpGet httpget = new HttpGet(uri);
- System.out.println("executing request" + httpget.getRequestLine());
+ //System.out.println("executing request " + httpget.getRequestLine());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
- System.out.println("----------------------------------------");
- System.out.println(response.getStatusLine());
- if (entity != null) {
- System.out.println("Response content length: " + entity.getContentLength());
+ //System.out.println("----------------------------------------");
+ //System.out.println(response.getStatusLine());
+ //if (entity != null) {
+ // System.out.println("Response content length: " + entity.getContentLength());
+ //}
+
+// Redirect to a POST is not supported without user interaction
+// http://www.ietf.org/rfc/rfc2616.txt
+// If the 301 status code is received in response to a request other
+// than GET or HEAD, the user agent MUST NOT automatically redirect the
+// request unless it can be confirmed by the user, since this might
+// change the conditions under which the request was issued.
+
+ httpclient.setRedirectStrategy(new LaxRedirectStrategy());
+ HttpPost httppost = new HttpPost(uri);
+
+ Source source = new Source(EntityUtils.toString(entity));
+ List <NameValuePair> nvps = new ArrayList <NameValuePair>();
+ FormFields formFields = source.getFormFields();
+ Assert.assertNotNull("Form field 'wa' not found", formFields.get("wa"));
+ Assert.assertNotNull("Form field 'wresult' not found", formFields.get("wresult"));
+ for (FormField formField : formFields) {
+ nvps.add(new BasicNameValuePair(formField.getName(), formField.getValues().get(0)));
}
- EntityUtils.consume(entity);
+ httppost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
+
+ response = httpclient.execute(httppost);
+ entity = response.getEntity();
+ //System.out.println("----------------------------------------");
+ //System.out.println(response.getStatusLine());
+ //if (entity != null) {
+ // System.out.println("Response content length: " + entity.getContentLength());
+ //}
+
+ String responseContent = EntityUtils.toString(entity);
+
+ Assert.assertTrue("Principal not alice", responseContent.indexOf("Principal: " + user) > 0);
+ //Has role 'Admin': no<p>
+ //Has role 'Manager': no<p>
+ //Has role 'User': no<p>
+
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
Added: cxf/fediz/trunk/plugins/jetty/src/test/resources/idpserver.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/jetty/src/test/resources/idpserver.xml?rev=1415156&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/jetty/src/test/resources/idpserver.xml (added)
+++ cxf/fediz/trunk/plugins/jetty/src/test/resources/idpserver.xml Thu Nov 29 13:19:07 2012
@@ -0,0 +1,60 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+
+<Configure id="IdpServer" class="org.eclipse.jetty.server.Server">
+
+ <Call class="org.eclipse.jetty.util.log.Log" name="getRootLogger">
+ <Call name="setDebugEnabled">
+ <Arg type="boolean">true</Arg>
+ </Call>
+ </Call>
+
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
+ <Set name="port">9080</Set>
+ </New>
+ </Arg>
+ </Call>
+
+ <Call name="addConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
+ <Arg>
+ <New class="org.eclipse.jetty.http.ssl.SslContextFactory">
+ <Set name="keyStore">./target/test-classes/tomcat-idp.jks</Set>
+ <Set name="keyStorePassword">tompass</Set>
+ <Set name="keyManagerPassword">tompass</Set>
+ </New>
+ </Arg>
+ <Set name="port">9443</Set>
+ <Set name="maxIdleTime">30000</Set>
+ </New>
+ </Arg>
+ </Call>
+
+ <Set name="handler">
+ <New class="org.eclipse.jetty.server.handler.HandlerList">
+ <Set name="handlers">
+ <Array type="org.eclipse.jetty.server.Handler">
+ <Item>
+ <New class="org.eclipse.jetty.webapp.WebAppContext">
+ <Set name="contextPath">/fedizidp</Set>
+ <Set name="war">./target/fediz-idp-1.1.0-SNAPSHOT.war</Set>
+ <Set name="throwUnavailableOnStartupException">true</Set>
+ <!--<Set name="defaultsDescriptor">./target/test-classes/webdefault.xml</Set>-->
+ </New>
+ </Item>
+ <Item>
+ <New class="org.eclipse.jetty.webapp.WebAppContext">
+ <Set name="contextPath">/fedizidpsts</Set>
+ <Set name="war">./target/fediz-idp-sts-1.1.0-SNAPSHOT.war</Set>
+ <Set name="throwUnavailableOnStartupException">true</Set>
+ </New>
+ </Item>
+ </Array>
+ </Set>
+ </New>
+ </Set>
+
+</Configure>
\ No newline at end of file