17
17
package org .springframework .security .oauth2 .client .http ;
18
18
19
19
import java .io .IOException ;
20
+ import java .net .URI ;
20
21
21
22
import org .junit .jupiter .api .Test ;
22
23
23
24
import org .springframework .http .HttpHeaders ;
25
+ import org .springframework .http .HttpMethod ;
24
26
import org .springframework .http .HttpStatus ;
25
27
import org .springframework .http .client .ClientHttpResponse ;
26
28
import org .springframework .http .converter .HttpMessageConverter ;
@@ -45,6 +47,10 @@ public class OAuth2ErrorResponseErrorHandlerTests {
45
47
46
48
private OAuth2ErrorResponseErrorHandler errorHandler = new OAuth2ErrorResponseErrorHandler ();
47
49
50
+ private URI anyURi = URI .create ("/any" );
51
+
52
+ private HttpMethod anyMethod = HttpMethod .GET ;
53
+
48
54
@ Test
49
55
public void handleErrorWhenErrorResponseBodyThenHandled () {
50
56
// @formatter:off
@@ -55,7 +61,7 @@ public void handleErrorWhenErrorResponseBodyThenHandled() {
55
61
// @formatter:on
56
62
MockClientHttpResponse response = new MockClientHttpResponse (errorResponse .getBytes (), HttpStatus .BAD_REQUEST );
57
63
assertThatExceptionOfType (OAuth2AuthorizationException .class )
58
- .isThrownBy (() -> this .errorHandler .handleError (response ))
64
+ .isThrownBy (() -> this .errorHandler .handleError (this . anyURi , this . anyMethod , response ))
59
65
.withMessage ("[unauthorized_client] The client is not authorized" );
60
66
}
61
67
@@ -74,7 +80,7 @@ public void handleErrorWhenOAuth2ErrorConverterSetThenCalled() throws IOExceptio
74
80
.willReturn (new OAuth2Error ("unauthorized_client" , "The client is not authorized" , null ));
75
81
76
82
assertThatExceptionOfType (OAuth2AuthorizationException .class )
77
- .isThrownBy (() -> this .errorHandler .handleError (response ))
83
+ .isThrownBy (() -> this .errorHandler .handleError (this . anyURi , this . anyMethod , response ))
78
84
.withMessage ("[unauthorized_client] The client is not authorized" );
79
85
verify (oauth2ErrorConverter ).read (eq (OAuth2Error .class ), eq (response ));
80
86
}
@@ -85,7 +91,7 @@ public void handleErrorWhenErrorResponseWwwAuthenticateHeaderThenHandled() {
85
91
MockClientHttpResponse response = new MockClientHttpResponse (new byte [0 ], HttpStatus .BAD_REQUEST );
86
92
response .getHeaders ().add (HttpHeaders .WWW_AUTHENTICATE , wwwAuthenticateHeader );
87
93
assertThatExceptionOfType (OAuth2AuthorizationException .class )
88
- .isThrownBy (() -> this .errorHandler .handleError (response ))
94
+ .isThrownBy (() -> this .errorHandler .handleError (this . anyURi , this . anyMethod , response ))
89
95
.withMessage ("[insufficient_scope] The access token expired" );
90
96
}
91
97
@@ -95,15 +101,15 @@ public void handleErrorWhenErrorResponseWithInvalidWwwAuthenticateHeaderThenHand
95
101
MockClientHttpResponse response = new MockClientHttpResponse (new byte [0 ], HttpStatus .BAD_REQUEST );
96
102
response .getHeaders ().add (HttpHeaders .WWW_AUTHENTICATE , invalidWwwAuthenticateHeader );
97
103
assertThatExceptionOfType (OAuth2AuthorizationException .class )
98
- .isThrownBy (() -> this .errorHandler .handleError (response ))
104
+ .isThrownBy (() -> this .errorHandler .handleError (this . anyURi , this . anyMethod , response ))
99
105
.withMessage ("[server_error] " );
100
106
}
101
107
102
108
@ Test
103
109
public void handleErrorWhenErrorResponseWithInvalidStatusCodeThenHandled () {
104
110
CustomMockClientHttpResponse response = new CustomMockClientHttpResponse (new byte [0 ], 596 );
105
111
assertThatExceptionOfType (IllegalArgumentException .class )
106
- .isThrownBy (() -> this .errorHandler .handleError (response ))
112
+ .isThrownBy (() -> this .errorHandler .handleError (this . anyURi , this . anyMethod , response ))
107
113
.withMessage ("No matching constant for [596]" );
108
114
}
109
115
0 commit comments