3434/**
3535 * Tests the OAuth signature behavior.
3636 *
37- * See <a href=
38- * "https://oauth.googlecode.com/svn/code/javascript/example/signature.html"
39- * >Signature Tester</a> for an online oauth signature checker.
37+ * See <a href= "https://oauth.googlecode.com/svn/code/javascript/example/signature.html" >Signature Tester</a> for an online oauth signature checker.
4038 *
4139 */
4240public class OAuthSignatureCalculatorTest {
@@ -273,10 +271,13 @@ public void testGetWithRequestBuilderAndQuery() {
273271 assertEquals (params .size (), 2 );
274272
275273 // From the signature tester, the URL should look like:
276- //normalized parameters: file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original
277- //signature base string: GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal
278- //signature: tR3+Ty81lMeYAr/Fid0kMTYa/WM=
279- //Authorization header: OAuth realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
274+ // normalized parameters:
275+ // file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original
276+ // signature base string:
277+ // GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal
278+ // signature: tR3+Ty81lMeYAr/Fid0kMTYa/WM=
279+ // Authorization header: OAuth
280+ // realm="",oauth_version="1.0",oauth_consumer_key="dpf43f3p2l4k3l03",oauth_token="nnch734d00sl2jdk",oauth_timestamp="1191242096",oauth_nonce="kllo9940pd9333jh",oauth_signature_method="HMAC-SHA1",oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
280281
281282 String authHeader = req .getHeaders ().get (AUTHORIZATION );
282283 Matcher m = Pattern .compile ("oauth_signature=\" (.+?)\" " ).matcher (authHeader );
@@ -291,34 +292,36 @@ public void testGetWithRequestBuilderAndQuery() {
291292
292293 assertEquals (sig , "tR3+Ty81lMeYAr/Fid0kMTYa/WM=" );
293294 assertEquals (req .getUrl (), "http://photos.example.net/photos?file=vacation.jpg&size=original" );
294- assertEquals (authHeader , "OAuth oauth_consumer_key=\" dpf43f3p2l4k3l03\" , oauth_token=\" nnch734d00sl2jdk\" , oauth_signature_method=\" HMAC-SHA1\" , oauth_signature=\" tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D\" , oauth_timestamp=\" 1191242096\" , oauth_nonce=\" kllo9940pd9333jh\" , oauth_version=\" 1.0\" " );
295+ assertEquals (
296+ authHeader ,
297+ "OAuth oauth_consumer_key=\" dpf43f3p2l4k3l03\" , oauth_token=\" nnch734d00sl2jdk\" , oauth_signature_method=\" HMAC-SHA1\" , oauth_signature=\" tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D\" , oauth_timestamp=\" 1191242096\" , oauth_nonce=\" kllo9940pd9333jh\" , oauth_version=\" 1.0\" " );
295298 }
296299
297300 @ Test (groups = "standalone" )
298301 public void testWithNullRequestToken () {
299- String url = "http://photos.example.net/photos?file=vacation.jpg&size=original" ;
300- ConsumerKey consumer = new ConsumerKey ("9djdj82h48djs9d2" , CONSUMER_SECRET );
301- RequestToken user = new RequestToken (null , null );
302- OAuthSignatureCalculator calc = new OAuthSignatureCalculator (consumer , user );
303-
304- final Request request = get (url )//
305- .setSignatureCalculator (calc )//
306- .build ();
307-
308- String signatureBaseString = calc .signatureBaseString (//
309- request .getMethod (),//
310- request .getUri (),//
311- 137131201 ,//
312- "ZLc92RAkooZcIO/0cctl0Q==" ,//
313- request .getFormParams (),//
314- request .getQueryParams ()).toString ();
315-
316- assertEquals (signatureBaseString , "GET&" + //
317- "http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" + //
318- "oauth_consumer_key%3D9djdj82h48djs9d2%26" + //
319- "oauth_nonce%3DZLc92RAkooZcIO%252F0cctl0Q%253D%253D%26" + //
320- "oauth_signature_method%3DHMAC-SHA1%26" + //
321- "oauth_timestamp%3D137131201%26" + //
322- "oauth_version%3D1.0%26size%3Doriginal" );
302+ String url = "http://photos.example.net/photos?file=vacation.jpg&size=original" ;
303+ ConsumerKey consumer = new ConsumerKey ("9djdj82h48djs9d2" , CONSUMER_SECRET );
304+ RequestToken user = new RequestToken (null , null );
305+ OAuthSignatureCalculator calc = new OAuthSignatureCalculator (consumer , user );
306+
307+ final Request request = get (url )//
308+ .setSignatureCalculator (calc )//
309+ .build ();
310+
311+ String signatureBaseString = calc .signatureBaseString (//
312+ request .getMethod (),//
313+ request .getUri (),//
314+ 137131201 ,//
315+ "ZLc92RAkooZcIO/0cctl0Q==" ,//
316+ request .getFormParams (),//
317+ request .getQueryParams ()).toString ();
318+
319+ assertEquals (signatureBaseString , "GET&" + //
320+ "http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" + //
321+ "oauth_consumer_key%3D9djdj82h48djs9d2%26" + //
322+ "oauth_nonce%3DZLc92RAkooZcIO%252F0cctl0Q%253D%253D%26" + //
323+ "oauth_signature_method%3DHMAC-SHA1%26" + //
324+ "oauth_timestamp%3D137131201%26" + //
325+ "oauth_version%3D1.0%26size%3Doriginal" );
323326 }
324327}
0 commit comments