Search in sources :

Example 1 with MspPrincipal

use of org.hyperledger.fabric.protos.common.MspPrincipal in project fabric-sdk-java by hyperledger.

the class ChaincodeEndorsementPolicyTest method testSDKIntegrationYaml.

/**
 * Test method for {@link ChaincodeEndorsementPolicy#fromYamlFile(File)}
 * @throws IOException
 * @throws ChaincodeEndorsementPolicyParseException
 */
@Test
public void testSDKIntegrationYaml() throws IOException, ChaincodeEndorsementPolicyParseException {
    ChaincodeEndorsementPolicy itTestPolicy = new ChaincodeEndorsementPolicy();
    itTestPolicy.fromYamlFile(new File("src/test/fixture/sdkintegration/chaincodeendorsementpolicy.yaml"));
    SignaturePolicyEnvelope sigPolEnv = SignaturePolicyEnvelope.parseFrom(itTestPolicy.getChaincodeEndorsementPolicyAsBytes());
    List<MSPPrincipal> identitiesList = sigPolEnv.getIdentitiesList();
    for (MSPPrincipal ident : identitiesList) {
        MSPPrincipal mspPrincipal = MSPPrincipal.parseFrom(ident.getPrincipal());
        MSPPrincipal.Classification principalClassification = mspPrincipal.getPrincipalClassification();
        assertEquals(principalClassification.toString(), MSPPrincipal.Classification.ROLE.name());
        MspPrincipal.MSPRole mspRole = MspPrincipal.MSPRole.parseFrom(ident.getPrincipal());
        String iden = mspRole.getMspIdentifier();
        assertTrue("Org1MSP".equals(iden) || "Org2MSP".equals(iden));
        assertTrue(mspRole.getRole().getNumber() == MspPrincipal.MSPRole.MSPRoleType.ADMIN_VALUE || mspRole.getRole().getNumber() == MspPrincipal.MSPRole.MSPRoleType.MEMBER_VALUE);
    }
    Policies.SignaturePolicy rule = sigPolEnv.getRule();
    TypeCase typeCase = rule.getTypeCase();
    assertEquals(TypeCase.N_OUT_OF.getNumber(), typeCase.getNumber());
}
Also used : Policies(org.hyperledger.fabric.protos.common.Policies) SignaturePolicyEnvelope(org.hyperledger.fabric.protos.common.Policies.SignaturePolicyEnvelope) TypeCase(org.hyperledger.fabric.protos.common.Policies.SignaturePolicy.TypeCase) MspPrincipal(org.hyperledger.fabric.protos.common.MspPrincipal) MSPPrincipal(org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 MspPrincipal (org.hyperledger.fabric.protos.common.MspPrincipal)1 MSPPrincipal (org.hyperledger.fabric.protos.common.MspPrincipal.MSPPrincipal)1 Policies (org.hyperledger.fabric.protos.common.Policies)1 TypeCase (org.hyperledger.fabric.protos.common.Policies.SignaturePolicy.TypeCase)1 SignaturePolicyEnvelope (org.hyperledger.fabric.protos.common.Policies.SignaturePolicyEnvelope)1 Test (org.junit.Test)1