Skip to content

Commit

Permalink
Polish gh-1729
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrandja committed Oct 4, 2024
1 parent 8c297b1 commit 68300d4
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ public void doFilterWhenDeviceAuthorizationRequestThenDeviceAuthorizationRespons
assertThat(deviceCode.getExpiresAt()).isAfter(deviceCode.getIssuedAt());
}

// gh-1714
@Test
public void doFilterWhenDeviceAuthorizationRequestWithContextPathThenDeviceAuthorizationResponse() throws Exception {
public void doFilterWhenDeviceAuthorizationRequestWithContextPathThenVerificationUriIncludesContextPath()
throws Exception {
Authentication authenticationResult = createAuthentication();
given(this.authenticationManager.authenticate(any(Authentication.class))).willReturn(authenticationResult);

Expand All @@ -256,22 +258,14 @@ public void doFilterWhenDeviceAuthorizationRequestWithContextPathThenDeviceAutho
this.filter.doFilter(request, response, filterChain);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());

ArgumentCaptor<OAuth2DeviceAuthorizationRequestAuthenticationToken> deviceAuthorizationRequestAuthenticationCaptor = ArgumentCaptor
.forClass(OAuth2DeviceAuthorizationRequestAuthenticationToken.class);
verify(this.authenticationManager).authenticate(deviceAuthorizationRequestAuthenticationCaptor.capture());
verify(this.authenticationManager).authenticate(any(OAuth2DeviceAuthorizationRequestAuthenticationToken.class));
verifyNoInteractions(filterChain);

OAuth2DeviceAuthorizationResponse deviceAuthorizationResponse = readDeviceAuthorizationResponse(response);
String verificationUri = ISSUER_URI + "/contextPath" + VERIFICATION_URI;
assertThat(deviceAuthorizationResponse.getVerificationUri()).isEqualTo(verificationUri);
assertThat(deviceAuthorizationResponse.getVerificationUriComplete())
.isEqualTo("%s?%s=%s".formatted(verificationUri, OAuth2ParameterNames.USER_CODE, USER_CODE));
OAuth2DeviceCode deviceCode = deviceAuthorizationResponse.getDeviceCode();
assertThat(deviceCode.getTokenValue()).isEqualTo(DEVICE_CODE);
assertThat(deviceCode.getExpiresAt()).isAfter(deviceCode.getIssuedAt());
OAuth2UserCode userCode = deviceAuthorizationResponse.getUserCode();
assertThat(userCode.getTokenValue()).isEqualTo(USER_CODE);
assertThat(deviceCode.getExpiresAt()).isAfter(deviceCode.getIssuedAt());
.isEqualTo("%s?%s=%s".formatted(verificationUri, OAuth2ParameterNames.USER_CODE, USER_CODE));
}

@Test
Expand Down

0 comments on commit 68300d4

Please sign in to comment.