Search in sources :

Example 6 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testMockReenrollNoResult.

@Test
public void testMockReenrollNoResult() throws Exception {
    thrown.expect(EnrollmentException.class);
    // thrown.expectMessage("failed");
    MockHFCAClient mockClient = MockHFCAClient.createNewInstance(testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG).getCALocation(), testConfig.getIntegrationTestsSampleOrg(TEST_WITH_INTEGRATION_ORG).getCAProperties());
    mockClient.setCryptoSuite(crypto);
    SampleUser user = getEnrolledUser(TEST_ADMIN_ORG);
    mockClient.setHttpPostResponse("{\"success\":true}");
    mockClient.reenroll(user);
}
Also used : MockHFCAClient(org.hyperledger.fabric_ca.sdk.MockHFCAClient) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 7 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testRegisterAttributes.

// Tests attributes
@Test
public void testRegisterAttributes() throws Exception {
    if (testConfig.isRunningAgainstFabric10()) {
        // needs v1.1
        return;
    }
    SampleUser user = new SampleUser("mrAttributes", TEST_ADMIN_ORG, sampleStore);
    RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
    String password = "mrAttributespassword";
    rr.setSecret(password);
    rr.addAttribute(new Attribute("testattr1", "mrAttributesValue1"));
    rr.addAttribute(new Attribute("testattr2", "mrAttributesValue2"));
    rr.addAttribute(new Attribute("testattrDEFAULTATTR", "mrAttributesValueDEFAULTATTR", true));
    user.setEnrollmentSecret(client.register(rr, admin));
    if (!user.getEnrollmentSecret().equals(password)) {
        fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
    }
    EnrollmentRequest req = new EnrollmentRequest();
    req.addAttrReq("testattr2").setOptional(false);
    user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret(), req));
    Enrollment enrollment = user.getEnrollment();
    String cert = enrollment.getCert();
    String certdec = getStringCert(cert);
    assertTrue(format("Missing testattr2 in certficate decoded: %s", certdec), certdec.contains("\"testattr2\":\"mrAttributesValue2\""));
    // Since request had specific attributes don't expect defaults.
    assertFalse(format("Contains testattrDEFAULTATTR in certificate decoded: %s", certdec), certdec.contains("\"testattrDEFAULTATTR\"") || certdec.contains("\"mrAttributesValueDEFAULTATTR\""));
    assertFalse(format("Contains testattr1 in certificate decoded: %s", certdec), certdec.contains("\"testattr1\"") || certdec.contains("\"mrAttributesValue1\""));
}
Also used : EnrollmentRequest(org.hyperledger.fabric_ca.sdk.EnrollmentRequest) Attribute(org.hyperledger.fabric_ca.sdk.Attribute) Enrollment(org.hyperledger.fabric.sdk.Enrollment) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) RegistrationRequest(org.hyperledger.fabric_ca.sdk.RegistrationRequest) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 8 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method testReenrollAndRevoke.

// Tests re-enrolling a user that has had an enrollment revoked
@Test
public void testReenrollAndRevoke() throws Exception {
    SampleUser user = getTestUser(TEST_ADMIN_ORG);
    if (!user.isRegistered()) {
        // users need to be registered AND enrolled
        RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
        String password = "testReenrollAndRevoke";
        rr.setSecret(password);
        user.setEnrollmentSecret(client.register(rr, admin));
        if (!user.getEnrollmentSecret().equals(password)) {
            fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
        }
    }
    if (!user.isEnrolled()) {
        user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret()));
    }
    sleepALittle();
    // get another enrollment
    EnrollmentRequest req = new EnrollmentRequest(DEFAULT_PROFILE_NAME, "label 1", null);
    req.addHost("example1.ibm.com");
    req.addHost("example2.ibm.com");
    Enrollment tmpEnroll = client.reenroll(user, req);
    // verify
    String cert = tmpEnroll.getCert();
    verifyOptions(cert, req);
    sleepALittle();
    // revoke one enrollment of this user
    client.revoke(admin, tmpEnroll, "remove user 2");
    // trying to reenroll should be ok (revocation above is only for a particular enrollment of this user)
    client.reenroll(user);
}
Also used : EnrollmentRequest(org.hyperledger.fabric_ca.sdk.EnrollmentRequest) Enrollment(org.hyperledger.fabric.sdk.Enrollment) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) RegistrationRequest(org.hyperledger.fabric_ca.sdk.RegistrationRequest) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser) Test(org.junit.Test)

Example 9 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class TestHFClient method setupClient.

public static void setupClient(HFClient hfclient) throws Exception {
    File tempFile = File.createTempFile("teststore", "properties");
    tempFile.deleteOnExit();
    File sampleStoreFile = new File(System.getProperty("user.home") + "/test.properties");
    if (sampleStoreFile.exists()) {
        // For testing start fresh
        sampleStoreFile.delete();
    }
    final SampleStore sampleStore = new SampleStore(sampleStoreFile);
    // src/test/fixture/sdkintegration/e2e-2Orgs/channel/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/
    // SampleUser someTestUSER = sampleStore.getMember("someTestUSER", "someTestORG");
    SampleUser someTestUSER = sampleStore.getMember("someTestUSER", "someTestORG", "mspid", findFileSk("src/test/fixture/sdkintegration/e2e-2Orgs/" + TestConfig.FAB_CONFIG_GEN_VERS + "/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore"), new File("src/test/fixture/sdkintegration/e2e-2Orgs/" + TestConfig.FAB_CONFIG_GEN_VERS + "/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"));
    someTestUSER.setMspId("testMSPID?");
    hfclient.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
    hfclient.setUserContext(someTestUSER);
}
Also used : SampleStore(org.hyperledger.fabric.sdkintegration.SampleStore) File(java.io.File) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser)

Example 10 with SampleUser

use of org.hyperledger.fabric.sdkintegration.SampleUser in project fabric-sdk-java by hyperledger.

the class HFCAClientIT method getEnrolledUser.

// Returns an enrolled user
private SampleUser getEnrolledUser(String org) throws Exception {
    SampleUser user = getTestUser(org);
    RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
    String password = "password";
    rr.setSecret(password);
    user.setEnrollmentSecret(client.register(rr, admin));
    if (!user.getEnrollmentSecret().equals(password)) {
        fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
    }
    user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret()));
    return user;
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) RegistrationRequest(org.hyperledger.fabric_ca.sdk.RegistrationRequest) SampleUser(org.hyperledger.fabric.sdkintegration.SampleUser)

Aggregations

SampleUser (org.hyperledger.fabric.sdkintegration.SampleUser)22 Test (org.junit.Test)20 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)9 RegistrationRequest (org.hyperledger.fabric_ca.sdk.RegistrationRequest)9 EnrollmentRequest (org.hyperledger.fabric_ca.sdk.EnrollmentRequest)8 MockHFCAClient (org.hyperledger.fabric_ca.sdk.MockHFCAClient)8 Attribute (org.hyperledger.fabric_ca.sdk.Attribute)7 Enrollment (org.hyperledger.fabric.sdk.Enrollment)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 File (java.io.File)2 SampleStore (org.hyperledger.fabric.sdkintegration.SampleStore)2 HFCAClient (org.hyperledger.fabric_ca.sdk.HFCAClient)2 HFCAIdentity (org.hyperledger.fabric_ca.sdk.HFCAIdentity)2 Ignore (org.junit.Ignore)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 HFCAAffiliation (org.hyperledger.fabric_ca.sdk.HFCAAffiliation)1