replaced mock client auth with concrete OAuth2Request object

pull/477/head
William Kim 2013-07-30 10:55:50 -04:00
parent ad2ace6d74
commit 1392faa83c
1 changed files with 10 additions and 15 deletions

View File

@ -16,6 +16,14 @@
******************************************************************************/ ******************************************************************************/
package org.mitre.oauth2.service.impl; package org.mitre.oauth2.service.impl;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
@ -38,7 +46,6 @@ import org.springframework.security.authentication.AuthenticationCredentialsNotF
import org.springframework.security.oauth2.common.exceptions.InvalidClientException; import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
import org.springframework.security.oauth2.common.exceptions.InvalidScopeException; import org.springframework.security.oauth2.common.exceptions.InvalidScopeException;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException; import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.OAuth2Request; import org.springframework.security.oauth2.provider.OAuth2Request;
import org.springframework.security.oauth2.provider.TokenRequest; import org.springframework.security.oauth2.provider.TokenRequest;
@ -46,14 +53,6 @@ import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* @author wkim * @author wkim
* *
@ -102,16 +101,13 @@ public class TestDefaultOAuth2ProviderTokenService {
Mockito.reset(tokenRepository, authenticationHolderRepository, clientDetailsService, tokenEnhancer); Mockito.reset(tokenRepository, authenticationHolderRepository, clientDetailsService, tokenEnhancer);
authentication = Mockito.mock(OAuth2Authentication.class); authentication = Mockito.mock(OAuth2Authentication.class);
Mockito.when(authentication.getOAuth2Request()).thenReturn(Mockito.mock(OAuth2Request.class)); OAuth2Request clientAuth = new OAuth2Request(null, clientId, null, true, scope, null, null, null);
OAuth2Request clientAuth = authentication.getOAuth2Request(); Mockito.when(authentication.getOAuth2Request()).thenReturn(clientAuth);
client = Mockito.mock(ClientDetailsEntity.class); client = Mockito.mock(ClientDetailsEntity.class);
Mockito.when(client.getClientId()).thenReturn(clientId); Mockito.when(client.getClientId()).thenReturn(clientId);
Mockito.when(clientDetailsService.loadClientByClientId(clientId)).thenReturn(client); Mockito.when(clientDetailsService.loadClientByClientId(clientId)).thenReturn(client);
Mockito.when(clientAuth.getClientId()).thenReturn(clientId);
Mockito.when(clientAuth.getScope()).thenReturn(scope);
// by default in tests, allow refresh tokens // by default in tests, allow refresh tokens
Mockito.when(client.isAllowRefresh()).thenReturn(true); Mockito.when(client.isAllowRefresh()).thenReturn(true);
@ -130,7 +126,6 @@ public class TestDefaultOAuth2ProviderTokenService {
Mockito.when(refreshToken.getAuthenticationHolder()).thenReturn(storedAuthHolder); Mockito.when(refreshToken.getAuthenticationHolder()).thenReturn(storedAuthHolder);
Mockito.when(storedAuthHolder.getAuthentication()).thenReturn(storedAuthentication); Mockito.when(storedAuthHolder.getAuthentication()).thenReturn(storedAuthentication);
Mockito.when(storedAuthentication.getOAuth2Request()).thenReturn(storedAuthRequest); Mockito.when(storedAuthentication.getOAuth2Request()).thenReturn(storedAuthRequest);
Mockito.when(storedAuthRequest.getScope()).thenReturn(storedScope);
} }
/** /**