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