Search in sources :

Example 1 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation 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 2 with HFCAAffiliation

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

the class HFCAClientIT method testDeleteAffiliationNotAllowed.

// Tests deleting an affiliation on CA that does not allow affiliation removal
@Test
public void testDeleteAffiliationNotAllowed() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    thrown.expectMessage("Authorization failure");
    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(admin2.getName(), TEST_ADMIN_PW));
    }
    HFCAAffiliation aff = client2.newHFCAAffiliation("org6");
    HFCAAffiliationResp resp = aff.delete(admin2);
    assertEquals("Incorrect status code", new Integer(400), new Integer(resp.getStatusCode()));
}
Also used : HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) 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 3 with HFCAAffiliation

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

the class HFCAClientIT method testCreateAffiliation.

// Tests adding an affiliation
@Test
public void testCreateAffiliation() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAAffiliation aff = client.newHFCAAffiliation("org3");
    HFCAAffiliationResp resp = aff.create(admin);
    assertEquals("Incorrect status code", new Integer(201), new Integer(resp.getStatusCode()));
    assertEquals("Incorrect response for id", "org3", aff.getName());
    Collection<HFCAAffiliation> children = aff.getChildren();
    assertEquals("Should have no children", 0, children.size());
}
Also used : HFCAAffiliationResp(org.hyperledger.fabric_ca.sdk.HFCAAffiliation.HFCAAffiliationResp) HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Example 4 with HFCAAffiliation

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

the class HFCAClientIT method testGetAffiliation.

// Tests getting an affiliation
@Test
public void testGetAffiliation() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    HFCAAffiliation aff = client.newHFCAAffiliation("org2");
    int resp = aff.read(admin);
    assertEquals("Incorrect response for affiliation name", "org2", aff.getName());
    assertEquals("Incorrect response for child affiliation name", "org2.department1", aff.getChild("department1").getName());
    assertEquals("Incorrect status code", new Integer(200), new Integer(resp));
}
Also used : HFCAAffiliation(org.hyperledger.fabric_ca.sdk.HFCAAffiliation) Test(org.junit.Test)

Example 5 with HFCAAffiliation

use of org.hyperledger.fabric_ca.sdk.HFCAAffiliation 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)

Aggregations

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