Fix test by returning a new OAuth2Authentication instead of mocking it
parent
d361f01999
commit
52da5e769a
|
@ -30,6 +30,8 @@ import org.mitre.oauth2.model.OAuth2RefreshTokenEntity;
|
|||
import org.mitre.oauth2.service.IntrospectionResultAssembler;
|
||||
import org.mitre.openid.connect.model.UserInfo;
|
||||
import org.mitre.uma.model.Permission;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||
import org.springframework.security.oauth2.provider.OAuth2Request;
|
||||
|
||||
|
@ -59,7 +61,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
|
||||
// given
|
||||
OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"), null, "Bearer",
|
||||
authentication("name", request("clientId")));
|
||||
oauth2AuthenticationWithUser(oauth2Request("clientId"), "name"));
|
||||
|
||||
UserInfo userInfo = userInfo("sub");
|
||||
|
||||
|
@ -89,7 +91,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
// given
|
||||
OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"),
|
||||
permissions(permission(1L, "foo", "bar")),
|
||||
"Bearer", authentication("name", request("clientId")));
|
||||
"Bearer", oauth2AuthenticationWithUser(oauth2Request("clientId"), "name"));
|
||||
|
||||
UserInfo userInfo = userInfo("sub");
|
||||
|
||||
|
@ -127,7 +129,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
|
||||
// given
|
||||
OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"), null, "Bearer",
|
||||
authentication("name", request("clientId")));
|
||||
oauth2AuthenticationWithUser(oauth2Request("clientId"), "name"));
|
||||
|
||||
Set<String> authScopes = scopes("foo", "bar", "baz");
|
||||
|
||||
|
@ -154,7 +156,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
|
||||
// given
|
||||
OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer",
|
||||
authentication("name", request("clientId")));
|
||||
oauth2AuthenticationWithUser(oauth2Request("clientId"), "name"));
|
||||
|
||||
UserInfo userInfo = userInfo("sub");
|
||||
|
||||
|
@ -181,7 +183,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
|
||||
// given
|
||||
OAuth2RefreshTokenEntity refreshToken = refreshToken(new Date(123 * 1000L),
|
||||
authentication("name", request("clientId", scopes("foo", "bar"))));
|
||||
oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name"));
|
||||
|
||||
UserInfo userInfo = userInfo("sub");
|
||||
|
||||
|
@ -209,7 +211,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
|
||||
// given
|
||||
OAuth2RefreshTokenEntity refreshToken = refreshToken(new Date(123 * 1000L),
|
||||
authentication("name", request("clientId", scopes("foo", "bar"))));
|
||||
oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name"));
|
||||
|
||||
Set<String> authScopes = scopes("foo", "bar", "baz");
|
||||
|
||||
|
@ -235,7 +237,7 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
|
||||
// given
|
||||
OAuth2RefreshTokenEntity refreshToken = refreshToken(null,
|
||||
authentication("name", request("clientId", scopes("foo", "bar"))));
|
||||
oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name"));
|
||||
|
||||
UserInfo userInfo = userInfo("sub");
|
||||
|
||||
|
@ -279,18 +281,20 @@ public class TestDefaultIntrospectionResultAssembler {
|
|||
return refreshToken;
|
||||
}
|
||||
|
||||
private OAuth2Authentication authentication(String name, OAuth2Request request) {
|
||||
OAuth2Authentication authentication = mock(OAuth2Authentication.class);
|
||||
given(authentication.getName()).willReturn(name);
|
||||
given(authentication.getOAuth2Request()).willReturn(request);
|
||||
return authentication;
|
||||
private OAuth2Authentication oauth2AuthenticationWithUser(OAuth2Request request, String username) {
|
||||
UsernamePasswordAuthenticationToken userAuthentication = new UsernamePasswordAuthenticationToken(username, "somepassword");
|
||||
return oauth2Authentication(request, userAuthentication);
|
||||
}
|
||||
|
||||
private OAuth2Request request(String clientId) {
|
||||
return request(clientId, null);
|
||||
private OAuth2Authentication oauth2Authentication(OAuth2Request request, Authentication userAuthentication) {
|
||||
return new OAuth2Authentication(request, userAuthentication);
|
||||
}
|
||||
|
||||
private OAuth2Request oauth2Request(String clientId) {
|
||||
return oauth2Request(clientId, null);
|
||||
}
|
||||
|
||||
private OAuth2Request request(String clientId, Set<String> scopes) {
|
||||
private OAuth2Request oauth2Request(String clientId, Set<String> scopes) {
|
||||
return new OAuth2Request(null, clientId, null, true, scopes, null, null, null, null);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue