Skip to content

Commit

Permalink
[FAB-8453] policy support for MSPIDs with special chars
Browse files Browse the repository at this point in the history
This change set ensures that the policy parser can handle MSP IDs contain
the '.' and '-' characters, which wasn't possible before. Tests have been
added.

Change-Id: I33dc210e68ec6f6c5839f1edc9bd1fbfe3b2630c
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Feb 24, 2018
1 parent bf3ed58 commit f66e8fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/cauthdsl/policyparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/hyperledger/fabric/protos/utils"
)

var regex *regexp.Regexp = regexp.MustCompile("^([[:alnum:]]+)([.])(member|admin|client|peer|orderer)$")
var regex *regexp.Regexp = regexp.MustCompile("^([[:alnum:].-]+)([.])(member|admin|client|peer|orderer)$")
var regexErr *regexp.Regexp = regexp.MustCompile("^No parameter '([^']+)' found[.]$")

// a stub function - it returns the same string as it's passed.
Expand Down
27 changes: 27 additions & 0 deletions common/cauthdsl/policyparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,33 @@ func TestComplex2(t *testing.T) {
assert.Equal(t, p1, p2)
}

func TestMSPIDWIthSpecialChars(t *testing.T) {
p1, err := FromString("OR('MSP.member', 'MSP.WITH.DOTS.member', 'MSP-WITH-DASHES.member')")
assert.NoError(t, err)

principals := make([]*msp.MSPPrincipal, 0)

principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "MSP"})})

principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "MSP.WITH.DOTS"})})

principals = append(principals, &msp.MSPPrincipal{
PrincipalClassification: msp.MSPPrincipal_ROLE,
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "MSP-WITH-DASHES"})})

p2 := &common.SignaturePolicyEnvelope{
Version: 0,
Rule: NOutOf(1, []*common.SignaturePolicy{SignedBy(0), SignedBy(1), SignedBy(2)}),
Identities: principals,
}

assert.Equal(t, p1, p2)
}

func TestBadStringsNoPanic(t *testing.T) {
_, err := FromString("OR('A.member', 'Bmember')")
assert.Error(t, err)
Expand Down

0 comments on commit f66e8fd

Please sign in to comment.