Search in sources :

Example 6 with HFCAIdentity

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

the class HFCAClientIT method testDeleteIdentity.

// Tests deleting an identity
@Test
public void testDeleteIdentity() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expect(IdentityException.class);
    thrown.expectMessage("Failed to get User");
    SampleUser user = new SampleUser("testuser4", TEST_ADMIN_ORG, sampleStore);
    HFCAIdentity ident = client.newHFCAIdentity(user.getName());
    ident.create(admin);
    ident.delete(admin);
    ident.read(admin);
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 7 with HFCAIdentity

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

the class HFCAClientIT method testForceDeleteAffiliationInvalid.

// Trying to delete affiliation with child affiliations and identities should result
// in an error without force option.
@Test
public void testForceDeleteAffiliationInvalid() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expectMessage("Authorization failure");
    HFCAAffiliation aff = client.newHFCAAffiliation("org1.dept3");
    aff.create(admin);
    HFCAAffiliation aff2 = client.newHFCAAffiliation("org1.dept3.team1");
    aff2.create(admin);
    HFCAIdentity ident = getIdentityReq("testorg1dept3", "client");
    ident.setAffiliation("org1.dept3");
    ident.create(admin);
    HFCAAffiliationResp resp = aff.delete(admin);
    assertEquals("Incorrect status code", new Integer(401), 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 8 with HFCAIdentity

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

the class HFCAClientIT method testDeleteIdentityNotAllowed.

// Tests deleting an identity on CA that does not allow identity removal
@Test
public void testDeleteIdentityNotAllowed() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expectMessage("Identity removal is disabled");
    SampleUser user = new SampleUser("testuser5", "org2", sampleStore);
    HFCAClient client2 = HFCAClient.createNewInstance(testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG2).getCAProperties());
    client2.setCryptoSuite(crypto);
    // SampleUser can be any implementation that implements org.hyperledger.fabric.sdk.User Interface
    SampleUser admin2 = sampleStore.getMember(TEST_ADMIN_NAME, "org2");
    if (!admin2.isEnrolled()) {
        // Preregistered admin only needs to be enrolled with Fabric CA.
        admin2.setEnrollment(client2.enroll(admin.getName(), TEST_ADMIN_PW));
    }
    HFCAIdentity ident = client2.newHFCAIdentity(user.getName());
    ident.create(admin2);
    ident.delete(admin2);
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) MockHFCAClient(org.hyperledger.fabric_ca.sdk.MockHFCAClient) HFCAClient(org.hyperledger.fabric_ca.sdk.HFCAClient) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 9 with HFCAIdentity

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

the class HFCAClientIT method getIdentityReq.

private HFCAIdentity getIdentityReq(String enrollmentID, String type) throws InvalidArgumentException {
    String password = "password";
    HFCAIdentity ident = client.newHFCAIdentity(enrollmentID);
    ident.setSecret(password);
    ident.setAffiliation(TEST_USER1_AFFILIATION);
    ident.setMaxEnrollments(1);
    ident.setType(type);
    Collection<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(new Attribute("testattr1", "valueattr1"));
    ident.setAttributes(attributes);
    return ident;
}
Also used : HFCAIdentity(org.hyperledger.fabric_ca.sdk.HFCAIdentity) Attribute(org.hyperledger.fabric_ca.sdk.Attribute) ArrayList(java.util.ArrayList) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString)

Example 10 with HFCAIdentity

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

the class HFCAClientIT method testGetIdentityNotExist.

// Tests getting an identity that does not exist
@Test
public void testGetIdentityNotExist() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    setField(client, "statusCode", 405);
    HFCAIdentity ident = client.newHFCAIdentity("fakeUser");
    int statusCode = ident.read(admin);
    if (statusCode != 404) {
        fail("Incorrect status code return for an identity that is not found, should have returned 404 and not thrown an excpetion");
    }
    setField(client, "statusCode", 400);
}
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