|
@@ -191,6 +191,7 @@ public class OAuth2DeviceCodeAuthenticationProviderTests {
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
Authentication authentication = createAuthentication(registeredClient);
|
|
Authentication authentication = createAuthentication(registeredClient);
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
|
|
+ .token(createDeviceCode())
|
|
.token(createUserCode())
|
|
.token(createUserCode())
|
|
.build();
|
|
.build();
|
|
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
|
|
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
|
|
@@ -209,7 +210,7 @@ public class OAuth2DeviceCodeAuthenticationProviderTests {
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void authenticateWhenDeviceCodeIsInvalidatedThenThrowOAuth2AuthenticationException() {
|
|
|
|
|
|
+ public void authenticateWhenDeviceCodeAndUserCodeAreInvalidatedThenThrowOAuth2AuthenticationException() {
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
Authentication authentication = createAuthentication(registeredClient);
|
|
Authentication authentication = createAuthentication(registeredClient);
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
@@ -231,13 +232,36 @@ public class OAuth2DeviceCodeAuthenticationProviderTests {
|
|
verifyNoInteractions(this.tokenGenerator);
|
|
verifyNoInteractions(this.tokenGenerator);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void authenticateWhenDeviceCodeIsInvalidatedThenThrowOAuth2AuthenticationException() {
|
|
|
|
+ RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
|
|
+ Authentication authentication = createAuthentication(registeredClient);
|
|
|
|
+ OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
|
|
+ .token(createDeviceCode(), withInvalidated())
|
|
|
|
+ .token(createUserCode())
|
|
|
|
+ .build();
|
|
|
|
+ given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
|
|
|
|
+ // @formatter:off
|
|
|
|
+ assertThatExceptionOfType(OAuth2AuthenticationException.class)
|
|
|
|
+ .isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
|
|
|
|
+ .extracting(OAuth2AuthenticationException::getError)
|
|
|
|
+ .extracting(OAuth2Error::getErrorCode)
|
|
|
|
+ .isEqualTo(OAuth2ErrorCodes.INVALID_GRANT);
|
|
|
|
+ // @formatter:on
|
|
|
|
+
|
|
|
|
+ verify(this.authorizationService).findByToken(DEVICE_CODE,
|
|
|
|
+ OAuth2DeviceCodeAuthenticationProvider.DEVICE_CODE_TOKEN_TYPE);
|
|
|
|
+ verifyNoMoreInteractions(this.authorizationService);
|
|
|
|
+ verifyNoInteractions(this.tokenGenerator);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void authenticateWhenDeviceCodeIsExpiredThenThrowOAuth2AuthenticationException() {
|
|
public void authenticateWhenDeviceCodeIsExpiredThenThrowOAuth2AuthenticationException() {
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
|
|
Authentication authentication = createAuthentication(registeredClient);
|
|
Authentication authentication = createAuthentication(registeredClient);
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
OAuth2Authorization authorization = TestOAuth2Authorizations.authorization(registeredClient)
|
|
.token(createExpiredDeviceCode())
|
|
.token(createExpiredDeviceCode())
|
|
- .token(createUserCode(), withInvalidated())
|
|
|
|
|
|
+ .token(createUserCode())
|
|
.build();
|
|
.build();
|
|
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
|
|
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
|
|
// @formatter:off
|
|
// @formatter:off
|