Skip to content

Commit

Permalink
[FAB-16357] Support for .orderer
Browse files Browse the repository at this point in the history
This change-set adds support to .orderer MSP
principal in the policy parser

Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
Change-Id: I5bcf972de684bcc1efcfd117b2a6a25b7e44fb6d
  • Loading branch information
adecaro committed Aug 21, 2019
1 parent 9b2fde0 commit 6f64c22
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
16 changes: 9 additions & 7 deletions common/cauthdsl/policyparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ const (

// Role values for principals
const (
RoleAdmin = "admin"
RoleMember = "member"
RoleClient = "client"
RolePeer = "peer"
// RoleOrderer = "orderer" TODO
RoleAdmin = "admin"
RoleMember = "member"
RoleClient = "client"
RolePeer = "peer"
RoleOrderer = "orderer"
)

var (
regex = regexp.MustCompile(
fmt.Sprintf("^([[:alnum:].-]+)([.])(%s|%s|%s|%s)$",
RoleAdmin, RoleMember, RoleClient, RolePeer),
fmt.Sprintf("^([[:alnum:].-]+)([.])(%s|%s|%s|%s|%s)$",
RoleAdmin, RoleMember, RoleClient, RolePeer, RoleOrderer),
)
regexErr = regexp.MustCompile("^No parameter '([^']+)' found[.]$")
)
Expand Down Expand Up @@ -180,6 +180,8 @@ func secondPass(args ...interface{}) (interface{}, error) {
r = msp.MSPRole_CLIENT
case RolePeer:
r = msp.MSPRole_PEER
case RoleOrderer:
r = msp.MSPRole_ORDERER
default:
return nil, fmt.Errorf("Error parsing role %s", t)
}
Expand Down
31 changes: 31 additions & 0 deletions common/cauthdsl/policyparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,37 @@ func TestBadStringsNoPanic(t *testing.T) {
assert.EqualError(t, err, "unrecognized token 'Bmember' in policy string")
}

func TestNodeOUs(t *testing.T) {
p1, err := FromString("OR('A.peer', 'B.admin', 'C.orderer', 'D.client')")
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_PEER, MspIdentifier: "A"})})

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

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

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

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

assert.Equal(t, p1, p2)
}

func TestOutOfNumIsString(t *testing.T) {
p1, err := FromString("OutOf('1', 'A.member', 'B.member')")
assert.NoError(t, err)
Expand Down

0 comments on commit 6f64c22

Please sign in to comment.