@@ -625,6 +625,69 @@ public void testValidateSpiffeServiceCertMismatch() throws IOException {
625
625
"1001" , validOrgs , null , errorMsg ));
626
626
}
627
627
628
+ @ Test
629
+ public void testValidateSpiffeServiceCertShortValid () throws IOException {
630
+
631
+ Path path = Paths .get ("src/test/resources/spiffe_short_service.csr" );
632
+ String csr = new String (Files .readAllBytes (path ));
633
+
634
+ X509ServiceCertRequest certReq = new X509ServiceCertRequest (csr );
635
+ assertNotNull (certReq );
636
+
637
+ Authorizer authorizer = Mockito .mock (Authorizer .class );
638
+ Principal provider = Mockito .mock (Principal .class );
639
+ Mockito .when (authorizer .access ("launch" , "sys.auth:dns.ostk.athenz.cloud" , provider , null ))
640
+ .thenReturn (true );
641
+
642
+ StringBuilder errorMsg = new StringBuilder (256 );
643
+ HashSet <String > validOrgs = new HashSet <>();
644
+ validOrgs .add ("Athenz" );
645
+ assertTrue (certReq .validate (provider , "athenz" , "production" ,
646
+ "1001" , validOrgs , null , errorMsg ));
647
+ }
648
+
649
+ @ Test
650
+ public void testValidateSpiffeServiceCertShortMismatchDomain () throws IOException {
651
+
652
+ Path path = Paths .get ("src/test/resources/spiffe_service_short_mismatch_domain.csr" );
653
+ String csr = new String (Files .readAllBytes (path ));
654
+
655
+ X509ServiceCertRequest certReq = new X509ServiceCertRequest (csr );
656
+ assertNotNull (certReq );
657
+
658
+ Authorizer authorizer = Mockito .mock (Authorizer .class );
659
+ Principal provider = Mockito .mock (Principal .class );
660
+ Mockito .when (authorizer .access ("launch" , "sys.auth:dns.ostk.athenz.cloud" , provider , null ))
661
+ .thenReturn (true );
662
+
663
+ StringBuilder errorMsg = new StringBuilder (256 );
664
+ HashSet <String > validOrgs = new HashSet <>();
665
+ validOrgs .add ("Athenz" );
666
+ assertFalse (certReq .validate (provider , "athenz" , "production" ,
667
+ "1001" , validOrgs , null , errorMsg ));
668
+ }
669
+
670
+ @ Test
671
+ public void testValidateSpiffeServiceCertShortMismatchService () throws IOException {
672
+
673
+ Path path = Paths .get ("src/test/resources/spiffe_service_short_mismatch_service.csr" );
674
+ String csr = new String (Files .readAllBytes (path ));
675
+
676
+ X509ServiceCertRequest certReq = new X509ServiceCertRequest (csr );
677
+ assertNotNull (certReq );
678
+
679
+ Authorizer authorizer = Mockito .mock (Authorizer .class );
680
+ Principal provider = Mockito .mock (Principal .class );
681
+ Mockito .when (authorizer .access ("launch" , "sys.auth:dns.ostk.athenz.cloud" , provider , null ))
682
+ .thenReturn (true );
683
+
684
+ StringBuilder errorMsg = new StringBuilder (256 );
685
+ HashSet <String > validOrgs = new HashSet <>();
686
+ validOrgs .add ("Athenz" );
687
+ assertFalse (certReq .validate (provider , "athenz" , "production" ,
688
+ "1001" , validOrgs , null , errorMsg ));
689
+ }
690
+
628
691
@ Test
629
692
public void testValidateSpiffeInvalidScheme () throws IOException {
630
693
0 commit comments