Skip to content

Commit f66e8fd

Browse files
committedFeb 24, 2018
[FAB-8453] policy support for MSPIDs with special chars
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>
1 parent bf3ed58 commit f66e8fd

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
 

‎common/cauthdsl/policyparser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/hyperledger/fabric/protos/utils"
2929
)
3030

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

3434
// a stub function - it returns the same string as it's passed.

‎common/cauthdsl/policyparser_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,33 @@ func TestComplex2(t *testing.T) {
200200
assert.Equal(t, p1, p2)
201201
}
202202

203+
func TestMSPIDWIthSpecialChars(t *testing.T) {
204+
p1, err := FromString("OR('MSP.member', 'MSP.WITH.DOTS.member', 'MSP-WITH-DASHES.member')")
205+
assert.NoError(t, err)
206+
207+
principals := make([]*msp.MSPPrincipal, 0)
208+
209+
principals = append(principals, &msp.MSPPrincipal{
210+
PrincipalClassification: msp.MSPPrincipal_ROLE,
211+
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "MSP"})})
212+
213+
principals = append(principals, &msp.MSPPrincipal{
214+
PrincipalClassification: msp.MSPPrincipal_ROLE,
215+
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "MSP.WITH.DOTS"})})
216+
217+
principals = append(principals, &msp.MSPPrincipal{
218+
PrincipalClassification: msp.MSPPrincipal_ROLE,
219+
Principal: utils.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_MEMBER, MspIdentifier: "MSP-WITH-DASHES"})})
220+
221+
p2 := &common.SignaturePolicyEnvelope{
222+
Version: 0,
223+
Rule: NOutOf(1, []*common.SignaturePolicy{SignedBy(0), SignedBy(1), SignedBy(2)}),
224+
Identities: principals,
225+
}
226+
227+
assert.Equal(t, p1, p2)
228+
}
229+
203230
func TestBadStringsNoPanic(t *testing.T) {
204231
_, err := FromString("OR('A.member', 'Bmember')")
205232
assert.Error(t, err)

0 commit comments

Comments
 (0)
Please sign in to comment.