| 1 |
package oauth.signpost.signature; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
import oauth.signpost.SignpostTestBase; |
| 5 |
import oauth.signpost.http.HttpParameters; |
| 6 |
|
| 7 |
import org.junit.Test; |
| 8 |
import org.junit.runner.RunWith; |
| 9 |
import org.mockito.runners.MockitoJUnit44Runner; |
| 10 |
|
| 11 |
@RunWith(MockitoJUnit44Runner.class) |
| 12 |
public class SigningStrategyTest extends SignpostTestBase { |
| 13 |
|
| 14 |
@Test |
| 15 |
public void testDifferentSigningStrategies() throws Exception { |
| 16 |
SigningStrategy strategy = null; |
| 17 |
String signature = "123"; |
| 18 |
HttpParameters params = new HttpParameters(); |
| 19 |
params.put("realm", "http://x.com"); |
| 20 |
params.put("oauth_token", "abc"); |
| 21 |
params.put("x_oauth_custom_param", "cde"); |
| 22 |
params.put("should_not_appear", "nono"); |
| 23 |
|
| 24 |
strategy = new AuthorizationHeaderSigningStrategy(); |
| 25 |
assertEquals( |
| 26 |
"OAuth realm=\"http://x.com\", oauth_signature=\"123\", oauth_token=\"abc\", x_oauth_custom_param=\"cde\"", |
| 27 |
strategy.writeSignature(signature, httpGetMock, params)); |
| 28 |
assertEquals( |
| 29 |
"OAuth realm=\"http://x.com\", oauth_signature=\"123\", oauth_token=\"abc\", x_oauth_custom_param=\"cde\"", |
| 30 |
strategy.writeSignature(signature, httpGetMockWithQueryString, params)); |
| 31 |
|
| 32 |
strategy = new QueryStringSigningStrategy(); |
| 33 |
assertEquals( |
| 34 |
"http://www.example.com?oauth_signature=123&oauth_token=abc&x_oauth_custom_param=cde", |
| 35 |
strategy.writeSignature(signature, httpGetMock, params)); |
| 36 |
|
| 37 |
assertEquals( |
| 38 |
"http://www.example.com?foo=bar&oauth_signature=123&oauth_token=abc&x_oauth_custom_param=cde", |
| 39 |
strategy.writeSignature(signature, httpGetMockWithQueryString, params)); |
| 40 |
|
| 41 |
} |
| 42 |
} |