@@ -1983,4 +1983,113 @@ func Demo(suite *utils.TestSuite) {
1983
1983
suite .AssertNotFound (err )
1984
1984
_ , err = GetX509Cert (suite , testconstants .LeafCertWithSameSubjectAndSKIDSubject , testconstants .LeafCertWithSameSubjectAndSKIDSubjectKeyID )
1985
1985
suite .AssertNotFound (err )
1986
+
1987
+ // Add VID scoped X509 certificate
1988
+
1989
+ // Check that if root cert is VID scoped and RootVID==CertVID==AccountVID then adding x509 should succeed
1990
+ // Add root certificate
1991
+ msgProposeAddX509RootCert = pkitypes.MsgProposeAddX509RootCert {
1992
+ Cert : testconstants .RootCertWithVid ,
1993
+ Vid : testconstants .RootCertWithVidVid ,
1994
+ Signer : aliceAccount .Address ,
1995
+ }
1996
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgProposeAddX509RootCert }, aliceName , aliceAccount )
1997
+ require .NoError (suite .T , err )
1998
+
1999
+ msgApproveAddX509RootCert = pkitypes.MsgApproveAddX509RootCert {
2000
+ Subject : testconstants .RootCertWithVidSubject ,
2001
+ SubjectKeyId : testconstants .RootCertWithVidSubjectKeyID ,
2002
+ Signer : jackAccount .Address ,
2003
+ }
2004
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgApproveAddX509RootCert }, jackName , jackAccount )
2005
+ require .NoError (suite .T , err )
2006
+
2007
+ // Register new Vendor account
2008
+ vendorName = utils .RandString ()
2009
+ vendorAccount = test_dclauth .CreateVendorAccount (
2010
+ suite ,
2011
+ vendorName ,
2012
+ dclauthtypes.AccountRoles {dclauthtypes .Vendor },
2013
+ testconstants .RootCertWithVidVid ,
2014
+ testconstants .ProductIDsEmpty ,
2015
+ aliceName ,
2016
+ aliceAccount ,
2017
+ jackName ,
2018
+ jackAccount ,
2019
+ testconstants .Info ,
2020
+ )
2021
+ require .NotNil (suite .T , vendorAccount )
2022
+
2023
+ // Add an intermediate certificate
2024
+ msgAddX509Cert = pkitypes.MsgAddX509Cert {
2025
+ Cert : testconstants .IntermediateCertWithVid1 ,
2026
+ Signer : aliceAccount .Address ,
2027
+ }
2028
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgAddX509Cert }, vendorName , vendorAccount )
2029
+ require .NoError (suite .T , err )
2030
+
2031
+ // Check approved certificates
2032
+ certs , _ = GetX509Cert (suite , testconstants .RootCertWithVidSubject , testconstants .RootCertWithVidSubjectKeyID )
2033
+ require .Equal (suite .T , 1 , len (certs .Certs ))
2034
+ certs , _ = GetX509Cert (suite , testconstants .IntermediateCertWithVidSubject , testconstants .IntermediateCertWithVidSubjectKeyID )
2035
+ require .Equal (suite .T , 1 , len (certs .Certs ))
2036
+
2037
+ // Check that if root cert is VID scoped and rootVID != CertVID then adding an intermediate cert should fail
2038
+ // Add an intermediate certificate
2039
+ msgAddX509Cert = pkitypes.MsgAddX509Cert {
2040
+ Cert : testconstants .IntermediateCertWithVid2 ,
2041
+ Signer : aliceAccount .Address ,
2042
+ }
2043
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgAddX509Cert }, vendorName , vendorAccount )
2044
+ require .Error (suite .T , err )
2045
+
2046
+ // Check there is only one approved intermediate certificate
2047
+ certs , _ = GetX509Cert (suite , testconstants .IntermediateCertWithVidSubject , testconstants .IntermediateCertWithVidSubjectKeyID )
2048
+ require .Equal (suite .T , 1 , len (certs .Certs ))
2049
+ require .Equal (suite .T , testconstants .IntermediateCertWithVid1SerialNumber , certs .Certs [0 ].SerialNumber )
2050
+
2051
+ // Check that if root cert is non-VID scoped and CertVID != AccountVID then adding an intermediate cert should fail
2052
+ // Ensure that there is a non-VID root cert exists
2053
+ certs , _ = GetX509Cert (suite , testconstants .PAACertNoVidSubject , testconstants .PAACertNoVidSubjectKeyID )
2054
+ require .Equal (suite .T , 1 , len (certs .Certs ))
2055
+
2056
+ // Add an intermediate certificate
2057
+ msgAddX509Cert = pkitypes.MsgAddX509Cert {
2058
+ Cert : testconstants .PAICertWithNumericVid ,
2059
+ Signer : aliceAccount .Address ,
2060
+ }
2061
+ // Try to submit txn with another Vendor
2062
+ newVendorName := utils .RandString ()
2063
+ newVendorAccount := test_dclauth .CreateVendorAccount (
2064
+ suite ,
2065
+ vendorName ,
2066
+ dclauthtypes.AccountRoles {dclauthtypes .Vendor },
2067
+ testconstants .IntermediateCertWithVid2Vid ,
2068
+ testconstants .ProductIDsEmpty ,
2069
+ aliceName ,
2070
+ aliceAccount ,
2071
+ jackName ,
2072
+ jackAccount ,
2073
+ testconstants .Info ,
2074
+ )
2075
+ require .NotNil (suite .T , vendorAccount )
2076
+
2077
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgAddX509Cert }, newVendorName , newVendorAccount )
2078
+ require .Error (suite .T , err )
2079
+
2080
+ // Check there is no an intermediate certificate
2081
+ certs , _ = GetX509Cert (suite , testconstants .PAICertWithNumericVidSubject , testconstants .PAICertWithNumericVidSubjectKeyID )
2082
+ require .Equal (suite .T , 0 , len (certs .Certs ))
2083
+
2084
+ // Check that if root cert is non-VID scoped and CertVID==AccountVID then adding x509 should succeed
2085
+ // Add an intermediate certificate
2086
+ msgAddX509Cert = pkitypes.MsgAddX509Cert {
2087
+ Cert : testconstants .PAICertWithNumericVid ,
2088
+ Signer : aliceAccount .Address ,
2089
+ }
2090
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgAddX509Cert }, vendorName , vendorAccount )
2091
+ require .NoError (suite .T , err )
2092
+ // Check there is only one approved intermediate certificate
2093
+ certs , _ = GetX509Cert (suite , testconstants .PAICertWithNumericVidSubject , testconstants .PAICertWithNumericVidSubjectKeyID )
2094
+ require .Equal (suite .T , 1 , len (certs .Certs ))
1986
2095
}
0 commit comments