Skip to content

Commit

Permalink
Fix checkstyle violations for test module in 1.3.x
Browse files Browse the repository at this point in the history
Issue gh-1624
  • Loading branch information
jgrandja committed May 23, 2024
1 parent fa59682 commit 448a782
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ public void authenticateWhenCustomAuthorizationConsentRequiredThenUsed() {
this.authenticationProvider.setAuthorizationConsentRequired(authorizationConsentRequired);

RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
when(this.registeredClientRepository.findByClientId(eq(registeredClient.getClientId())))
.thenReturn(registeredClient);
given(this.registeredClientRepository.findByClientId(eq(registeredClient.getClientId())))
.willReturn(registeredClient);

String redirectUri = registeredClient.getRedirectUris().toArray(new String[0])[1];
OAuth2AuthorizationCodeRequestAuthenticationToken authentication = new OAuth2AuthorizationCodeRequestAuthenticationToken(
AUTHORIZATION_URI, registeredClient.getClientId(), principal, redirectUri, STATE,
AUTHORIZATION_URI, registeredClient.getClientId(), this.principal, redirectUri, STATE,
registeredClient.getScopes(), null);

OAuth2AuthorizationCodeRequestAuthenticationToken authenticationResult = (OAuth2AuthorizationCodeRequestAuthenticationToken) this.authenticationProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void authenticateWhenCustomAuthenticationValidatorThenUsed() {
Consumer<OAuth2ClientCredentialsAuthenticationContext> authenticationValidator = mock(Consumer.class);
this.authenticationProvider.setAuthenticationValidator(authenticationValidator);

when(this.jwtEncoder.encode(any())).thenReturn(createJwt(registeredClient.getScopes()));
given(this.jwtEncoder.encode(any())).willReturn(createJwt(registeredClient.getScopes()));

this.authenticationProvider.authenticate(authentication);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

/**
* Tests for {@link OAuth2TokenExchangeAuthenticationProvider}.
Expand Down Expand Up @@ -180,7 +180,7 @@ public void authenticateWhenSubjectTokenNotFoundThenThrowOAuth2AuthenticationExc
.authorizationGrantType(AuthorizationGrantType.TOKEN_EXCHANGE)
.build();
OAuth2TokenExchangeAuthenticationToken authentication = createDelegationRequest(registeredClient);
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).thenReturn(null);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(null);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -203,7 +203,7 @@ public void authenticateWhenSubjectTokenNotActiveThenThrowOAuth2AuthenticationEx
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createExpiredAccessToken(SUBJECT_TOKEN))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).thenReturn(authorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -226,7 +226,7 @@ public void authenticateWhenSubjectTokenTypeJwtAndSubjectTokenFormatReferenceThe
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(SUBJECT_TOKEN), withTokenFormat(OAuth2TokenFormat.REFERENCE))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).thenReturn(authorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -252,7 +252,7 @@ public void authenticateWhenSubjectPrincipalNullThenThrowOAuth2AuthenticationExc
.attributes((attributes) -> attributes.remove(Principal.class.getName()))
.build();
// @formatter:on
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).thenReturn(authorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -275,8 +275,8 @@ public void authenticateWhenActorTokenNotFoundThenThrowOAuth2AuthenticationExcep
OAuth2Authorization subjectAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(SUBJECT_TOKEN))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, (OAuth2Authorization) null);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, (OAuth2Authorization) null);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -303,8 +303,8 @@ public void authenticateWhenActorTokenNotActiveThenThrowOAuth2AuthenticationExce
OAuth2Authorization actorAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createExpiredAccessToken(ACTOR_TOKEN))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -331,8 +331,8 @@ public void authenticateWhenActorTokenTypeJwtAndActorTokenFormatReferenceThenThr
OAuth2Authorization actorAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(ACTOR_TOKEN), withTokenFormat(OAuth2TokenFormat.REFERENCE))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand Down Expand Up @@ -365,8 +365,8 @@ public void authenticateWhenMayActAndActorIssClaimNotAuthorizedThenThrowOAuth2Au
OAuth2Authorization actorAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(ACTOR_TOKEN), withClaims(actorTokenClaims))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand Down Expand Up @@ -399,8 +399,8 @@ public void authenticateWhenMayActAndActorSubClaimNotAuthorizedThenThrowOAuth2Au
OAuth2Authorization actorAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(ACTOR_TOKEN), withClaims(actorTokenClaims))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand Down Expand Up @@ -428,8 +428,8 @@ public void authenticateWhenMayActAndImpersonationThenThrowOAuth2AuthenticationE
.token(createAccessToken(SUBJECT_TOKEN), withClaims(Map.of("may_act", authorizedActorClaims)))
.build();
// @formatter:on
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand All @@ -456,8 +456,8 @@ public void authenticateWhenInvalidScopeInRequestThenThrowOAuth2AuthenticationEx
OAuth2Authorization actorAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(ACTOR_TOKEN))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand Down Expand Up @@ -485,8 +485,8 @@ public void authenticateWhenInvalidScopeInSubjectAuthorizationThenThrowOAuth2Aut
OAuth2Authorization actorAuthorization = TestOAuth2Authorizations.authorization(registeredClient)
.token(createAccessToken(ACTOR_TOKEN))
.build();
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
// @formatter:off
assertThatExceptionOfType(OAuth2AuthenticationException.class)
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
Expand Down Expand Up @@ -514,10 +514,10 @@ public void authenticateWhenNoActorTokenAndValidTokenExchangeThenReturnAccessTok
.attribute(Principal.class.getName(), userPrincipal)
.build();
// @formatter:on
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization);
OAuth2AccessToken accessToken = createAccessToken("token-value");
when(this.tokenGenerator.generate(any(OAuth2TokenContext.class))).thenReturn(accessToken);
given(this.tokenGenerator.generate(any(OAuth2TokenContext.class))).willReturn(accessToken);
OAuth2AccessTokenAuthenticationToken authenticationResult = (OAuth2AccessTokenAuthenticationToken) this.authenticationProvider
.authenticate(authentication);
assertThat(authenticationResult.getRegisteredClient()).isEqualTo(registeredClient);
Expand Down Expand Up @@ -571,10 +571,10 @@ public void authenticateWhenNoActorTokenAndPreviousActorThenReturnAccessTokenFor
.attribute(Principal.class.getName(), subjectPrincipal)
.build();
// @formatter:on
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization);
OAuth2AccessToken accessToken = createAccessToken("token-value");
when(this.tokenGenerator.generate(any(OAuth2TokenContext.class))).thenReturn(accessToken);
given(this.tokenGenerator.generate(any(OAuth2TokenContext.class))).willReturn(accessToken);
OAuth2AccessTokenAuthenticationToken authenticationResult = (OAuth2AccessTokenAuthenticationToken) this.authenticationProvider
.authenticate(authentication);
assertThat(authenticationResult.getRegisteredClient()).isEqualTo(registeredClient);
Expand Down Expand Up @@ -634,10 +634,10 @@ public void authenticateWhenActorTokenAndValidTokenExchangeThenReturnAccessToken
.token(createAccessToken(ACTOR_TOKEN), withClaims(actor2.getClaims()))
.build();
// @formatter:on
when(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.thenReturn(subjectAuthorization, actorAuthorization);
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class)))
.willReturn(subjectAuthorization, actorAuthorization);
OAuth2AccessToken accessToken = createAccessToken("token-value");
when(this.tokenGenerator.generate(any(OAuth2TokenContext.class))).thenReturn(accessToken);
given(this.tokenGenerator.generate(any(OAuth2TokenContext.class))).willReturn(accessToken);
OAuth2AccessTokenAuthenticationToken authenticationResult = (OAuth2AccessTokenAuthenticationToken) this.authenticationProvider
.authenticate(authentication);
assertThat(authenticationResult.getRegisteredClient()).isEqualTo(registeredClient);
Expand Down
Loading

0 comments on commit 448a782

Please sign in to comment.