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