use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testCreateVerificationToken.
@Test
public void testCreateVerificationToken() throws Exception {
Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
String profileId = profile.getId().toString();
VerificationToken token = profileService.createVerificationToken(profileId);
assertNotNull(token);
try {
assertNotNull(token.getId());
assertEquals(profile.getTenant(), token.getTenant());
assertEquals(profileId, token.getProfileId());
assertNotNull(token.getTimestamp());
} finally {
profileService.deleteVerificationToken(token.getId());
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testUpdateAttributes.
@Test
@DirtiesContext
public void testUpdateAttributes() throws Exception {
// Update a bunch attributes
Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, false, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
Map<String, Object> attributes = new HashMap<>();
try {
Map<String, Object> subscriptions = new HashMap<>();
subscriptions.put("frequency", JDOE_SUBSCRIPTIONS_FREQUENCY);
subscriptions.put("autoWatch", JDOE_SUBSCRIPTIONS_AUTO_WATCH);
subscriptions.put("targets", JDOE_SUBSCRIPTIONS_TARGETS);
attributes.put("subscriptions", subscriptions);
profile = profileService.updateAttributes(profile.getId().toString(), attributes);
attributes = profile.getAttributes();
assertNotNull(attributes);
assertEquals(1, attributes.size());
subscriptions = (Map<String, Object>) attributes.get("subscriptions");
assertNotNull(subscriptions);
assertEquals(3, subscriptions.size());
assertEquals(JDOE_SUBSCRIPTIONS_FREQUENCY, subscriptions.get("frequency"));
assertEquals(JDOE_SUBSCRIPTIONS_AUTO_WATCH, subscriptions.get("autoWatch"));
assertEquals(JDOE_SUBSCRIPTIONS_TARGETS, subscriptions.get("targets"));
accessTokenIdResolver.setAccessTokenId(RANDOM_APP_ACCESS_TOKEN_ID);
// Unallowed updates should be rejected
try {
profileService.updateAttributes(profile.getId().toString(), attributes);
fail("Exception " + ProfileRestServiceException.class.getName() + " expected");
} catch (ProfileRestServiceException e) {
assertEquals(HttpStatus.FORBIDDEN, e.getStatus());
assertEquals(ErrorCode.ACTION_DENIED, e.getErrorCode());
}
} finally {
profileService.deleteProfile(profile.getId().toString());
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testDeleteProfile.
@Test
public void testDeleteProfile() throws Exception {
Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, false, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
assertNotNull(profile);
profileService.deleteProfile(profile.getId().toString());
profile = profileService.getProfile(profile.getId().toString());
assertNull(profile);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testGetVerificationToken.
@Test
public void testGetVerificationToken() throws Exception {
Profile profile = profileService.getProfileByUsername(DEFAULT_TENANT, ADMIN_USERNAME);
String profileId = profile.getId().toString();
VerificationToken originalToken = profileService.createVerificationToken(profileId);
assertNotNull(originalToken);
try {
VerificationToken token = profileService.getVerificationToken(originalToken.getId());
assertNotNull(token);
assertEquals(originalToken.getId(), token.getId());
assertEquals(originalToken.getTenant(), token.getTenant());
assertEquals(originalToken.getProfileId(), token.getProfileId());
assertEquals(originalToken.getTimestamp(), token.getTimestamp());
} finally {
profileService.deleteVerificationToken(originalToken.getId());
}
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceIT method testCreateAndVerifyProfile.
@Test
public void testCreateAndVerifyProfile() throws Exception {
GreenMail mailServer = new GreenMail(ServerSetupTest.SMTP);
mailServer.start();
tenantService.verifyNewProfiles(DEFAULT_TENANT, true);
Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1, AVASQUEZ_EMAIL1, true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
try {
assertNotNull(profile);
assertNotNull(profile.getId());
assertEquals(AVASQUEZ_USERNAME, profile.getUsername());
assertNull(profile.getPassword());
assertEquals(AVASQUEZ_EMAIL1, profile.getEmail());
assertFalse(profile.isVerified());
assertFalse(profile.isEnabled());
assertNotNull(profile.getCreatedOn());
assertNotNull(profile.getLastModified());
assertEquals(DEFAULT_TENANT, profile.getTenant());
assertEquals(AVASQUEZ_ROLES1, profile.getRoles());
assertNotNull(profile.getAttributes());
assertEquals(0, profile.getAttributes().size());
// Wait a few seconds so that the email can be sent
Thread.sleep(3000);
String email = GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]);
assertNotNull(email);
Pattern emailPattern = Pattern.compile(VERIFICATION_EMAIL_REGEX, Pattern.DOTALL);
Matcher emailMatcher = emailPattern.matcher(email);
assertTrue(emailMatcher.matches());
String verificationTokenId = emailMatcher.group(1);
Profile verifiedProfile = profileService.verifyProfile(verificationTokenId);
assertNotNull(verifiedProfile);
assertEquals(profile.getId(), verifiedProfile.getId());
assertTrue(verifiedProfile.isEnabled());
assertTrue(verifiedProfile.isVerified());
} finally {
profileService.deleteProfile(profile.getId().toString());
tenantService.verifyNewProfiles(DEFAULT_TENANT, false);
mailServer.stop();
}
}
Aggregations