Skip to content

Commit

Permalink
Merge remote branch 'hugo/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandezpablo85 committed Jun 7, 2010
2 parents 0737651 + 1e564f0 commit 13dc4a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
target/
.DS_Store
bin/
.idea
*.iws
*.ipr
*.iml
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<packaging>jar</packaging>
<version>0.6.6</version>
<version>0.6.7-SNAPSHOT</version>
<name>Simple OAuth Library</name>
<dependencies>

Expand Down
24 changes: 18 additions & 6 deletions src/test/java/org/scribe/oauth/OAuthParametersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,34 @@ String getTimestampInSeconds() {

@Test
public void shouldSetupDefaultParams(){
String encodedString = "oauth_consumer_key=any&oauth_nonce=827ccb0eea8a706c4c34a16891f84e7b&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0";
assertEquals(encodedString, params.asSortedFormEncodedString());
String encodedString = "oauth_consumer_key=any&oauth_nonce=ee1f212e0ae38d7ccd8b4377e722199d&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0";
assertEqualsIgnoreOAuthNonce(encodedString, params.asSortedFormEncodedString());
}

@Test
public void shouldReturnEncodedParams(){
params.put("q","foo");
params.put("other param", "bar");
String encodedString = "oauth_consumer_key=any&oauth_nonce=827ccb0eea8a706c4c34a16891f84e7b&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0&other%20param=bar&q=foo";
assertEquals(encodedString, params.asSortedFormEncodedString());
String encodedString = "oauth_consumer_key=any&oauth_nonce=a4955bf6ae6349f3e0bff8319c53df16&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0&other%20param=bar&q=foo";
assertEqualsIgnoreOAuthNonce(encodedString, params.asSortedFormEncodedString());
}

@Test
public void shouldReturnOAuthHeader(){
String header = "OAuth oauth_consumer_key=\"any\", oauth_nonce=\"827ccb0eea8a706c4c34a16891f84e7b\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"12345\", oauth_version=\"1.0\"";
assertEquals(header,params.asOAuthHeader());
String header = "OAuth oauth_consumer_key=\"any\", oauth_nonce=\"4b722ffd811b585b0fbdf98048da65a6\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"12345\", oauth_version=\"1.0\"";
assertEqualsIgnoreOAuthNonce(header,params.asOAuthHeader());
}

/**
* Asserts that the two strings are equal, ignoring any {@code oauth_nonce} parameter.
* @param expected expected value
* @param actual the value to check against {@code expected}
*/
private static void assertEqualsIgnoreOAuthNonce(String expected, String actual){
final String regex = "oauth_nonce=\"?[0-9a-fA-F]+\"?";
String cleanedExpected = expected.replaceAll(regex, "");
String cleanedActual = actual.replaceAll(regex, "");
assertEquals(cleanedExpected, cleanedActual);
}

}

0 comments on commit 13dc4a6

Please sign in to comment.