Search in sources :

Example 6 with AuditEntity

use of io.gravitee.rest.api.model.audit.AuditEntity in project gravitee-management-rest-api by gravitee-io.

the class UserServiceTest method shouldNotResetPassword_AlreadyReset.

@Test(expected = PasswordAlreadyResetException.class)
public void shouldNotResetPassword_AlreadyReset() throws TechnicalException {
    when(user.getId()).thenReturn(USER_NAME);
    when(user.getSource()).thenReturn("gravitee");
    when(userRepository.findById(USER_NAME)).thenReturn(of(user));
    MetadataPage mdPage = mock(MetadataPage.class);
    AuditEntity entity1 = new AuditEntity();
    entity1.setProperties(Collections.singletonMap("USER", USER_NAME));
    when(mdPage.getContent()).thenReturn(Arrays.asList(entity1));
    when(auditService.search(argThat(arg -> arg.getEvents().contains(User.AuditEvent.PASSWORD_RESET.name())))).thenReturn(mdPage);
    userService.resetPassword(USER_NAME);
    verify(user, never()).setPassword(null);
    verify(userRepository, never()).update(user);
    verify(emailService, never()).sendAsyncEmailNotification(any(), any());
}
Also used : AuditEntity(io.gravitee.rest.api.model.audit.AuditEntity) ArgumentMatchers(org.mockito.ArgumentMatchers) Optional.of(java.util.Optional.of) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) MembershipRepository(io.gravitee.repository.management.api.MembershipRepository) SocialIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.SocialIdentityProviderEntity) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) ArgumentMatcher(org.mockito.ArgumentMatcher) Algorithm(com.auth0.jwt.algorithms.Algorithm) RoleMappingEntity(io.gravitee.rest.api.model.configuration.identity.RoleMappingEntity) Duration(java.time.Duration) GroupMappingEntity(io.gravitee.rest.api.model.configuration.identity.GroupMappingEntity) ExpressionEvaluationException(io.gravitee.el.exceptions.ExpressionEvaluationException) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) Instant(java.time.Instant) RESET_PASSWORD(io.gravitee.rest.api.service.common.JWTHelper.ACTION.RESET_PASSWORD) UserServiceImpl(io.gravitee.rest.api.service.impl.UserServiceImpl) AdditionalAnswers.returnsFirstArg(org.mockito.AdditionalAnswers.returnsFirstArg) Key(io.gravitee.rest.api.model.parameters.Key) IOUtils(org.apache.commons.io.IOUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AuditEntity(io.gravitee.rest.api.model.audit.AuditEntity) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) Optional.empty(java.util.Optional.empty) JWT(com.auth0.jwt.JWT) java.util(java.util) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER(io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Charset(java.nio.charset.Charset) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) UserRepository(io.gravitee.repository.management.api.UserRepository) UserStatus(io.gravitee.repository.management.model.UserStatus) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Membership(io.gravitee.repository.management.model.Membership) InjectMocks(org.mockito.InjectMocks) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ApplicationType(io.gravitee.repository.management.model.ApplicationType) IOException(java.io.IOException) Test(org.junit.Test) Maps(io.gravitee.common.util.Maps) DEFAULT_JWT_ISSUER(io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER) Mockito(org.mockito.Mockito) MetadataPage(io.gravitee.common.data.domain.MetadataPage) ReflectionTestUtils.setField(org.springframework.test.util.ReflectionTestUtils.setField) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) User(io.gravitee.repository.management.model.User) JWTHelper(io.gravitee.rest.api.service.common.JWTHelper) Assert(org.junit.Assert) USER_REGISTRATION(io.gravitee.rest.api.service.common.JWTHelper.ACTION.USER_REGISTRATION) InputStream(java.io.InputStream) MetadataPage(io.gravitee.common.data.domain.MetadataPage) Test(org.junit.Test)

Aggregations

AuditEntity (io.gravitee.rest.api.model.audit.AuditEntity)6 MetadataPage (io.gravitee.common.data.domain.MetadataPage)5 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 JWT (com.auth0.jwt.JWT)3 Algorithm (com.auth0.jwt.algorithms.Algorithm)3 Maps (io.gravitee.common.util.Maps)3 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)3 UserRepository (io.gravitee.repository.management.api.UserRepository)3 Membership (io.gravitee.repository.management.model.Membership)3 User (io.gravitee.repository.management.model.User)3 UserStatus (io.gravitee.repository.management.model.UserStatus)3 io.gravitee.rest.api.model (io.gravitee.rest.api.model)3 GroupMappingEntity (io.gravitee.rest.api.model.configuration.identity.GroupMappingEntity)3 RoleMappingEntity (io.gravitee.rest.api.model.configuration.identity.RoleMappingEntity)3 SocialIdentityProviderEntity (io.gravitee.rest.api.model.configuration.identity.SocialIdentityProviderEntity)3 Key (io.gravitee.rest.api.model.parameters.Key)3 ParameterReferenceType (io.gravitee.rest.api.model.parameters.ParameterReferenceType)3 RoleScope (io.gravitee.rest.api.model.permissions.RoleScope)3 Page (io.gravitee.common.data.domain.Page)2 ExpressionEvaluationException (io.gravitee.el.exceptions.ExpressionEvaluationException)2