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");
}
}
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");
}
}
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()));
}
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);
}
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());
}
Aggregations