Skip to content

Commit 179e1e3

Browse files
committed
[FAB-16357] Support for .orderer
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
1 parent 7d1256f commit 179e1e3

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

common/cauthdsl/policyparser.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ const (
2828

2929
// Role values for principals
3030
const (
31-
RoleAdmin = "admin"
32-
RoleMember = "member"
33-
RoleClient = "client"
34-
RolePeer = "peer"
35-
// RoleOrderer = "orderer" TODO
31+
RoleAdmin = "admin"
32+
RoleMember = "member"
33+
RoleClient = "client"
34+
RolePeer = "peer"
35+
RoleOrderer = "orderer"
3636
)
3737

3838
var (
3939
regex = regexp.MustCompile(
40-
fmt.Sprintf("^([[:alnum:].-]+)([.])(%s|%s|%s|%s)$",
41-
RoleAdmin, RoleMember, RoleClient, RolePeer),
40+
fmt.Sprintf("^([[:alnum:].-]+)([.])(%s|%s|%s|%s|%s)$",
41+
RoleAdmin, RoleMember, RoleClient, RolePeer, RoleOrderer),
4242
)
4343
regexErr = regexp.MustCompile("^No parameter '([^']+)' found[.]$")
4444
)
@@ -170,6 +170,8 @@ func secondPass(args ...interface{}) (interface{}, error) {
170170
r = msp.MSPRole_CLIENT
171171
case RolePeer:
172172
r = msp.MSPRole_PEER
173+
case RoleOrderer:
174+
r = msp.MSPRole_ORDERER
173175
default:
174176
return nil, fmt.Errorf("Error parsing role %s", t)
175177
}

common/cauthdsl/policyparser_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,37 @@ func TestBadStringsNoPanic(t *testing.T) {
228228
assert.EqualError(t, err, "unrecognized token 'Bmember' in policy string")
229229
}
230230

231+
func TestNodeOUs(t *testing.T) {
232+
p1, err := FromString("OR('A.peer', 'B.admin', 'C.orderer', 'D.client')")
233+
assert.NoError(t, err)
234+
235+
principals := make([]*msp.MSPPrincipal, 0)
236+
237+
principals = append(principals, &msp.MSPPrincipal{
238+
PrincipalClassification: msp.MSPPrincipal_ROLE,
239+
Principal: protoutil.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_PEER, MspIdentifier: "A"})})
240+
241+
principals = append(principals, &msp.MSPPrincipal{
242+
PrincipalClassification: msp.MSPPrincipal_ROLE,
243+
Principal: protoutil.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_ADMIN, MspIdentifier: "B"})})
244+
245+
principals = append(principals, &msp.MSPPrincipal{
246+
PrincipalClassification: msp.MSPPrincipal_ROLE,
247+
Principal: protoutil.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_ORDERER, MspIdentifier: "C"})})
248+
249+
principals = append(principals, &msp.MSPPrincipal{
250+
PrincipalClassification: msp.MSPPrincipal_ROLE,
251+
Principal: protoutil.MarshalOrPanic(&msp.MSPRole{Role: msp.MSPRole_CLIENT, MspIdentifier: "D"})})
252+
253+
p2 := &common.SignaturePolicyEnvelope{
254+
Version: 0,
255+
Rule: NOutOf(1, []*common.SignaturePolicy{SignedBy(0), SignedBy(1), SignedBy(2), SignedBy(3)}),
256+
Identities: principals,
257+
}
258+
259+
assert.Equal(t, p1, p2)
260+
}
261+
231262
func TestOutOfNumIsString(t *testing.T) {
232263
p1, err := FromString("OutOf('1', 'A.member', 'B.member')")
233264
assert.NoError(t, err)

0 commit comments

Comments
 (0)