Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9C2552009C5 for ; Mon, 16 May 2016 12:58:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9AC3C160A16; Mon, 16 May 2016 10:58:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BCA091609B0 for ; Mon, 16 May 2016 12:58:36 +0200 (CEST) Received: (qmail 20358 invoked by uid 500); 16 May 2016 10:58:35 -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 20349 invoked by uid 99); 16 May 2016 10:58:35 -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; Mon, 16 May 2016 10:58:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BBB9CDFA3E; Mon, 16 May 2016 10:58:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <1b64c3a20d3a420c838a6e382fcf5d1f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: Fixing the old OAuth test Date: Mon, 16 May 2016 10:58:35 +0000 (UTC) archived-at: Mon, 16 May 2016 10:58:37 -0000 Repository: cxf Updated Branches: refs/heads/master 5c5f752d2 -> a732913f6 Fixing the old OAuth test Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a732913f Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a732913f Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a732913f Branch: refs/heads/master Commit: a732913f6aacda7effc8347e4a29fbe67607cf23 Parents: 5c5f752 Author: Sergey Beryozkin Authored: Mon May 16 11:58:17 2016 +0100 Committer: Sergey Beryozkin Committed: Mon May 16 11:58:17 2016 +0100 ---------------------------------------------------------------------- systests/rs-security/pom.xml | 13 --- .../jaxrs/security/oauth/OAuthTestUtils.java | 27 +----- .../oauth/TemporaryCredentialServiceTest.java | 87 +++++--------------- 3 files changed, 20 insertions(+), 107 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/a732913f/systests/rs-security/pom.xml ---------------------------------------------------------------------- diff --git a/systests/rs-security/pom.xml b/systests/rs-security/pom.xml index 19a03ed..b046927 100644 --- a/systests/rs-security/pom.xml +++ b/systests/rs-security/pom.xml @@ -132,12 +132,6 @@ test - net.oauth.core - oauth-consumer - ${oauth.version} - test - - org.springframework spring-web test @@ -222,11 +216,4 @@ - - - oauth - OAuth Repository - http://oauth.googlecode.com/svn/code/maven/ - - http://git-wip-us.apache.org/repos/asf/cxf/blob/a732913f/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java index 26f4adb..a54ee5c 100644 --- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/OAuthTestUtils.java @@ -22,18 +22,10 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URISyntaxException; import java.util.List; -import java.util.Map; import net.oauth.OAuth; -import net.oauth.OAuthAccessor; -import net.oauth.OAuthConsumer; -import net.oauth.OAuthException; import net.oauth.OAuthMessage; -import net.oauth.ParameterStyle; -import net.oauth.client.OAuthClient; -import net.oauth.client.URLConnectionClient; public final class OAuthTestUtils { @@ -41,28 +33,11 @@ public final class OAuthTestUtils { public static final String APPLICATION_NAME = "Test Oauth 1.0 application"; public static final String CLIENT_ID = "12345678"; public static final String CLIENT_SECRET = "secret"; - public static final String[] SIGN_METHOD = {"HMAC-SHA1", "PLAINTEXT"}; - + private OAuthTestUtils() { } - public static OAuthMessage access(String url, String method, Map params, - ParameterStyle style) - throws IOException, URISyntaxException, OAuthException { - - OAuthConsumer consumer = new OAuthConsumer(null, params.get(OAuth.OAUTH_CONSUMER_KEY), - CLIENT_SECRET, null); - - OAuthAccessor accessor = new OAuthAccessor(consumer); - - OAuthMessage msg = accessor - .newRequestMessage(method, url, params.entrySet()); - - OAuthClient client = new OAuthClient(new URLConnectionClient()); - - return client.access(msg, style); - } public static String readBody(OAuthMessage msg) throws IOException { StringBuilder body = new StringBuilder(); http://git-wip-us.apache.org/repos/asf/cxf/blob/a732913f/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/TemporaryCredentialServiceTest.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/TemporaryCredentialServiceTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/TemporaryCredentialServiceTest.java index c6c5261..a23961b 100644 --- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/TemporaryCredentialServiceTest.java +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth/TemporaryCredentialServiceTest.java @@ -18,25 +18,18 @@ */ package org.apache.cxf.systest.jaxrs.security.oauth; -import java.io.IOException; -import java.net.URISyntaxException; +import java.net.URI; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import net.oauth.OAuth; -import net.oauth.OAuthException; -import net.oauth.OAuthMessage; -import net.oauth.ParameterStyle; -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.common.util.StringUtils; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.rs.security.oauth.client.OAuthClientUtils; +import org.apache.cxf.rs.security.oauth.client.OAuthClientUtils.Token; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -45,8 +38,6 @@ public class TemporaryCredentialServiceTest extends AbstractBusClientServerTestB public static final String TEMPORARY_CREDENTIALS_URL = "/a/oauth/initiate"; public static final String HOST = "http://localhost:"; - private static final Logger LOG = LogUtils.getL7dLogger(TemporaryCredentialServiceTest.class); - @BeforeClass public static void startServers() throws Exception { assertTrue("server did not launch correctly", @@ -57,62 +48,22 @@ public class TemporaryCredentialServiceTest extends AbstractBusClientServerTestB @Test public void testGetTemporaryCredentialsURIQuery() throws Exception { Map parameters = new HashMap(); - parameters.put(OAuth.OAUTH_CALLBACK, OAuthTestUtils.CALLBACK); - //check all parameter transmissions - for (ParameterStyle style : ParameterStyle.values()) { - //for all signing methods - for (String signMethod : OAuthTestUtils.SIGN_METHOD) { - LOG.log(Level.INFO, "Preparing request with parameter style: {0} and signature method: {1}", - new String[] {style.toString(), signMethod}); - - parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, signMethod); - parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString()); - parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000)); - parameters.put(OAuth.OAUTH_CONSUMER_KEY, OAuthTestUtils.CLIENT_ID); - OAuthMessage message = invokeRequestToken(parameters, style, OAuthServer.PORT); - - //test response ok - boolean isFormEncoded = OAuth.isFormEncoded(message.getBodyType()); - Assert.assertTrue(isFormEncoded); - - List responseParams = OAuthTestUtils.getResponseParams(message); - - String wwwHeader = message.getHeader("Authenticate"); - Assert.assertNull(wwwHeader); - - String callbacConf = OAuthTestUtils - .findOAuthParameter(responseParams, OAuth.OAUTH_CALLBACK_CONFIRMED) - .getValue(); - Assert.assertEquals("true", callbacConf); - - String oauthToken = OAuthTestUtils.findOAuthParameter(responseParams, OAuth.OAUTH_TOKEN) - .getKey(); - Assert.assertFalse(StringUtils.isEmpty(oauthToken)); - - String tokenSecret = OAuthTestUtils - .findOAuthParameter(responseParams, OAuth.OAUTH_TOKEN_SECRET) - .getKey(); - Assert.assertFalse(StringUtils.isEmpty(tokenSecret)); - - - //test wrong client id - parameters.put(OAuth.OAUTH_CONSUMER_KEY, "wrong"); - message = invokeRequestToken(parameters, style, OAuthServer.PORT); - String response = message.getHeader("oauth_problem"); - Assert.assertEquals(OAuth.Problems.CONSUMER_KEY_UNKNOWN, response); - } - } - } - - protected OAuthMessage invokeRequestToken(Map parameters, ParameterStyle style, - int port) - throws IOException, URISyntaxException, OAuthException { - OAuthMessage message; - String uri = HOST + port + TEMPORARY_CREDENTIALS_URL; - message = OAuthTestUtils - .access(uri, OAuthMessage.POST, parameters, style); - return message; + parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, "HMAC-SHA1"); + parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString()); + parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000)); + + String uri = HOST + OAuthServer.PORT + TEMPORARY_CREDENTIALS_URL; + WebClient wc = WebClient.create(uri); + + Token t = OAuthClientUtils.getRequestToken(wc, + new OAuthClientUtils.Consumer(OAuthTestUtils.CLIENT_ID, OAuthTestUtils.CLIENT_SECRET), + URI.create(OAuthTestUtils.CALLBACK), + parameters); + assertNotNull(t); + assertNotNull(t.getToken()); + assertNotNull(t.getSecret()); + } }