@@ -231,6 +231,7 @@ public static class CertificateApiTest {
231231 private static final String SPIFFE_TRUST_BUNDLE_WRONG_ROOT = "spiffebundle_wrong_root.json" ;
232232 private static final String SPIFFE_TRUST_BUNDLE_WRONG_SEQ = "spiffebundle_wrong_seq_type.json" ;
233233 private static final String SPIFFE_TRUST_BUNDLE_MISSING_X5C = "spiffebundle_missing_x5c.json" ;
234+ private static final String SPIFFE_TRUST_BUNDLE_IGNORED_KEYS = "spiffebundle_ignored_keys.json" ;
234235 private static final String DOMAIN_ERROR_MESSAGE =
235236 " Certificate loading for trust domain 'google.com' failed." ;
236237
@@ -330,6 +331,42 @@ public void loadTrustBundleFromFileSuccessTest() throws Exception {
330331 assertEquals ("foo.bar.com" , spiffeId_ec .get ().getTrustDomain ());
331332 }
332333
334+ @ Test
335+ public void loadTrustBundleFromFileWithMultiCertsSuccessTest () throws Exception {
336+ SpiffeBundle tb = SpiffeUtil .loadTrustBundleFromFile (
337+ copyFileToTmp (SPIFFE_TRUST_BUNDLE_WRONG_MULTI_CERTS ));
338+ assertEquals (1 , tb .getSequenceNumbers ().size ());
339+ assertEquals (123L , (long ) tb .getSequenceNumbers ().get ("google.com" ));
340+ assertEquals (1 , tb .getBundleMap ().size ());
341+ assertEquals (1 , tb .getBundleMap ().get ("google.com" ).size ());
342+ Optional <SpiffeId > spiffeId = SpiffeUtil .extractSpiffeId (
343+ tb .getBundleMap ().get ("google.com" ).toArray (new X509Certificate [0 ]));
344+ assertTrue (spiffeId .isPresent ());
345+ assertEquals ("foo.bar.com" , spiffeId .get ().getTrustDomain ());
346+ }
347+
348+ @ Test
349+ public void loadTrustBundleFromFileWithMissingX5cSuccessTest () throws Exception {
350+ SpiffeBundle tb = SpiffeUtil .loadTrustBundleFromFile (
351+ copyFileToTmp (SPIFFE_TRUST_BUNDLE_MISSING_X5C ));
352+ assertEquals (1 , tb .getBundleMap ().size ());
353+ assertEquals (1 , tb .getBundleMap ().get ("google.com" ).size ());
354+ }
355+
356+ @ Test
357+ public void loadTrustBundleFromFileWithIgnoredKeysSuccessTest () throws Exception {
358+ SpiffeBundle tb = SpiffeUtil .loadTrustBundleFromFile (
359+ copyFileToTmp (SPIFFE_TRUST_BUNDLE_IGNORED_KEYS ));
360+ assertEquals (1 , tb .getSequenceNumbers ().size ());
361+ assertEquals (123L , (long ) tb .getSequenceNumbers ().get ("google.com" ));
362+ assertEquals (1 , tb .getBundleMap ().size ());
363+ assertEquals (1 , tb .getBundleMap ().get ("google.com" ).size ());
364+ Optional <SpiffeId > spiffeId = SpiffeUtil .extractSpiffeId (
365+ tb .getBundleMap ().get ("google.com" ).toArray (new X509Certificate [0 ]));
366+ assertTrue (spiffeId .isPresent ());
367+ assertEquals ("foo.bar.com" , spiffeId .get ().getTrustDomain ());
368+ }
369+
333370 @ Test
334371 public void loadTrustBundleFromFileFailureTest () {
335372 // Check the exception if JSON root element is different from 'trust_domains'
@@ -352,10 +389,6 @@ public void loadTrustBundleFromFileFailureTest() {
352389 iae = assertThrows (IllegalArgumentException .class , () -> SpiffeUtil
353390 .loadTrustBundleFromFile (copyFileToTmp (SPIFFE_TRUST_BUNDLE_CORRUPTED_CERT )));
354391 assertEquals ("Certificate can't be parsed." + DOMAIN_ERROR_MESSAGE , iae .getMessage ());
355- // Check the exception if a key entry is missing the 'x5c' parameter
356- iae = assertThrows (IllegalArgumentException .class , () -> SpiffeUtil
357- .loadTrustBundleFromFile (copyFileToTmp (SPIFFE_TRUST_BUNDLE_MISSING_X5C )));
358- assertEquals ("'x5c' parameter is required." + DOMAIN_ERROR_MESSAGE , iae .getMessage ());
359392 // Check the exception if 'kty' value differs from 'RSA'
360393 iae = assertThrows (IllegalArgumentException .class , () -> SpiffeUtil
361394 .loadTrustBundleFromFile (copyFileToTmp (SPIFFE_TRUST_BUNDLE_WRONG_KTY )));
@@ -371,11 +404,6 @@ public void loadTrustBundleFromFileFailureTest() {
371404 .loadTrustBundleFromFile (copyFileToTmp (SPIFFE_TRUST_BUNDLE_WRONG_USE )));
372405 assertEquals ("'use' parameter must be 'x509-svid' but 'i_am_not_x509-svid' found."
373406 + DOMAIN_ERROR_MESSAGE , iae .getMessage ());
374- // Check the exception if multiple certs are provided for 'x5c'
375- iae = assertThrows (IllegalArgumentException .class , () -> SpiffeUtil
376- .loadTrustBundleFromFile (copyFileToTmp (SPIFFE_TRUST_BUNDLE_WRONG_MULTI_CERTS )));
377- assertEquals ("Exactly 1 certificate is expected, but 2 found." + DOMAIN_ERROR_MESSAGE ,
378- iae .getMessage ());
379407 }
380408
381409 @ Test
0 commit comments