@@ -120,6 +120,22 @@ public void doFilterWhenCustomRequestMatcherThenUses() throws Exception {
120
120
verify (this .repository ).findByRegistrationId ("path" );
121
121
}
122
122
123
+ @ Test
124
+ public void doFilterWhenSetMetadataFilenameThenUses () throws Exception {
125
+ RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations .full ().build ();
126
+ String testMetadataFilename = "test-{registrationId}-metadata.xml" ;
127
+ String fileName = testMetadataFilename .replace ("{registrationId}" , validRegistration .getRegistrationId ());
128
+ String encodedFileName = URLEncoder .encode (fileName , StandardCharsets .UTF_8 .name ());
129
+ String generatedMetadata = "<xml>test</xml>" ;
130
+ this .request .setPathInfo ("/saml2/service-provider-metadata/validRegistration" );
131
+ given (this .resolver .resolve (validRegistration )).willReturn (generatedMetadata );
132
+ this .filter = new Saml2MetadataFilter ((request ) -> validRegistration , this .resolver );
133
+ this .filter .setMetadataFilename (testMetadataFilename );
134
+ this .filter .doFilter (this .request , this .response , this .chain );
135
+ assertThat (this .response .getHeaderValue (HttpHeaders .CONTENT_DISPOSITION )).asString ()
136
+ .isEqualTo ("attachment; filename=\" %s\" ; filename*=UTF-8''%s" , fileName , encodedFileName );
137
+ }
138
+
123
139
@ Test
124
140
public void setRequestMatcherWhenNullThenIllegalArgument () {
125
141
assertThatIllegalArgumentException ().isThrownBy (() -> this .filter .setRequestMatcher (null ));
@@ -138,30 +154,4 @@ public void setMetadataFilenameWhenMissingRegistrationIdVariableThenThrowsExcept
138
154
.withMessage ("metadataFilename must contain a {registrationId} match variable" );
139
155
}
140
156
141
- @ Test
142
- public void doFilterWhenSetMetadataFilenameThenUses () throws Exception {
143
- String testMetadataFilename = "test-{registrationId}-metadata.xml" ;
144
- this .request .setPathInfo ("/saml2/service-provider-metadata/validRegistration" );
145
- RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations .noCredentials ()
146
- .assertingPartyDetails ((party ) -> party .verificationX509Credentials (
147
- (c ) -> c .add (TestSaml2X509Credentials .relyingPartyVerifyingCredential ())))
148
- .build ();
149
- String generatedMetadata = "<xml>test</xml>" ;
150
- given (this .resolver .resolve (validRegistration )).willReturn (generatedMetadata );
151
-
152
- this .filter = new Saml2MetadataFilter ((request ) -> validRegistration , this .resolver );
153
- this .filter .setMetadataFilename (testMetadataFilename );
154
- this .filter .doFilter (this .request , this .response , this .chain );
155
-
156
- verifyNoInteractions (this .chain );
157
- assertThat (this .response .getStatus ()).isEqualTo (200 );
158
- assertThat (this .response .getContentAsString ()).isEqualTo (generatedMetadata );
159
-
160
- String fileName = testMetadataFilename .replace ("{registrationId}" , validRegistration .getRegistrationId ());
161
- String encodedFileName = URLEncoder .encode (fileName , StandardCharsets .UTF_8 .name ());
162
- assertThat (this .response .getHeaderValue (HttpHeaders .CONTENT_DISPOSITION )).asString ()
163
- .isEqualTo ("attachment; filename=\" %s\" ; filename*=UTF-8''%s" , fileName , encodedFileName );
164
- verify (this .resolver ).resolve (validRegistration );
165
- }
166
-
167
157
}
0 commit comments