@@ -787,6 +787,126 @@ func TestHandler_AddX509Cert(t *testing.T) {
787
787
}
788
788
}
789
789
790
+ func TestHandler_AddX509Cert_RootVID_Equal_To_CertVID_And_AccountVID (t * testing.T ) {
791
+ setup := Setup (t )
792
+
793
+ // store root certificate
794
+ rootCertOptions := createPAACertWithNumericVidOptions ()
795
+ proposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
796
+
797
+ accAddress := GenerateAccAddress ()
798
+ setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, testconstants .PAACertWithNumericVidVid )
799
+
800
+ // add x509 certificate
801
+ addX509Cert := types .NewMsgAddX509Cert (accAddress .String (), testconstants .PAICertWithNumericPidVid )
802
+ _ , err := setup .Handler (setup .Ctx , addX509Cert )
803
+ require .NoError (t , err )
804
+
805
+ // query certificate
806
+ certs , _ := queryAllApprovedCertificates (setup )
807
+ require .Equal (t , 2 , len (certs ))
808
+ intermediateCerts , _ := queryApprovedCertificates (setup , testconstants .PAICertWithNumericPidVidSubject , testconstants .PAICertWithNumericPidVidSubjectKeyID )
809
+ require .Equal (t , 1 , len (intermediateCerts .Certs ))
810
+ require .Equal (t , testconstants .PAICertWithNumericPidVidSubject , intermediateCerts .Certs [0 ].Subject )
811
+ require .Equal (t , testconstants .PAICertWithNumericPidVidSubjectKeyID , intermediateCerts .Certs [0 ].SubjectKeyId )
812
+ }
813
+
814
+ func TestHandler_AddX509Cert_Non_VID_Scoped_Root__ChildVID_Equal_To_AccountVID (t * testing.T ) {
815
+ setup := Setup (t )
816
+ // store root certificate
817
+ rootCertOptions := & rootCertOptions {
818
+ pemCert : testconstants .PAACertNoVid ,
819
+ info : testconstants .Info ,
820
+ subject : testconstants .PAACertNoVidSubject ,
821
+ subjectKeyID : testconstants .PAACertNoVidSubjectKeyID ,
822
+ }
823
+ proposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
824
+
825
+ accAddress := GenerateAccAddress ()
826
+ setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, 65522 )
827
+
828
+ // add x509 certificate
829
+ addX509Cert := types .NewMsgAddX509Cert (accAddress .String (), testconstants .PAICertWithNumericVid )
830
+ _ , err := setup .Handler (setup .Ctx , addX509Cert )
831
+ require .NoError (t , err )
832
+
833
+ // query certificate
834
+ certs , _ := queryAllApprovedCertificates (setup )
835
+ require .Equal (t , 2 , len (certs ))
836
+ intermediateCerts , _ := queryApprovedCertificates (setup , testconstants .PAICertWithNumericVidSubject , testconstants .PAICertWithNumericVidSubjectKeyID )
837
+ require .Equal (t , 1 , len (intermediateCerts .Certs ))
838
+ require .Equal (t , testconstants .PAICertWithNumericVidSubject , intermediateCerts .Certs [0 ].Subject )
839
+ require .Equal (t , testconstants .PAICertWithNumericVidSubjectKeyID , intermediateCerts .Certs [0 ].SubjectKeyId )
840
+ }
841
+
842
+ func TestHandler_AddX509Cert_Root_VID_Does_Not_Equal_To_ChildVID (t * testing.T ) {
843
+ setup := Setup (t )
844
+
845
+ // store root certificate
846
+ rootCertOptions := & rootCertOptions {
847
+ pemCert : testconstants .RootCertWithVid ,
848
+ info : testconstants .Info ,
849
+ subject : testconstants .RootCertWithVidSubject ,
850
+ subjectKeyID : testconstants .RootCertWithVidSubjectKeyID ,
851
+ vid : testconstants .RootCertWithVidVid ,
852
+ }
853
+ proposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
854
+
855
+ accAddress := GenerateAccAddress ()
856
+ setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, testconstants .RootCertWithVidVid )
857
+
858
+ // add x509 certificate
859
+ addX509Cert := types .NewMsgAddX509Cert (accAddress .String (), testconstants .IntermediateCertWithVid2 )
860
+ _ , err := setup .Handler (setup .Ctx , addX509Cert )
861
+ require .Error (t , err )
862
+ require .True (t , pkitypes .ErrCertVidNotEqualToRootVid .Is (err ))
863
+ }
864
+
865
+ func TestHandler_AddX509Cert_Root_VID_Does_Not_Equal_To_AccountVID (t * testing.T ) {
866
+ setup := Setup (t )
867
+
868
+ // store root certificate
869
+ rootCertOptions := & rootCertOptions {
870
+ pemCert : testconstants .RootCertWithVid ,
871
+ info : testconstants .Info ,
872
+ subject : testconstants .RootCertWithVidSubject ,
873
+ subjectKeyID : testconstants .RootCertWithVidSubjectKeyID ,
874
+ vid : testconstants .RootCertWithVidVid ,
875
+ }
876
+ proposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
877
+
878
+ accAddress := GenerateAccAddress ()
879
+ setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, 1111 )
880
+
881
+ // add x509 certificate
882
+ addX509Cert := types .NewMsgAddX509Cert (accAddress .String (), testconstants .IntermediateCertWithVid1 )
883
+ _ , err := setup .Handler (setup .Ctx , addX509Cert )
884
+ require .Error (t , err )
885
+ require .True (t , pkitypes .ErrCertVidNotEqualAccountVid .Is (err ))
886
+ }
887
+
888
+ func TestHandler_AddX509Cert_Non_Root_VID__Child_VID_Does_Not_Equal_To_AccountVID (t * testing.T ) {
889
+ setup := Setup (t )
890
+
891
+ // store root certificate
892
+ rootCertOptions := & rootCertOptions {
893
+ pemCert : testconstants .PAACertNoVid ,
894
+ info : testconstants .Info ,
895
+ subject : testconstants .PAACertNoVidSubject ,
896
+ subjectKeyID : testconstants .PAACertNoVidSubjectKeyID ,
897
+ }
898
+ proposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
899
+
900
+ accAddress := GenerateAccAddress ()
901
+ setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, 1111 )
902
+
903
+ // add x509 certificate
904
+ addX509Cert := types .NewMsgAddX509Cert (accAddress .String (), testconstants .PAICertWithNumericVid )
905
+ _ , err := setup .Handler (setup .Ctx , addX509Cert )
906
+ require .Error (t , err )
907
+ require .True (t , pkitypes .ErrCertVidNotEqualAccountVid .Is (err ))
908
+ }
909
+
790
910
func TestHandler_AddX509Cert_ForInvalidCertificate (t * testing.T ) {
791
911
setup := Setup (t )
792
912
0 commit comments