@@ -1983,4 +1983,130 @@ 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 : vendorAccount .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 : vendorAccount .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
+ // Try to submit txn with another Vendor
2057
+ newVendorName := utils .RandString ()
2058
+ newVendorAccount := test_dclauth .CreateVendorAccount (
2059
+ suite ,
2060
+ newVendorName ,
2061
+ dclauthtypes.AccountRoles {dclauthtypes .Vendor },
2062
+ 1234 ,
2063
+ testconstants .ProductIDsEmpty ,
2064
+ aliceName ,
2065
+ aliceAccount ,
2066
+ jackName ,
2067
+ jackAccount ,
2068
+ testconstants .Info ,
2069
+ )
2070
+ require .NotNil (suite .T , newVendorAccount )
2071
+
2072
+ // Add an intermediate certificate
2073
+ msgAddX509Cert = pkitypes.MsgAddX509Cert {
2074
+ Cert : testconstants .PAICertWithNumericVid ,
2075
+ Signer : newVendorAccount .Address ,
2076
+ }
2077
+
2078
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgAddX509Cert }, newVendorName , newVendorAccount )
2079
+ require .Error (suite .T , err )
2080
+
2081
+ // Check there is no an intermediate certificate
2082
+ certs , _ = GetX509Cert (suite , testconstants .PAICertWithNumericVidSubject , testconstants .PAICertWithNumericVidSubjectKeyID )
2083
+ require .Equal (suite .T , 0 , len (certs .Certs ))
2084
+
2085
+ // Check that if root cert is non-VID scoped and CertVID==AccountVID then adding x509 should succeed
2086
+ // Create vendor with valid VID
2087
+ newVendorName = utils .RandString ()
2088
+ newVendorAccount = test_dclauth .CreateVendorAccount (
2089
+ suite ,
2090
+ newVendorName ,
2091
+ dclauthtypes.AccountRoles {dclauthtypes .Vendor },
2092
+ testconstants .IntermediateCertWithVid2Vid ,
2093
+ testconstants .ProductIDsEmpty ,
2094
+ aliceName ,
2095
+ aliceAccount ,
2096
+ jackName ,
2097
+ jackAccount ,
2098
+ testconstants .Info ,
2099
+ )
2100
+ require .NotNil (suite .T , newVendorAccount )
2101
+
2102
+ // Add an intermediate certificate
2103
+ msgAddX509Cert = pkitypes.MsgAddX509Cert {
2104
+ Cert : testconstants .PAICertWithNumericVid ,
2105
+ Signer : newVendorAccount .Address ,
2106
+ }
2107
+ _ , err = suite .BuildAndBroadcastTx ([]sdk.Msg {& msgAddX509Cert }, newVendorName , newVendorAccount )
2108
+ require .NoError (suite .T , err )
2109
+ // Check there is only one approved intermediate certificate
2110
+ certs , _ = GetX509Cert (suite , testconstants .PAICertWithNumericVidSubject , testconstants .PAICertWithNumericVidSubjectKeyID )
2111
+ require .Equal (suite .T , 1 , len (certs .Certs ))
1986
2112
}
0 commit comments