Search in sources :

Example 1 with HFCAIdentity

use of org.hyperledger.fabric_ca.sdk.HFCAIdentity in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testGetAllIdentity.

// Tests getting all identities for a caller
@Test
public void testGetAllIdentity() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAIdentity ident = getIdentityReq("testuser2", HFCAClient.HFCA_TYPE_CLIENT);
    ident.create(admin);
    Collection<HFCAIdentity> foundIdentities = client.getHFCAIdentities(admin);
    String[] expectedIdenities = new String[] { "testuser2", "admin" };
    Integer found = 0;
    for (HFCAIdentity id : foundIdentities) {
        for (String name : expectedIdenities) {
            if (id.getEnrollmentId().equals(name)) {
                found++;
            }
        }
    }
    if (found != 2) {
        fail("Failed to get the correct number of identities");
    }
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) Test(org.junit.Test)

Example 2 with HFCAIdentity

use of org.hyperledger.fabric_ca.sdk.HFCAIdentity in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testCreateAndGetIdentity.

// Tests getting an identity
@Test
public void testCreateAndGetIdentity() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAIdentity ident = getIdentityReq("testuser1", HFCAClient.HFCA_TYPE_PEER);
    ident.create(admin);
    HFCAIdentity identGet = client.newHFCAIdentity(ident.getEnrollmentId());
    identGet.read(admin);
    assertEquals("Incorrect response for id", ident.getEnrollmentId(), identGet.getEnrollmentId());
    assertEquals("Incorrect response for type", ident.getType(), identGet.getType());
    assertEquals("Incorrect response for affiliation", ident.getAffiliation(), identGet.getAffiliation());
    assertEquals("Incorrect response for max enrollments", ident.getMaxEnrollments(), identGet.getMaxEnrollments());
    Collection<Attribute> attrs = identGet.getAttributes();
    Boolean found = false;
    for (Attribute attr : attrs) {
        if (attr.getName().equals("testattr1")) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Incorrect response for attribute");
    }
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) Attribute(org.hyperledger.fabric_ca.sdk.Attribute) Test(org.junit.Test)

Example 3 with HFCAIdentity

use of org.hyperledger.fabric_ca.sdk.HFCAIdentity in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testUpdateAffiliationInvalid.

// Trying to update affiliations with child affiliations and identities
// should fail if not using 'force' option.
@Test
public void testUpdateAffiliationInvalid() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expectMessage("Need to use 'force' to remove identities and affiliation");
    HFCAAffiliation aff = client.newHFCAAffiliation("org1.dept1");
    aff.create(admin);
    HFCAAffiliation aff2 = aff.createDecendent("team1");
    aff2.create(admin);
    HFCAIdentity ident = getIdentityReq("testorg1dept1", "client");
    ident.setAffiliation(aff.getName());
    ident.create(admin);
    aff.setUpdateName("org1.dept2");
    HFCAAffiliationResp resp = aff.update(admin);
    assertEquals("Incorrect status code", new Integer(400), new Integer(resp.getStatusCode()));
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Example 4 with HFCAIdentity

use of org.hyperledger.fabric_ca.sdk.HFCAIdentity in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testDeleteIdentityFailUpdate.

// Tests deleting an identity and making sure it can't update after deletion
@Test
public void testDeleteIdentityFailUpdate() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expect(IdentityException.class);
    thrown.expectMessage("Identity has been deleted");
    HFCAIdentity ident = client.newHFCAIdentity("deletedUser");
    ident.create(admin);
    ident.delete(admin);
    ident.update(admin);
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) Test(org.junit.Test)

Example 5 with HFCAIdentity

use of org.hyperledger.fabric_ca.sdk.HFCAIdentity in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testModifyIdentity.

// Tests modifying an identity
@Test
public void testModifyIdentity() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAIdentity ident = getIdentityReq("testuser3", HFCAClient.HFCA_TYPE_ORDERER);
    ident.create(admin);
    assertEquals("Incorrect response for type", "orderer", ident.getType());
    assertNotEquals("Incorrect value for max enrollments", ident.getMaxEnrollments(), new Integer(5));
    ident.setMaxEnrollments(5);
    ident.update(admin);
    assertEquals("Incorrect value for max enrollments", ident.getMaxEnrollments(), new Integer(5));
    ident.setMaxEnrollments(100);
    ident.read(admin);
    assertEquals("Incorrect value for max enrollments", new Integer(5), ident.getMaxEnrollments());
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) Test(org.junit.Test)

Aggregations

HFCAIdentity (org.hyperledger.fabric_ca.sdk.HFCAIdentity)13 Test (org.junit.Test)12 HFCAAffiliation (org.hyperledger.fabric_ca.sdk.HFCAAffiliation)4 HFCAAffiliationResp (org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp)4 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 SampleUser (org.hyperledger.fabric.sdkintegration.SampleUser)2 Attribute (org.hyperledger.fabric_ca.sdk.Attribute)2 ArrayList (java.util.ArrayList)1 HFCAClient (org.hyperledger.fabric_ca.sdk.HFCAClient)1 MockHFCAClient (org.hyperledger.fabric_ca.sdk.MockHFCAClient)1