Skip to content

Commit

Permalink
Merge "[FAB-3307] Adding Identity Validation"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Apr 28, 2017
2 parents 84a1616 + 185d06e commit 139f67f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion msp/mspimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func (msp *bccspmsp) SatisfiesPrincipal(id Identity, principal *m.MSPPrincipal)
}

if bytes.Equal(id.(*identity).cert.Raw, principalId.(*identity).cert.Raw) {
return nil
return principalId.Validate()
}

return errors.New("The identities do not match")
Expand Down
26 changes: 25 additions & 1 deletion msp/revocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package msp
import (
"testing"

"github.com/hyperledger/fabric/protos/msp"
"github.com/stretchr/testify/assert"
)

func TestRevocation(t *testing.T) {
func getRevocationMSP(t *testing.T) MSP {
// testdata/revocation
// 1) a key and a signcert (used to populate the default signing identity);
// 2) cacert is the CA that signed the intermediate;
Expand All @@ -36,10 +37,33 @@ func TestRevocation(t *testing.T) {
err = thisMSP.Setup(conf)
assert.NoError(t, err)

return thisMSP
}

func TestRevocation(t *testing.T) {
thisMSP := getRevocationMSP(t)

id, err := thisMSP.GetDefaultSigningIdentity()
assert.NoError(t, err)

// the certificate associated to this id is revoked and so validation should fail!
err = id.Validate()
assert.Error(t, err)
}

func TestIdentityPolicyPrincipalAgainstRevokedIdentity(t *testing.T) {
thisMSP := getRevocationMSP(t)

id, err := thisMSP.GetDefaultSigningIdentity()
assert.NoError(t, err)

idSerialized, err := id.Serialize()
assert.NoError(t, err)

principal := &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_IDENTITY,
Principal: idSerialized}

err = id.SatisfiesPrincipal(principal)
assert.Error(t, err)
}

0 comments on commit 139f67f

Please sign in to comment.