You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/05/16 10:58:35 UTC
cxf git commit: Fixing the old OAuth test
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 <sb...@gmail.com>
Authored: Mon May 16 11:58:17 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
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 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>net.oauth.core</groupId>
- <artifactId>oauth-consumer</artifactId>
- <version>${oauth.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
@@ -222,11 +216,4 @@
</dependencies>
</profile>
</profiles>
- <repositories>
- <repository>
- <id>oauth</id>
- <name>OAuth Repository</name>
- <url>http://oauth.googlecode.com/svn/code/maven/</url>
- </repository>
- </repositories>
</project>
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<String, String> 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<String, String> parameters = new HashMap<String, String>();
- 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<OAuth.Parameter> 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<String, String> 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());
+
}
}