Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7763918E95 for ; Thu, 14 Jan 2016 15:42:38 +0000 (UTC) Received: (qmail 98769 invoked by uid 500); 14 Jan 2016 15:42:38 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 98677 invoked by uid 500); 14 Jan 2016 15:42:38 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 98659 invoked by uid 99); 14 Jan 2016 15:42:38 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jan 2016 15:42:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2C4AEE3874; Thu, 14 Jan 2016 15:42:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Thu, 14 Jan 2016 15:42:38 -0000 Message-Id: <24dfee953e2c4541a0c32f79ebf52d6f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] cxf-fediz git commit: More OIDC tests Repository: cxf-fediz Updated Branches: refs/heads/master 6842bcfc2 -> a4a444400 More OIDC tests Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/5f5dfbf9 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/5f5dfbf9 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/5f5dfbf9 Branch: refs/heads/master Commit: 5f5dfbf9ae7a6193c911a7b194e64ff3e91c1a44 Parents: 6842bcf Author: Colm O hEigeartaigh Authored: Thu Jan 14 15:34:29 2016 +0000 Committer: Colm O hEigeartaigh Committed: Thu Jan 14 15:34:29 2016 +0000 ---------------------------------------------------------------------- .../webapp/WEB-INF/views/registeredClients.jsp | 2 +- systests/oidc/pom.xml | 1 + .../cxf/fediz/systests/oidc/OIDCTest.java | 74 ++++++++++++++++---- 3 files changed, 63 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/5f5dfbf9/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp ---------------------------------------------------------------------- diff --git a/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp b/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp index 6ddeca0..afd91ae 100644 --- a/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp +++ b/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp @@ -40,7 +40,7 @@

Registered Clients


- +
<% SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US); http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/5f5dfbf9/systests/oidc/pom.xml ---------------------------------------------------------------------- diff --git a/systests/oidc/pom.xml b/systests/oidc/pom.xml index b96f16d..42bf107 100644 --- a/systests/oidc/pom.xml +++ b/systests/oidc/pom.xml @@ -234,6 +234,7 @@ true${idp.https.port}${rp.https.port} + ${basedir}/target **/systests/** http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/5f5dfbf9/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/OIDCTest.java ---------------------------------------------------------------------- diff --git a/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/OIDCTest.java b/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/OIDCTest.java index 41918df..2401a03 100644 --- a/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/OIDCTest.java +++ b/systests/oidc/src/test/java/org/apache/cxf/fediz/systests/oidc/OIDCTest.java @@ -22,6 +22,11 @@ package org.apache.cxf.fediz.systests.oidc; import java.io.File; import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; @@ -32,6 +37,9 @@ import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import com.gargoylesoftware.htmlunit.html.HtmlTable; +import com.gargoylesoftware.htmlunit.html.HtmlTableCell; +import com.gargoylesoftware.htmlunit.html.HtmlTableRow; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.util.WebConnectionWrapper; @@ -58,7 +66,7 @@ public class OIDCTest { private static Tomcat rpServer; @BeforeClass - public static void init() { + public static void init() throws Exception { 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", "info"); @@ -75,6 +83,8 @@ public class OIDCTest { initIdp(); initOidc(); + + loginToClientsPage(rpHttpsPort, idpHttpsPort); } private static void initIdp() { @@ -193,16 +203,16 @@ public class OIDCTest { } // Login to the OIDC Clients page + create a new client - @org.junit.Test - public void testLoginToClientsPage() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/fediz-oidc/clients"; + private static void loginToClientsPage(String rpPort, String idpPort) throws Exception { + String url = "https://localhost:" + rpPort + "/fediz-oidc/clients"; String user = "alice"; String password = "ecila"; // Login to the client page successfully - WebClient webClient = setupWebClient(user, password, getIdpHttpsPort()); - final String bodyTextContent = login(url, webClient); - Assert.assertTrue(bodyTextContent.contains("Registered API Clients")); + WebClient webClient = setupWebClient(user, password, idpPort); + HtmlPage loginPage = login(url, webClient); + final String bodyTextContent = loginPage.getBody().getTextContent(); + Assert.assertTrue(bodyTextContent.contains("Registered Clients")); // Now try to register a new client HtmlPage registerPage = webClient.getPage(url + "/register"); @@ -219,13 +229,53 @@ public class OIDCTest { final HtmlPage rpPage = button.click(); String registeredClientPage = rpPage.getBody().getTextContent(); - Assert.assertTrue(registeredClientPage.contains("Registered API Clients")); + Assert.assertTrue(registeredClientPage.contains("Registered Clients")); Assert.assertTrue(registeredClientPage.contains("new-client")); Assert.assertTrue(registeredClientPage.contains("http://127.0.0.1")); webClient.close(); } + // Test that we managed to create a new Client ok + @org.junit.Test + public void testClientCreated() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/fediz-oidc/clients"; + String user = "alice"; + String password = "ecila"; + + // Login to the client page successfully + WebClient webClient = setupWebClient(user, password, getIdpHttpsPort()); + HtmlPage loginPage = login(url, webClient); + final String bodyTextContent = loginPage.getBody().getTextContent(); + Assert.assertTrue(bodyTextContent.contains("Registered Clients")); + + // Get the new client identifier + HtmlTable table = loginPage.getHtmlElementById("registered_clients"); + String clientId = table.getCellAt(1, 1).asText().trim(); + Assert.assertNotNull(clientId); + + // Check the Date + String date = table.getCellAt(1, 2).asText().trim(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US); + dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + Assert.assertEquals(dateFormat.format(new Date()), date); + + // Check the redirect URI + String redirectURI = table.getCellAt(1, 3).asText().trim(); + Assert.assertEquals("http://127.0.0.1", redirectURI); + + Assert.assertEquals(table.getRows().size(), 2); + } + + /* + @org.junit.Test + public void testTemp() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/fediz-oidc/clients"; + System.out.println("URL: " + url); + Thread.sleep(60 * 1000); + } + */ + @org.junit.Test @org.junit.Ignore public void testOIDCLogin() throws Exception { @@ -259,12 +309,12 @@ public class OIDCTest { return webClient; } - private static String login(String url, WebClient webClient) throws IOException { + private static HtmlPage login(String url, WebClient webClient) throws IOException { webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); webClient.getOptions().setJavaScriptEnabled(true); Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); - + // Test the SAML Version here DomNodeList results = idpPage.getElementsByTagName("input"); @@ -281,9 +331,7 @@ public class OIDCTest { final HtmlForm form = idpPage.getFormByName("signinresponseform"); final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - final HtmlPage rpPage = button.click(); - - return rpPage.getBody().getTextContent(); + return button.click(); } private static String loginAndGetAuthorizationCode(
NameIDCreation DateRedirect URI