Skip to content

Commit 4342cd6

Browse files
committed
[FAB-3312] Adding consolidation tests
This change-set does the following: 1. It checks that MSP does not validate MSP's CA and intermediate CA identinties. 2. It checks that MSP does validate MSP's admins. Change-Id: I54ea756c490a925df6beff3fac6715de51b46bb3 Signed-off-by: Angelo De Caro <[email protected]>
1 parent c5c60c3 commit 4342cd6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

msp/msp_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323

2424
"fmt"
2525

26+
"path/filepath"
27+
2628
"github.com/golang/protobuf/proto"
2729
"github.com/hyperledger/fabric/bccsp"
2830
"github.com/hyperledger/fabric/core/config"
@@ -118,6 +120,20 @@ func TestSerializeIdentities(t *testing.T) {
118120
}
119121
}
120122

123+
func TestValidateCAIdentity(t *testing.T) {
124+
caID := getIdentity(t, cacerts)
125+
126+
err := localMsp.Validate(caID)
127+
assert.Error(t, err)
128+
}
129+
130+
func TestValidateAdminIdentity(t *testing.T) {
131+
caID := getIdentity(t, admincerts)
132+
133+
err := localMsp.Validate(caID)
134+
assert.NoError(t, err)
135+
}
136+
121137
func TestSerializeIdentitiesWithWrongMSP(t *testing.T) {
122138
id, err := localMsp.GetDefaultSigningIdentity()
123139
if err != nil {
@@ -497,3 +513,16 @@ func TestMain(m *testing.M) {
497513
retVal := m.Run()
498514
os.Exit(retVal)
499515
}
516+
517+
func getIdentity(t *testing.T, path string) Identity {
518+
mspDir, err := config.GetDevMspDir()
519+
assert.NoError(t, err)
520+
521+
pems, err := getPemMaterialFromDir(filepath.Join(mspDir, path))
522+
assert.NoError(t, err)
523+
524+
id, _, err := localMsp.(*bccspmsp).getIdentityFromConf(pems[0])
525+
assert.NoError(t, err)
526+
527+
return id
528+
}

msp/mspwithintermediatecas_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,35 @@ func TestMSPWithIntermediateCAs(t *testing.T) {
134134
err = thisMSP.Validate(localMSPID.GetPublicVersion())
135135
assert.Error(t, err)
136136
}
137+
138+
func TestIntermediateCAIdentityValidity(t *testing.T) {
139+
keyinfo := &msp.KeyInfo{KeyIdentifier: "PEER", KeyMaterial: []byte(key)}
140+
141+
sigid := &msp.SigningIdentityInfo{PublicSigner: []byte(signcert), PrivateSigner: keyinfo}
142+
143+
cryptoConfig := &msp.FabricCryptoConfig{
144+
SignatureHashFamily: bccsp.SHA2,
145+
IdentityIdentifierHashFunction: bccsp.SHA256,
146+
}
147+
148+
fmspconf := &msp.FabricMSPConfig{
149+
RootCerts: [][]byte{[]byte(cacert)},
150+
IntermediateCerts: [][]byte{[]byte(intermediatecert)},
151+
SigningIdentity: sigid,
152+
Name: "DEFAULT",
153+
CryptoConfig: cryptoConfig}
154+
155+
fmpsjs, _ := proto.Marshal(fmspconf)
156+
157+
mspconf := &msp.MSPConfig{Config: fmpsjs, Type: int32(FABRIC)}
158+
159+
thisMSP, err := NewBccspMsp()
160+
assert.NoError(t, err)
161+
162+
err = thisMSP.Setup(mspconf)
163+
assert.NoError(t, err)
164+
165+
id, _, err := thisMSP.(*bccspmsp).getIdentityFromConf([]byte(intermediatecert))
166+
assert.NoError(t, err)
167+
assert.Error(t, id.Validate())
168+
}

0 commit comments

Comments
 (0)