@Test public void testWithStarQueryParameterValue() { ConsumerKey consumer = new ConsumerKey("key", "secret"); RequestToken user = new RequestToken(null, null); OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user); final Request request = get("http://term.ie/oauth/example/request_token.php?testvalue=*").build(); String signatureBaseString = calc.signatureBaseString( // request, // 1469019732, // "6ad17f97334700f3ec2df0631d5b7511") .toString(); assertEquals( signatureBaseString, "GET&" + // "http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&" // + "oauth_consumer_key%3Dkey%26" // + "oauth_nonce%3D6ad17f97334700f3ec2df0631d5b7511%26" // + "oauth_signature_method%3DHMAC-SHA1%26" // + "oauth_timestamp%3D1469019732%26" // + "oauth_version%3D1.0%26" // + "testvalue%3D%252A"); }
// sample from RFC https://tools.ietf.org/html/rfc5849#section-3.4.1 private void testSignatureBaseString(Request request) { ConsumerKey consumer = new ConsumerKey("9djdj82h48djs9d2", CONSUMER_SECRET); RequestToken user = new RequestToken("kkk9d7dh3k39sjv7", TOKEN_SECRET); OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user); String signatureBaseString = calc.signatureBaseString( // request, // 137131201, // "7d8f3e4a") .toString(); assertEquals( signatureBaseString, "POST&" // + "http%3A%2F%2Fexample.com%2Frequest" // + "&a2%3Dr%2520b%26" // + "a3%3D2%2520q%26" + "a3%3Da%26" // + "b5%3D%253D%25253D%26" // + "c%2540%3D%26" // + "c2%3D%26" // + "oauth_consumer_key%3D9djdj82h48djs9d2%26" // + "oauth_nonce%3D7d8f3e4a%26" // + "oauth_signature_method%3DHMAC-SHA1%26" // + "oauth_timestamp%3D137131201%26" // + "oauth_token%3Dkkk9d7dh3k39sjv7%26" // + "oauth_version%3D1.0"); }
@Test public void testWithNullRequestToken() { ConsumerKey consumer = new ConsumerKey("9djdj82h48djs9d2", CONSUMER_SECRET); RequestToken user = new RequestToken(null, null); OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user); final Request request = get("http://photos.example.net/photos?file=vacation.jpg&size=original").build(); String signatureBaseString = calc.signatureBaseString( // request, // 137131201, // "ZLc92RAkooZcIO/0cctl0Q==") .toString(); assertEquals( signatureBaseString, "GET&" + // "http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26" + // "oauth_consumer_key%3D9djdj82h48djs9d2%26" + // "oauth_nonce%3DZLc92RAkooZcIO%252F0cctl0Q%253D%253D%26" + // "oauth_signature_method%3DHMAC-SHA1%26" + // "oauth_timestamp%3D137131201%26" + // "oauth_version%3D1.0%26size%3Doriginal"); }