Search in sources :

Example 81 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class TenantControllerTest method getProfile.

private Profile getProfile(String tenantName, String role) {
    Profile profile = new Profile();
    profile.setTenant(tenantName);
    profile.getRoles().add(role);
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 82 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testUpdateProfile.

@Test
public void testUpdateProfile() throws Exception {
    final Profile expected = new Profile();
    expected.setId(PROFILE1_ID);
    expected.setTenant(TENANT1_NAME);
    expected.setUsername(USERNAME2);
    expected.setPassword(CryptoUtils.hashPassword(PASSWORD2));
    expected.setEmail(EMAIL2);
    expected.setRoles(ROLES2);
    expected.setVerified(true);
    expected.setEnabled(false);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    expected.getAttributes().put(ATTRIB_NAME_GENDER, GENDER);
    final Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(ATTRIB_NAME_GENDER, GENDER);
    Profile actual = profileService.updateProfile(PROFILE1_ID.toString(), USERNAME2, PASSWORD2, EMAIL2, false, ROLES2, newAttributes);
    assertEqualProfiles(expected, actual);
    ArgumentMatcher<Object> setParamMatcher = new ArgumentMatcher<Object>() {

        @Override
        public boolean matches(Object argument) {
            Map<String, Object> param = (Map<String, Object>) argument;
            return param.size() == 7 && param.get("username").equals(USERNAME2) && param.containsKey("password") && param.get("email").equals(EMAIL2) && param.get("roles").equals(ROLES2) && param.get("enabled").equals(false) && param.containsKey("lastModified") && param.get("attributes." + ATTRIB_NAME_GENDER).equals(GENDER);
        }
    };
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
    verify(profileRepository).update(eq(PROFILE1_ID.toString()), eq("{$set: #}"), eq(false), eq(false), argThat(setParamMatcher));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Mockito.anyString(org.mockito.Mockito.anyString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 83 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testResetPassword.

@Test
public void testResetPassword() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.resetPassword(PROFILE1_ID.toString(), RESET_PASSWORD_URL);
    assertEqualProfiles(expected, actual);
    VerificationToken token = new VerificationToken();
    token.setId(VERIFICATION_TOKEN_ID1);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
    verify(verificationService).createToken(actual);
    verify(verificationService).sendEmail(token, actual, RESET_PASSWORD_URL, RESET_PASSWORD_FROM_ADDRESS, RESET_PASSWORD_SUBJECT, RESET_PASSWORD_TEMPLATE_NAME);
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 84 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testCreateProfileNotVerify.

@Test
public void testCreateProfileNotVerify() throws Exception {
    Profile expected = getTenant2Profile();
    expected.setEnabled(true);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    expected.setAttribute(ATTRIB_NAME_GENDER, GENDER);
    Profile actual = profileService.createProfile(TENANT2_NAME, USERNAME2, PASSWORD2, EMAIL2, true, ROLES2, getAttributesWithoutPrivateAttribute(), VERIFICATION_URL);
    assertEqualProfiles(expected, actual);
    assertTrue(CryptoUtils.matchPassword(actual.getPassword(), PASSWORD2));
    assertNotNull(actual.getCreatedOn());
    assertNotNull(actual.getLastModified());
    verify(tenantPermissionEvaluator).isAllowed(TENANT2_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(tenantService).getTenant(TENANT2_NAME);
    verify(profileRepository).insert(actual);
    verify(verificationService, never()).createToken(any(Profile.class));
    verify(verificationService, never()).sendEmail(any(VerificationToken.class), any(Profile.class), anyString(), anyString(), anyString(), anyString());
}
Also used : VerificationToken(org.craftercms.profile.api.VerificationToken) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 85 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testUpdateAttributes.

@Test
public void testUpdateAttributes() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    expected.getAttributes().put(ATTRIB_NAME_GENDER, GENDER);
    Map<String, Object> newAttributes = Collections.<String, Object>singletonMap(ATTRIB_NAME_GENDER, GENDER);
    Profile actual = profileService.updateAttributes(PROFILE1_ID.toString(), newAttributes);
    assertEqualProfiles(expected, actual);
    ArgumentMatcher<Object> setParamMatcher = new ArgumentMatcher<Object>() {

        @Override
        public boolean matches(Object argument) {
            Map<String, Object> param = (Map<String, Object>) argument;
            return param.size() == 2 && param.containsKey("lastModified") && param.get("attributes." + ATTRIB_NAME_GENDER).equals(GENDER);
        }
    };
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
    verify(profileRepository).update(eq(PROFILE1_ID.toString()), eq("{$set: #}"), eq(false), eq(false), argThat(setParamMatcher));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Mockito.anyString(org.mockito.Mockito.anyString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Aggregations

Profile (org.craftercms.profile.api.Profile)111 Test (org.junit.Test)54 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)19 MongoDataException (org.craftercms.commons.mongo.MongoDataException)15 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)15 LinkedHashMap (java.util.LinkedHashMap)13 VerificationToken (org.craftercms.profile.api.VerificationToken)13 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)12 Date (java.util.Date)11 Map (java.util.Map)11 ObjectId (org.bson.types.ObjectId)10 RequestContext (org.craftercms.commons.http.RequestContext)9 Authentication (org.craftercms.security.authentication.Authentication)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Mockito.anyString (org.mockito.Mockito.anyString)9 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Tenant (org.craftercms.profile.api.Tenant)6 HashMap (java.util.HashMap)4