Skip to content

Commit 653b724

Browse files
authored
Fix the handling of the key endorsement policy (#377)
The nOutOf was missing. Signed-off-by: Matthew B White <[email protected]> Signed-off-by: Matthew B White <[email protected]>
1 parent 982edda commit 653b724

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

libraries/fabric-shim/lib/utils/statebased.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,15 @@ class KeyEndorsementPolicy {
132132
sigsPolicies.push(signedBy);
133133
});
134134

135-
const policy = new common.SignaturePolicy();
135+
136+
// Need to say that we want all of the mspIDs from the list.
136137
const nOutOf = new common.SignaturePolicy.NOutOf();
137138
nOutOf.setN(mspIds.length);
138139
nOutOf.setRulesList(sigsPolicies);
139140

141+
const policy = new common.SignaturePolicy();
142+
policy.setNOutOf(nOutOf);
143+
140144
spe.setIdentitiesList(principals);
141145
spe.setRule(policy);
142146

libraries/fabric-shim/test/unit/utils/statebased.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
8-
// const rewire = require('rewire');
9-
7+
const { msp, common } = require('@hyperledger/fabric-protos');
8+
const { SignedProposal } = require('@hyperledger/fabric-protos/lib/peer');
109
const chai = require('chai');
1110
const expect = chai.expect;
1211
const KeyEndorsementPolicy = require('../../../lib/utils/statebased');
@@ -106,9 +105,34 @@ describe('KeyEndorsementPolicy', () => {
106105
it('should successfully get policy', () => {
107106
const policy = ep.getPolicy();
108107
const anotherEp = new KeyEndorsementPolicy(policy);
109-
expect(anotherEp.orgs).to.haveOwnProperty('Org1MSP');
110-
expect(anotherEp.orgs).to.haveOwnProperty('Org2MSP');
111-
expect(anotherEp.orgs).to.haveOwnProperty('Org3MSP');
108+
109+
const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy);
110+
const speClone = common.SignaturePolicyEnvelope.deserializeBinary(anotherEp.getPolicy());
111+
expect(spe.toObject()).to.deep.equals(speClone.toObject());
112+
});
113+
114+
115+
it('should get policy that is semantically valid', () => {
116+
const policy = ep.getPolicy();
117+
const spe = common.SignaturePolicyEnvelope.deserializeBinary(policy);
118+
119+
// create a blank object and expand all the protobufs into it
120+
const speObject = spe.toObject();
121+
122+
speObject.identitiesList = spe.getIdentitiesList().map(principal => {
123+
let mapped = { principalClassification: 0 };
124+
mapped.principal = msp.MSPRole.deserializeBinary(principal.getPrincipal_asU8()).toObject();
125+
return mapped;
126+
});
127+
128+
speObject.rule.nOutOf.rulesList = spe.getRule().getNOutOf().getRulesList().map(sigRule =>{
129+
return {signedBy: sigRule.getSignedBy()}
130+
});
131+
132+
const expectedPolicy={"version":0,"rule":{"signedBy":0,"nOutOf":{"n":3,"rulesList":[{"signedBy":0},{"signedBy":1},{"signedBy":2}]}},"identitiesList":[{"principalClassification":0,"principal":{"mspIdentifier":"Org1MSP","role":0}},{"principalClassification":0,"principal":{"mspIdentifier":"Org2MSP","role":0}},{"principalClassification":0,"principal":{"mspIdentifier":"Org3MSP","role":0}}]}
133+
expect(speObject).to.deep.equals(expectedPolicy);
112134
});
113135
});
114136
});
137+
138+

0 commit comments

Comments
 (0)