|  | 
| 21 | 21 | import org.junit.jupiter.api.BeforeEach; | 
| 22 | 22 | import org.junit.jupiter.api.Test; | 
| 23 | 23 | 
 | 
|  | 24 | +import org.springframework.http.HttpStatus; | 
| 24 | 25 | import org.springframework.mock.web.MockHttpServletRequest; | 
| 25 | 26 | import org.springframework.security.oauth2.core.OAuth2AuthenticationException; | 
|  | 27 | +import org.springframework.security.oauth2.server.resource.BearerTokenError; | 
|  | 28 | +import org.springframework.security.oauth2.server.resource.BearerTokenErrorCodes; | 
| 26 | 29 | 
 | 
| 27 | 30 | import static org.assertj.core.api.Assertions.assertThat; | 
| 28 | 31 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | 
| @@ -258,4 +261,36 @@ public void resolveWhenQueryParameterIsPresentAndNotSupportedThenTokenIsNotResol | 
| 258 | 261 | 		assertThat(this.resolver.resolve(request)).isNull(); | 
| 259 | 262 | 	} | 
| 260 | 263 | 
 | 
|  | 264 | +	@Test | 
|  | 265 | +	public void resolveWhenQueryParameterIsPresentAndEmptyStringThenTokenIsNotResolved() { | 
|  | 266 | +		this.resolver.setAllowUriQueryParameter(true); | 
|  | 267 | +		MockHttpServletRequest request = new MockHttpServletRequest(); | 
|  | 268 | +		request.setMethod("GET"); | 
|  | 269 | +		request.setQueryString("access_token="); | 
|  | 270 | +		request.addParameter("access_token", ""); | 
|  | 271 | +		assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request)) | 
|  | 272 | +				.withMessageContaining("The requested token parameter is an empty string") | 
|  | 273 | +				.satisfies(e -> { | 
|  | 274 | +					BearerTokenError error = (BearerTokenError) e.getError(); | 
|  | 275 | +					assertThat(error.getErrorCode()).isEqualTo(BearerTokenErrorCodes.INVALID_REQUEST); | 
|  | 276 | +					assertThat(error.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST); | 
|  | 277 | +				}); | 
|  | 278 | +	} | 
|  | 279 | + | 
|  | 280 | +	@Test | 
|  | 281 | +	public void resolveWhenFormParameterIsPresentAndEmptyStringThenTokenIsNotResolved() { | 
|  | 282 | +		this.resolver.setAllowFormEncodedBodyParameter(true); | 
|  | 283 | +		MockHttpServletRequest request = new MockHttpServletRequest(); | 
|  | 284 | +		request.setMethod("POST"); | 
|  | 285 | +		request.setContentType("application/x-www-form-urlencoded"); | 
|  | 286 | +		request.addParameter("access_token", ""); | 
|  | 287 | +		assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request)) | 
|  | 288 | +				.withMessageContaining("The requested token parameter is an empty string") | 
|  | 289 | +				.satisfies(e -> { | 
|  | 290 | +					BearerTokenError error = (BearerTokenError) e.getError(); | 
|  | 291 | +					assertThat(error.getErrorCode()).isEqualTo(BearerTokenErrorCodes.INVALID_REQUEST); | 
|  | 292 | +					assertThat(error.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST); | 
|  | 293 | +				}); | 
|  | 294 | +	} | 
|  | 295 | + | 
| 261 | 296 | } | 
0 commit comments