@@ -106,6 +106,29 @@ public void testCreateRequest() throws IOException {
106
106
assertEquals ("https://projectId.firebaseapp.com/__/auth/handler" , spConfig .get ("callbackUri" ));
107
107
}
108
108
109
+ @ Test
110
+ public void testCreateRequestX509Certificates () throws IOException {
111
+ SamlProviderConfig .CreateRequest createRequest =
112
+ new SamlProviderConfig .CreateRequest ()
113
+ .addX509Certificate ("certificate1" )
114
+ .addAllX509Certificates (ImmutableList .of ("certificate2" , "certificate3" ))
115
+ .addX509Certificate ("certificate4" );
116
+
117
+ Map <String ,Object > properties = createRequest .getProperties ();
118
+ assertEquals (1 , properties .size ());
119
+ Map <String , Object > idpConfig = (Map <String , Object >) properties .get ("idpConfig" );
120
+ assertNotNull (idpConfig );
121
+ assertEquals (1 , idpConfig .size ());
122
+
123
+ List <Object > idpCertificates = (List <Object >) idpConfig .get ("idpCertificates" );
124
+ assertNotNull (idpCertificates );
125
+ assertEquals (4 , idpCertificates .size ());
126
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate1" ), idpCertificates .get (0 ));
127
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate2" ), idpCertificates .get (1 ));
128
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate3" ), idpCertificates .get (2 ));
129
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate4" ), idpCertificates .get (3 ));
130
+ }
131
+
109
132
@ Test (expected = IllegalArgumentException .class )
110
133
public void testCreateRequestMissingProviderId () {
111
134
new SamlProviderConfig .CreateRequest ().setProviderId (null );
@@ -141,6 +164,16 @@ public void testCreateRequestMissingX509Certificate() {
141
164
new SamlProviderConfig .CreateRequest ().addX509Certificate (null );
142
165
}
143
166
167
+ @ Test (expected = IllegalArgumentException .class )
168
+ public void testCreateRequestNullX509CertificatesCollection () {
169
+ new SamlProviderConfig .CreateRequest ().addAllX509Certificates (null );
170
+ }
171
+
172
+ @ Test (expected = IllegalArgumentException .class )
173
+ public void testCreateRequestEmptyX509CertificatesCollection () {
174
+ new SamlProviderConfig .CreateRequest ().addAllX509Certificates (ImmutableList .<String >of ());
175
+ }
176
+
144
177
@ Test (expected = IllegalArgumentException .class )
145
178
public void testCreateRequestMissingRpEntityId () {
146
179
new SamlProviderConfig .CreateRequest ().setRpEntityId (null );
@@ -155,4 +188,136 @@ public void testCreateRequestMissingCallbackUrl() {
155
188
public void testCreateRequestInvalidCallbackUrl () {
156
189
new SamlProviderConfig .CreateRequest ().setCallbackUrl ("not a valid url" );
157
190
}
191
+
192
+ @ Test
193
+ public void testUpdateRequestFromSamlProviderConfig () throws IOException {
194
+ SamlProviderConfig config = jsonFactory .fromString (SAML_JSON_STRING , SamlProviderConfig .class );
195
+
196
+ SamlProviderConfig .UpdateRequest updateRequest = config .updateRequest ();
197
+
198
+ assertEquals ("saml.provider-id" , updateRequest .getProviderId ());
199
+ assertTrue (updateRequest .getProperties ().isEmpty ());
200
+ }
201
+
202
+ @ Test
203
+ public void testUpdateRequest () throws IOException {
204
+ SamlProviderConfig .UpdateRequest updateRequest =
205
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" );
206
+ updateRequest
207
+ .setDisplayName ("DISPLAY_NAME" )
208
+ .setEnabled (false )
209
+ .setIdpEntityId ("IDP_ENTITY_ID" )
210
+ .setSsoUrl ("https://example.com/login" )
211
+ .addX509Certificate ("certificate1" )
212
+ .addX509Certificate ("certificate2" )
213
+ .setRpEntityId ("RP_ENTITY_ID" )
214
+ .setCallbackUrl ("https://projectId.firebaseapp.com/__/auth/handler" );
215
+
216
+ Map <String ,Object > properties = updateRequest .getProperties ();
217
+ assertEquals (4 , properties .size ());
218
+ assertEquals ("DISPLAY_NAME" , (String ) properties .get ("displayName" ));
219
+ assertFalse ((boolean ) properties .get ("enabled" ));
220
+
221
+ Map <String , Object > idpConfig = (Map <String , Object >) properties .get ("idpConfig" );
222
+ assertNotNull (idpConfig );
223
+ assertEquals (3 , idpConfig .size ());
224
+ assertEquals ("IDP_ENTITY_ID" , idpConfig .get ("idpEntityId" ));
225
+ assertEquals ("https://example.com/login" , idpConfig .get ("ssoUrl" ));
226
+ List <Object > idpCertificates = (List <Object >) idpConfig .get ("idpCertificates" );
227
+ assertNotNull (idpCertificates );
228
+ assertEquals (2 , idpCertificates .size ());
229
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate1" ), idpCertificates .get (0 ));
230
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate2" ), idpCertificates .get (1 ));
231
+
232
+ Map <String , Object > spConfig = (Map <String , Object >) properties .get ("spConfig" );
233
+ assertNotNull (spConfig );
234
+ assertEquals (2 , spConfig .size ());
235
+ assertEquals ("RP_ENTITY_ID" , spConfig .get ("spEntityId" ));
236
+ assertEquals ("https://projectId.firebaseapp.com/__/auth/handler" , spConfig .get ("callbackUri" ));
237
+ }
238
+
239
+ @ Test
240
+ public void testUpdateRequestX509Certificates () throws IOException {
241
+ SamlProviderConfig .UpdateRequest updateRequest =
242
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" );
243
+ updateRequest
244
+ .addX509Certificate ("certificate1" )
245
+ .addAllX509Certificates (ImmutableList .of ("certificate2" , "certificate3" ))
246
+ .addX509Certificate ("certificate4" );
247
+
248
+ Map <String ,Object > properties = updateRequest .getProperties ();
249
+ assertEquals (1 , properties .size ());
250
+ Map <String , Object > idpConfig = (Map <String , Object >) properties .get ("idpConfig" );
251
+ assertNotNull (idpConfig );
252
+ assertEquals (1 , idpConfig .size ());
253
+
254
+ List <Object > idpCertificates = (List <Object >) idpConfig .get ("idpCertificates" );
255
+ assertNotNull (idpCertificates );
256
+ assertEquals (4 , idpCertificates .size ());
257
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate1" ), idpCertificates .get (0 ));
258
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate2" ), idpCertificates .get (1 ));
259
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate3" ), idpCertificates .get (2 ));
260
+ assertEquals (ImmutableMap .of ("x509Certificate" , "certificate4" ), idpCertificates .get (3 ));
261
+ }
262
+
263
+ @ Test (expected = IllegalArgumentException .class )
264
+ public void testUpdateRequestMissingProviderId () {
265
+ new SamlProviderConfig .UpdateRequest (null );
266
+ }
267
+
268
+ @ Test (expected = IllegalArgumentException .class )
269
+ public void testUpdateRequestInvalidProviderId () {
270
+ new SamlProviderConfig .UpdateRequest ("oidc.invalid-saml-provider-id" );
271
+ }
272
+
273
+ @ Test (expected = IllegalArgumentException .class )
274
+ public void testUpdateRequestMissingDisplayName () {
275
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setDisplayName (null );
276
+ }
277
+
278
+ @ Test (expected = IllegalArgumentException .class )
279
+ public void testUpdateRequestMissingIdpEntityId () {
280
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setIdpEntityId (null );
281
+ }
282
+
283
+ @ Test (expected = IllegalArgumentException .class )
284
+ public void testUpdateRequestMissingSsoUrl () {
285
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setSsoUrl (null );
286
+ }
287
+
288
+ @ Test (expected = IllegalArgumentException .class )
289
+ public void testUpdateRequestInvalidSsoUrl () {
290
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setSsoUrl ("not a valid url" );
291
+ }
292
+
293
+ @ Test (expected = IllegalArgumentException .class )
294
+ public void testUpdateRequestMissingX509Certificate () {
295
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).addX509Certificate (null );
296
+ }
297
+
298
+ @ Test (expected = IllegalArgumentException .class )
299
+ public void testUpdateRequestNullX509CertificatesCollection () {
300
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).addAllX509Certificates (null );
301
+ }
302
+
303
+ @ Test (expected = IllegalArgumentException .class )
304
+ public void testUpdateRequestEmptyX509CertificatesCollection () {
305
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" )
306
+ .addAllX509Certificates (ImmutableList .<String >of ());
307
+ }
308
+
309
+ @ Test (expected = IllegalArgumentException .class )
310
+ public void testUpdateRequestMissingRpEntityId () {
311
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setRpEntityId (null );
312
+ }
313
+
314
+ @ Test (expected = IllegalArgumentException .class )
315
+ public void testUpdateRequestMissingCallbackUrl () {
316
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setCallbackUrl (null );
317
+ }
318
+
319
+ @ Test (expected = IllegalArgumentException .class )
320
+ public void testUpdateRequestInvalidCallbackUrl () {
321
+ new SamlProviderConfig .UpdateRequest ("saml.provider-id" ).setCallbackUrl ("not a valid url" );
322
+ }
158
323
}
0 commit comments