use of org.hyperledger.fabric_ca.sdk.Attribute in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testRegisterAttributesNONE.
/**
* Test that we get no attributes.
*
* @throws Exception
*/
@Test
public void testRegisterAttributesNONE() throws Exception {
SampleUser user = new SampleUser("mrAttributesNone", 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();
// empty ensure no attributes.
req.addAttrReq();
user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret(), req));
Enrollment enrollment = user.getEnrollment();
String cert = enrollment.getCert();
String certdec = getStringCert(cert);
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\""));
assertFalse(format("Contains testattr2 in certificate decoded: %s", certdec), certdec.contains("\"testattr2\"") || certdec.contains("\"mrAttributesValue2\""));
}
use of org.hyperledger.fabric_ca.sdk.Attribute in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testUserRevoke.
// Tests attempting to re-enroll a revoked user
@Test
public void testUserRevoke() throws Exception {
thrown.expect(EnrollmentException.class);
thrown.expectMessage("Failed to re-enroll user");
// gets a calendar using the default time zone and locale.
Calendar calendar = Calendar.getInstance();
// avoid any clock skewing.
Date revokedTinyBitAgoTime = calendar.getTime();
SampleUser user = getTestUser(TEST_USER1_ORG);
if (!user.isRegistered()) {
RegistrationRequest rr = new RegistrationRequest(user.getName(), TEST_USER1_AFFILIATION);
String password = "testUserRevoke";
rr.setSecret(password);
rr.addAttribute(new Attribute("user.role", "department lead"));
rr.addAttribute(new Attribute(HFCAClient.HFCA_ATTRIBUTE_HFREVOKER, "true"));
// Admin can register other users.
user.setEnrollmentSecret(client.register(rr, admin));
if (!user.getEnrollmentSecret().equals(password)) {
fail("Secret returned from RegistrationRequest not match : " + user.getEnrollmentSecret());
}
}
if (!user.isEnrolled()) {
EnrollmentRequest req = new EnrollmentRequest(DEFAULT_PROFILE_NAME, "label 2", null);
req.addHost("example3.ibm.com");
user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret(), req));
// verify
String cert = user.getEnrollment().getCert();
verifyOptions(cert, req);
}
int startedWithRevokes = -1;
if (!testConfig.isRunningAgainstFabric10()) {
// prevent clock skewing. make sure we request started with revokes.
Thread.sleep(1000);
// one more after we do this revoke.
startedWithRevokes = getRevokes(null).length;
// prevent clock skewing. make sure we request started with revokes.
Thread.sleep(1000);
}
// revoke all enrollment of this user
client.revoke(admin, user.getName(), "revoke user 3");
if (!testConfig.isRunningAgainstFabric10()) {
final int newRevokes = getRevokes(null).length;
assertEquals(format("Expected one more revocation %d, but got %d", startedWithRevokes + 1, newRevokes), startedWithRevokes + 1, newRevokes);
// see if we can get right number of revokes that we started with by specifying the time: revokedTinyBitAgoTime
// TODO: Investigate clock scew
// final int revokestinybitago = getRevokes(revokedTinyBitAgoTime).length; //Should be same number when test case was started.
// assertEquals(format("Expected same revocations %d, but got %d", startedWithRevokes, revokestinybitago), startedWithRevokes, revokestinybitago);
}
// trying to reenroll the revoked user should fail with an EnrollmentException
client.reenroll(user);
}
use of org.hyperledger.fabric_ca.sdk.Attribute in project fabric-sdk-java by hyperledger.
the class HFCAClientIT method testRegisterAttributesDefault.
/**
* Test that we get default attributes.
*
* @throws Exception
*/
@Test
public void testRegisterAttributesDefault() throws Exception {
if (testConfig.isRunningAgainstFabric10()) {
// needs v1.1
return;
}
SampleUser user = new SampleUser("mrAttributesDefault", 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());
}
user.setEnrollment(client.enroll(user.getName(), user.getEnrollmentSecret()));
Enrollment enrollment = user.getEnrollment();
String cert = enrollment.getCert();
String certdec = getStringCert(cert);
assertTrue(format("Missing testattrDEFAULTATTR in certficate decoded: %s", certdec), certdec.contains("\"testattrDEFAULTATTR\":\"mrAttributesValueDEFAULTATTR\""));
// Since request and no attribute requests at all defaults should be in certificate.
assertFalse(format("Contains testattr1 in certificate decoded: %s", certdec), certdec.contains("\"testattr1\"") || certdec.contains("\"mrAttributesValue1\""));
assertFalse(format("Contains testattr2 in certificate decoded: %s", certdec), certdec.contains("\"testattr2\"") || certdec.contains("\"mrAttributesValue2\""));
}
use of org.hyperledger.fabric_ca.sdk.Attribute 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;
}
Aggregations