|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
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,35 @@ 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.addParameter("access_token", ""); |
| 270 | + assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request)) |
| 271 | + .withMessageContaining("The requested token parameter is an empty string") |
| 272 | + .satisfies((e) -> { |
| 273 | + BearerTokenError error = (BearerTokenError) e.getError(); |
| 274 | + assertThat(error.getErrorCode()).isEqualTo(BearerTokenErrorCodes.INVALID_REQUEST); |
| 275 | + assertThat(error.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST); |
| 276 | + }); |
| 277 | + } |
| 278 | + |
| 279 | + @Test |
| 280 | + public void resolveWhenFormParameterIsPresentAndEmptyStringThenTokenIsNotResolved() { |
| 281 | + this.resolver.setAllowFormEncodedBodyParameter(true); |
| 282 | + MockHttpServletRequest request = new MockHttpServletRequest(); |
| 283 | + request.setMethod("POST"); |
| 284 | + request.setContentType("application/x-www-form-urlencoded"); |
| 285 | + request.addParameter("access_token", ""); |
| 286 | + assertThatExceptionOfType(OAuth2AuthenticationException.class).isThrownBy(() -> this.resolver.resolve(request)) |
| 287 | + .withMessageContaining("The requested token parameter is an empty string") |
| 288 | + .satisfies((e) -> { |
| 289 | + BearerTokenError error = (BearerTokenError) e.getError(); |
| 290 | + assertThat(error.getErrorCode()).isEqualTo(BearerTokenErrorCodes.INVALID_REQUEST); |
| 291 | + assertThat(error.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST); |
| 292 | + }); |
| 293 | + } |
| 294 | + |
261 | 295 | }
|
0 commit comments