@@ -258,7 +258,43 @@ public void testGetWithRequestBuilder() {
258
258
}
259
259
260
260
assertEquals (sig , "tR3+Ty81lMeYAr/Fid0kMTYa/WM=" );
261
-
261
+ assertEquals ( req . getUrl (), "http://photos.example.net/photos?file=vacation.jpg&size=original" );
262
262
}
263
263
264
+ @ Test (groups = "fast" )
265
+ public void testGetWithRequestBuilderAndQuery () {
266
+ ConsumerKey consumer = new ConsumerKey (CONSUMER_KEY , CONSUMER_SECRET );
267
+ RequestToken user = new RequestToken (TOKEN_KEY , TOKEN_SECRET );
268
+ OAuthSignatureCalculator calc = new StaticOAuthSignatureCalculator (consumer , user , TIMESTAMP , NONCE );
269
+
270
+ String url = "http://photos.example.net/photos?file=vacation.jpg&size=original" ;
271
+
272
+ final Request req = new RequestBuilder ("GET" )//
273
+ .setUri (Uri .create (url ))//
274
+ .setSignatureCalculator (calc )//
275
+ .build ();
276
+
277
+ final List <Param > params = req .getQueryParams ();
278
+ assertEquals (params .size (), 2 );
279
+
280
+ // From the signature tester, the URL should look like:
281
+ //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
282
+ //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
283
+ //signature: tR3+Ty81lMeYAr/Fid0kMTYa/WM=
284
+ //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"
285
+
286
+ String authHeader = req .getHeaders ().get ("Authorization" ).get (0 );
287
+ Matcher m = Pattern .compile ("oauth_signature=\" (.+?)\" " ).matcher (authHeader );
288
+ assertEquals (m .find (), true );
289
+ String encodedSig = m .group (1 );
290
+ String sig = null ;
291
+ try {
292
+ sig = URLDecoder .decode (encodedSig , "UTF-8" );
293
+ } catch (UnsupportedEncodingException e ) {
294
+ fail ("bad encoding" , e );
295
+ }
296
+
297
+ assertEquals (sig , "tR3+Ty81lMeYAr/Fid0kMTYa/WM=" );
298
+ assertEquals (req .getUrl (), "http://photos.example.net/photos?file=vacation.jpg&size=original" );
299
+ }
264
300
}
0 commit comments