Permalink
Browse files

SECOAUTH-84 upgrade main project to JUnit 4.8

  • Loading branch information...
1 parent 5b91744 commit bdd9f9c152f929b9ed9a3ade5153135c75cc191d @dsyer dsyer committed Jul 28, 2011
Showing with 2,447 additions and 1,975 deletions.
  1. +251 −0 spring-eclipse-code-conventions.xml
  2. +67 −61 spring-security-oauth/src/test/java/net/oauth/signature/TestGoogleCodeCompatibility.java
  3. +19 −15 spring-security-oauth/src/test/java/org/springframework/security/oauth/common/TestOAuthCodec.java
  4. +54 −44 ...java/org/springframework/security/oauth/common/signature/TestCoreOAuthSignatureMethodFactory.java
  5. +45 −37 ...c/test/java/org/springframework/security/oauth/common/signature/TestHMAC_SHA1SignatureMethod.java
  6. +12 −11 ...c/test/java/org/springframework/security/oauth/common/signature/TestPlainTextSignatureMethod.java
  7. +60 −60 ...rc/test/java/org/springframework/security/oauth/common/signature/TestRSA_SHA1SignatureMethod.java
  8. +6 −5 ...uth/src/test/java/org/springframework/security/oauth/consumer/SteamHandlerForTestingPurposes.java
  9. +465 −413 ...oauth/src/test/java/org/springframework/security/oauth/consumer/TestCoreOAuthConsumerSupport.java
  10. +35 −34 spring-security-oauth/src/test/java/org/springframework/security/oauth/consumer/TestGoogleOAuth.java
  11. +125 −111 ...uth/src/test/java/org/springframework/security/oauth/consumer/TestOAuthConsumerContextFilter.java
  12. +44 −37 ...th/src/test/java/org/springframework/security/oauth/provider/TestAccessTokenProcessingFilter.java
  13. +66 −58 ...oauth/src/test/java/org/springframework/security/oauth/provider/TestCoreOAuthProviderSupport.java
  14. +324 −302 ...ty-oauth/src/test/java/org/springframework/security/oauth/provider/TestOAuthProcessingFilter.java
  15. +55 −49 .../java/org/springframework/security/oauth/provider/TestOAuthUserAuthorizationProcessingFilter.java
  16. +42 −34 .../test/java/org/springframework/security/oauth/provider/TestProtectedResourceProcessingFilter.java
  17. +81 −72 .../org/springframework/security/oauth/provider/TestUnauthenticatedRequestTokenProcessingFilter.java
  18. +36 −33 ...springframework/security/oauth/provider/TestUserAuthorizationSuccessfulAuthenticationHandler.java
  19. +51 −53 ...th/src/test/java/org/springframework/security/oauth/provider/nonce/TestInMemoryNonceServices.java
  20. +86 −80 ...c/test/java/org/springframework/security/oauth2/config/TestClientServiceBeanDefinitionParser.java
  21. +5 −2 ...uth/src/test/java/org/springframework/security/oauth2/consumer/TestOAuth2ClientContextFilter.java
  22. +8 −4 ...rc/test/java/org/springframework/security/oauth2/consumer/TestOAuth2ClientHttpRequestFactory.java
  23. +37 −33 ...rity-oauth/src/test/java/org/springframework/security/oauth2/consumer/TestOAuth2ErrorHandler.java
  24. +87 −77 ...test/java/org/springframework/security/oauth2/provider/TestAccessGrantAuthenticationProvider.java
  25. +97 −86 ...auth/src/test/java/org/springframework/security/oauth2/provider/TestJdbcClientDetailsService.java
  26. +4 −4 ...a/org/springframework/security/oauth2/provider/token/TestInMemoryOAuth2ProviderTokenServices.java
  27. +19 −20 .../java/org/springframework/security/oauth2/provider/token/TestJdbcOAuth2ProviderTokenServices.java
  28. +133 −113 ...pringframework/security/oauth2/provider/token/TestRandomValueOAuth2ProviderTokenServicesBase.java
  29. +12 −12 ...g/springframework/security/oauth2/provider/verification/TestInMemoryVerificationCodeServices.java
  30. +5 −6 ...a/org/springframework/security/oauth2/provider/verification/TestJdbcVerificationCodeServices.java
  31. +116 −109 ...a/org/springframework/security/oauth2/provider/verification/TestVerificationCodeServicesBase.java
Oops, something went wrong.
@@ -17,10 +17,13 @@
package net.oauth.signature;
import junit.framework.TestCase;
+
+import org.junit.Test;
import org.springframework.security.oauth.common.signature.HMAC_SHA1SignatureMethod;
import org.springframework.security.oauth.common.OAuthCodec;
import org.springframework.security.oauth.provider.CoreOAuthProviderSupport;
import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
@@ -31,74 +34,77 @@
/**
* @author Ryan Heaton
+ * @author Dave Syer
*/
-public class TestGoogleCodeCompatibility extends TestCase {
+public class TestGoogleCodeCompatibility {
- /**
- * tests compatibilty with the google code HMAC_SHA1 signature.
- */
- public void testHMAC_SHA1_1() throws Exception {
- HMAC_SHA1 theirMethod = new HMAC_SHA1();
- String baseString = "GET&http%3A%2F%2Flocalhost%3A8080%2Fgrailscrowd%2Foauth%2Frequest_token&oauth_consumer_key%3Dtonrconsumerkey%26oauth_nonce%3D1227967049787975000%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1227967049%26oauth_version%3D1.0";
- theirMethod.setConsumerSecret("xxxxxx");
- theirMethod.setTokenSecret("");
- SecretKeySpec spec = new SecretKeySpec("xxxxxx&".getBytes("UTF-8"), HMAC_SHA1SignatureMethod.MAC_NAME);
- HMAC_SHA1SignatureMethod ourMethod = new HMAC_SHA1SignatureMethod(spec);
- String theirSignature = theirMethod.getSignature(baseString);
- String ourSignature = ourMethod.sign(baseString);
- assertEquals(theirSignature, ourSignature);
- }
+ /**
+ * tests compatibilty with the google code HMAC_SHA1 signature.
+ */
+ @Test
+ public void testHMAC_SHA1_1() throws Exception {
+ HMAC_SHA1 theirMethod = new HMAC_SHA1();
+ String baseString = "GET&http%3A%2F%2Flocalhost%3A8080%2Fgrailscrowd%2Foauth%2Frequest_token&oauth_consumer_key%3Dtonrconsumerkey%26oauth_nonce%3D1227967049787975000%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1227967049%26oauth_version%3D1.0";
+ theirMethod.setConsumerSecret("xxxxxx");
+ theirMethod.setTokenSecret("");
+ SecretKeySpec spec = new SecretKeySpec("xxxxxx&".getBytes("UTF-8"), HMAC_SHA1SignatureMethod.MAC_NAME);
+ HMAC_SHA1SignatureMethod ourMethod = new HMAC_SHA1SignatureMethod(spec);
+ String theirSignature = theirMethod.getSignature(baseString);
+ String ourSignature = ourMethod.sign(baseString);
+ assertEquals(theirSignature, ourSignature);
+ }
- /**
- * tests compatibility of calculating the signature base string.
- */
- public void testCalculateSignatureBaseString() throws Exception {
- final String baseUrl = "http://www.springframework.org/schema/security/";
- CoreOAuthProviderSupport support = new CoreOAuthProviderSupport() {
- @Override
- protected String getBaseUrl(HttpServletRequest request) {
- return baseUrl;
- }
- };
- HttpServletRequest request = createMock(HttpServletRequest.class);
+ /**
+ * tests compatibility of calculating the signature base string.
+ */
+ @Test
+ public void testCalculateSignatureBaseString() throws Exception {
+ final String baseUrl = "http://www.springframework.org/schema/security/";
+ CoreOAuthProviderSupport support = new CoreOAuthProviderSupport() {
+ @Override
+ protected String getBaseUrl(HttpServletRequest request) {
+ return baseUrl;
+ }
+ };
+ HttpServletRequest request = createMock(HttpServletRequest.class);
- Map<String, String[]> parameterMap = new HashMap<String, String[]>();
- parameterMap.put("a", new String[] {"value-a"});
- parameterMap.put("b", new String[] {"value-b"});
- parameterMap.put("c", new String[] {"value-c"});
- parameterMap.put("param[1]", new String[] {"aaa", "bbb"});
+ Map<String, String[]> parameterMap = new HashMap<String, String[]>();
+ parameterMap.put("a", new String[] { "value-a" });
+ parameterMap.put("b", new String[] { "value-b" });
+ parameterMap.put("c", new String[] { "value-c" });
+ parameterMap.put("param[1]", new String[] { "aaa", "bbb" });
- expect(request.getParameterNames()).andReturn(Collections.enumeration(parameterMap.keySet()));
- for (Map.Entry<String, String[]> param : parameterMap.entrySet()) {
- expect(request.getParameterValues(param.getKey())).andReturn(param.getValue());
- }
+ expect(request.getParameterNames()).andReturn(Collections.enumeration(parameterMap.keySet()));
+ for (Map.Entry<String, String[]> param : parameterMap.entrySet()) {
+ expect(request.getParameterValues(param.getKey())).andReturn(param.getValue());
+ }
- String header = "OAuth realm=\"http://sp.example.com/\"," +
- " oauth_consumer_key=\"0685bd9184jfhq22\"," +
- " oauth_token=\"ad180jjd733klru7\"," +
- " oauth_signature_method=\"HMAC-SHA1\"," +
- " oauth_signature=\"wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D\"," +
- " oauth_timestamp=\"137131200\"," +
- " oauth_callback=\"" + OAuthCodec.oauthEncode("http://myhost.com/callback") + "\"," +
- " oauth_nonce=\"4572616e48616d6d65724c61686176\"," +
- " oauth_version=\"1.0\"";
- expect(request.getHeaders("Authorization")).andReturn(Collections.enumeration(Arrays.asList(header)));
- expect(request.getMethod()).andReturn("GET");
- replay(request);
- String ours = support.getSignatureBaseString(request);
- verify(request);
- reset(request);
+ String header = "OAuth realm=\"http://sp.example.com/\","
+ + " oauth_consumer_key=\"0685bd9184jfhq22\","
+ + " oauth_token=\"ad180jjd733klru7\","
+ + " oauth_signature_method=\"HMAC-SHA1\","
+ + " oauth_signature=\"wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D\","
+ + " oauth_timestamp=\"137131200\"," + " oauth_callback=\""
+ + OAuthCodec.oauthEncode("http://myhost.com/callback") + "\","
+ + " oauth_nonce=\"4572616e48616d6d65724c61686176\","
+ + " oauth_version=\"1.0\"";
+ expect(request.getHeaders("Authorization")).andReturn(Collections.enumeration(Arrays.asList(header)));
+ expect(request.getMethod()).andReturn("GET");
+ replay(request);
+ String ours = support.getSignatureBaseString(request);
+ verify(request);
+ reset(request);
- expect(request.getMethod()).andReturn("GET");
- expect(request.getHeaders("Authorization")).andReturn(Collections.enumeration(Arrays.asList(header)));
- expect(request.getParameterMap()).andReturn(parameterMap);
- expect(request.getHeaderNames()).andReturn(null);
- replay(request);
- OAuthMessage message = OAuthServlet.getMessage(request, baseUrl);
- verify(request);
+ expect(request.getMethod()).andReturn("GET");
+ expect(request.getHeaders("Authorization")).andReturn(Collections.enumeration(Arrays.asList(header)));
+ expect(request.getParameterMap()).andReturn(parameterMap);
+ expect(request.getHeaderNames()).andReturn(null);
+ replay(request);
+ OAuthMessage message = OAuthServlet.getMessage(request, baseUrl);
+ verify(request);
- String theirs = OAuthSignatureMethod.getBaseString(message);
- assertEquals(theirs, ours);
- }
+ String theirs = OAuthSignatureMethod.getBaseString(message);
+ assertEquals(theirs, ours);
+ }
}
@@ -16,25 +16,29 @@
package org.springframework.security.oauth.common;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
/**
* @author Ryan Heaton
*/
-public class TestOAuthCodec extends TestCase {
+public class TestOAuthCodec {
- /**
- * tests idempotent decode.
- */
- public void testIdempotentDecode() throws Exception {
- String original = "4KaVKEnW6e1a+vwJTpz0VFqIaGU=";
- String encoded = OAuthCodec.oauthEncode(original);
- String decoded = OAuthCodec.oauthDecode(encoded);
- assertEquals(original, decoded);
- decoded = OAuthCodec.oauthDecode(encoded);
- assertEquals(original, decoded);
- decoded = OAuthCodec.oauthDecode(decoded);
- assertFalse(original.equals(decoded));
- }
+ /**
+ * tests idempotent decode.
+ */
+ @Test
+ public void testIdempotentDecode() throws Exception {
+ String original = "4KaVKEnW6e1a+vwJTpz0VFqIaGU=";
+ String encoded = OAuthCodec.oauthEncode(original);
+ String decoded = OAuthCodec.oauthDecode(encoded);
+ assertEquals(original, decoded);
+ decoded = OAuthCodec.oauthDecode(encoded);
+ assertEquals(original, decoded);
+ decoded = OAuthCodec.oauthDecode(decoded);
+ assertFalse(original.equals(decoded));
+ }
}
@@ -16,60 +16,70 @@
package org.springframework.security.oauth.common.signature;
-import junit.framework.TestCase;
-import org.springframework.security.oauth.provider.token.OAuthProviderTokenImpl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import javax.crypto.spec.SecretKeySpec;
-import java.util.Arrays;
-import java.security.KeyPairGenerator;
import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.util.Arrays;
+
+import javax.crypto.spec.SecretKeySpec;
+
+import org.junit.Test;
+import org.springframework.security.oauth.provider.token.OAuthProviderTokenImpl;
/**
* @author Ryan Heaton
*/
-public class TestCoreOAuthSignatureMethodFactory extends TestCase {
+public class TestCoreOAuthSignatureMethodFactory {
- /**
- * tests getting the signature method.
- */
- public void testGetSignatureMethod() throws Exception {
- CoreOAuthSignatureMethodFactory factory = new CoreOAuthSignatureMethodFactory();
- OAuthProviderTokenImpl token = new OAuthProviderTokenImpl();
- token.setSecret("token_SHHHHHHHHHHHHHH");
- SharedConsumerSecret sharedSecret = new SharedConsumerSecret("consumer_shhhhhhhhhh");
- try {
- factory.getSignatureMethod("unknown", sharedSecret, token.getSecret());
- fail("should fail with unknown signature method.");
- }
- catch (UnsupportedSignatureMethodException e) {
- //fall thru...
- }
+ /**
+ * tests getting the signature method.
+ */
+ @Test
+ public void testGetSignatureMethod() throws Exception {
+ CoreOAuthSignatureMethodFactory factory = new CoreOAuthSignatureMethodFactory();
+ OAuthProviderTokenImpl token = new OAuthProviderTokenImpl();
+ token.setSecret("token_SHHHHHHHHHHHHHH");
+ SharedConsumerSecret sharedSecret = new SharedConsumerSecret("consumer_shhhhhhhhhh");
+ try {
+ factory.getSignatureMethod("unknown", sharedSecret, token.getSecret());
+ fail("should fail with unknown signature method.");
+ } catch (UnsupportedSignatureMethodException e) {
+ // fall thru...
+ }
- try {
- factory.getSignatureMethod(PlainTextSignatureMethod.SIGNATURE_NAME, sharedSecret, token.getSecret());
- fail("plain text shouldn't be supported by default.");
- }
- catch (UnsupportedSignatureMethodException e) {
- //fall thru...
- }
+ try {
+ factory.getSignatureMethod(PlainTextSignatureMethod.SIGNATURE_NAME, sharedSecret, token.getSecret());
+ fail("plain text shouldn't be supported by default.");
+ } catch (UnsupportedSignatureMethodException e) {
+ // fall thru...
+ }
- factory.setSupportPlainText(true);
- OAuthSignatureMethod signatureMethod = factory.getSignatureMethod(PlainTextSignatureMethod.SIGNATURE_NAME, sharedSecret, token.getSecret());
- assertTrue(signatureMethod instanceof PlainTextSignatureMethod);
- assertEquals("consumer_shhhhhhhhhh%26token_SHHHHHHHHHHHHHH", ((PlainTextSignatureMethod) signatureMethod).getSecret());
+ factory.setSupportPlainText(true);
+ OAuthSignatureMethod signatureMethod = factory.getSignatureMethod(PlainTextSignatureMethod.SIGNATURE_NAME,
+ sharedSecret, token.getSecret());
+ assertTrue(signatureMethod instanceof PlainTextSignatureMethod);
+ assertEquals("consumer_shhhhhhhhhh%26token_SHHHHHHHHHHHHHH",
+ ((PlainTextSignatureMethod) signatureMethod).getSecret());
- signatureMethod = factory.getSignatureMethod(HMAC_SHA1SignatureMethod.SIGNATURE_NAME, sharedSecret, token.getSecret());
- assertTrue(signatureMethod instanceof HMAC_SHA1SignatureMethod);
- SecretKeySpec spec = new SecretKeySpec("consumer_shhhhhhhhhh&token_SHHHHHHHHHHHHHH".getBytes("UTF-8"), HMAC_SHA1SignatureMethod.MAC_NAME);
- assertTrue(Arrays.equals(spec.getEncoded(), ((HMAC_SHA1SignatureMethod) signatureMethod).getSecretKey().getEncoded()));
+ signatureMethod = factory.getSignatureMethod(HMAC_SHA1SignatureMethod.SIGNATURE_NAME, sharedSecret,
+ token.getSecret());
+ assertTrue(signatureMethod instanceof HMAC_SHA1SignatureMethod);
+ SecretKeySpec spec = new SecretKeySpec("consumer_shhhhhhhhhh&token_SHHHHHHHHHHHHHH".getBytes("UTF-8"),
+ HMAC_SHA1SignatureMethod.MAC_NAME);
+ assertTrue(Arrays.equals(spec.getEncoded(), ((HMAC_SHA1SignatureMethod) signatureMethod).getSecretKey()
+ .getEncoded()));
- KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
- generator.initialize(1024);
- KeyPair keyPair = generator.generateKeyPair();
- signatureMethod = factory.getSignatureMethod(RSA_SHA1SignatureMethod.SIGNATURE_NAME, new RSAKeySecret(keyPair.getPrivate(), keyPair.getPublic()), token.getSecret());
- assertTrue(signatureMethod instanceof RSA_SHA1SignatureMethod);
- assertEquals(keyPair.getPrivate(), ((RSA_SHA1SignatureMethod) signatureMethod).getPrivateKey());
- assertEquals(keyPair.getPublic(), ((RSA_SHA1SignatureMethod) signatureMethod).getPublicKey());
- }
+ KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
+ generator.initialize(1024);
+ KeyPair keyPair = generator.generateKeyPair();
+ signatureMethod = factory.getSignatureMethod(RSA_SHA1SignatureMethod.SIGNATURE_NAME,
+ new RSAKeySecret(keyPair.getPrivate(), keyPair.getPublic()), token.getSecret());
+ assertTrue(signatureMethod instanceof RSA_SHA1SignatureMethod);
+ assertEquals(keyPair.getPrivate(), ((RSA_SHA1SignatureMethod) signatureMethod).getPrivateKey());
+ assertEquals(keyPair.getPublic(), ((RSA_SHA1SignatureMethod) signatureMethod).getPublicKey());
+ }
}
Oops, something went wrong.

0 comments on commit bdd9f9c

Please sign in to comment.