use of org.springframework.security.oauth.common.signature.SignatureSecret in project spring-security-oauth by spring-projects.
the class OAuthProcessingFilterTests method testValidateSignature.
/**
* test validating the signature.
*/
@Test
public void testValidateSignature() throws Exception {
OAuthProviderProcessingFilter filter = new OAuthProviderProcessingFilter() {
@Override
protected void onValidSignature(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
}
};
ConsumerDetails details = mock(ConsumerDetails.class);
SignatureSecret secret = mock(SignatureSecret.class);
OAuthProviderToken token = mock(OAuthProviderToken.class);
OAuthSignatureMethod sigMethod = mock(OAuthSignatureMethod.class);
ConsumerCredentials credentials = new ConsumerCredentials("id", "sig", "method", "base", "token");
when(details.getAuthorities()).thenReturn(new ArrayList<GrantedAuthority>());
when(details.getSignatureSecret()).thenReturn(secret);
filter.setTokenServices(tokenServices);
when(tokenServices.getToken("token")).thenReturn(token);
filter.setSignatureMethodFactory(signatureFactory);
when(token.getSecret()).thenReturn("shhh!!!");
when(signatureFactory.getSignatureMethod("method", secret, "shhh!!!")).thenReturn(sigMethod);
ConsumerAuthentication authentication = new ConsumerAuthentication(details, credentials);
filter.validateSignature(authentication);
verify(sigMethod).verify("base", "sig");
}
Aggregations