45
45
*/
46
46
public class OidcProviderConfigurationEndpointFilterTests {
47
47
private static final String DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI = "/.well-known/openid-configuration" ;
48
- private final OidcProviderConfigurationEndpointFilter filter = new OidcProviderConfigurationEndpointFilter ();
49
48
50
49
@ AfterEach
51
50
public void cleanup () {
@@ -54,39 +53,51 @@ public void cleanup() {
54
53
55
54
@ Test
56
55
public void setProviderConfigurationCustomizerWhenNullThenThrowIllegalArgumentException () {
57
- assertThatThrownBy (() -> this .filter .setProviderConfigurationCustomizer (null ))
56
+ OidcProviderConfigurationEndpointFilter filter = new OidcProviderConfigurationEndpointFilter (
57
+ DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI );
58
+
59
+ assertThatThrownBy (() -> filter .setProviderConfigurationCustomizer (null ))
58
60
.isInstanceOf (IllegalArgumentException .class )
59
61
.hasMessage ("providerConfigurationCustomizer cannot be null" );
60
62
}
61
63
62
64
@ Test
63
65
public void doFilterWhenNotConfigurationRequestThenNotProcessed () throws Exception {
66
+ OidcProviderConfigurationEndpointFilter filter = new OidcProviderConfigurationEndpointFilter (
67
+ DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI );
68
+
64
69
String requestUri = "/path" ;
65
70
MockHttpServletRequest request = new MockHttpServletRequest ("GET" , requestUri );
66
71
request .setServletPath (requestUri );
67
72
MockHttpServletResponse response = new MockHttpServletResponse ();
68
73
FilterChain filterChain = mock (FilterChain .class );
69
74
70
- this . filter .doFilter (request , response , filterChain );
75
+ filter .doFilter (request , response , filterChain );
71
76
72
77
verify (filterChain ).doFilter (any (HttpServletRequest .class ), any (HttpServletResponse .class ));
73
78
}
74
79
75
80
@ Test
76
81
public void doFilterWhenConfigurationRequestPostThenNotProcessed () throws Exception {
82
+ OidcProviderConfigurationEndpointFilter filter = new OidcProviderConfigurationEndpointFilter (
83
+ DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI );
84
+
77
85
String requestUri = DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI ;
78
86
MockHttpServletRequest request = new MockHttpServletRequest ("POST" , requestUri );
79
87
request .setServletPath (requestUri );
80
88
MockHttpServletResponse response = new MockHttpServletResponse ();
81
89
FilterChain filterChain = mock (FilterChain .class );
82
90
83
- this . filter .doFilter (request , response , filterChain );
91
+ filter .doFilter (request , response , filterChain );
84
92
85
93
verify (filterChain ).doFilter (any (HttpServletRequest .class ), any (HttpServletResponse .class ));
86
94
}
87
95
88
96
@ Test
89
97
public void doFilterWhenConfigurationRequestThenConfigurationResponse () throws Exception {
98
+ OidcProviderConfigurationEndpointFilter filter = new OidcProviderConfigurationEndpointFilter (
99
+ "/issuer1" + DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI );
100
+
90
101
String issuer = "https://example.com/issuer1" ;
91
102
String authorizationEndpoint = "/oauth2/v1/authorize" ;
92
103
String tokenEndpoint = "/oauth2/v1/token" ;
@@ -108,13 +119,13 @@ public void doFilterWhenConfigurationRequestThenConfigurationResponse() throws E
108
119
.build ();
109
120
AuthorizationServerContextHolder .setContext (new TestAuthorizationServerContext (authorizationServerSettings , null ));
110
121
111
- String requestUri = DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI ;
122
+ String requestUri = "/issuer1" + DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI ;
112
123
MockHttpServletRequest request = new MockHttpServletRequest ("GET" , requestUri );
113
124
request .setServletPath (requestUri );
114
125
MockHttpServletResponse response = new MockHttpServletResponse ();
115
126
FilterChain filterChain = mock (FilterChain .class );
116
127
117
- this . filter .doFilter (request , response , filterChain );
128
+ filter .doFilter (request , response , filterChain );
118
129
119
130
verifyNoInteractions (filterChain );
120
131
@@ -140,6 +151,9 @@ public void doFilterWhenConfigurationRequestThenConfigurationResponse() throws E
140
151
141
152
@ Test
142
153
public void doFilterWhenAuthorizationServerSettingsWithInvalidIssuerThenThrowIllegalArgumentException () {
154
+ OidcProviderConfigurationEndpointFilter filter = new OidcProviderConfigurationEndpointFilter (
155
+ DEFAULT_OIDC_PROVIDER_CONFIGURATION_ENDPOINT_URI );
156
+
143
157
AuthorizationServerSettings authorizationServerSettings = AuthorizationServerSettings .builder ()
144
158
.issuer ("https://this is an invalid URL" )
145
159
.build ();
@@ -152,7 +166,7 @@ public void doFilterWhenAuthorizationServerSettingsWithInvalidIssuerThenThrowIll
152
166
FilterChain filterChain = mock (FilterChain .class );
153
167
154
168
assertThatIllegalArgumentException ()
155
- .isThrownBy (() -> this . filter .doFilter (request , response , filterChain ))
169
+ .isThrownBy (() -> filter .doFilter (request , response , filterChain ))
156
170
.withMessage ("issuer must be a valid URL" );
157
171
}
158
172
0 commit comments