Search in sources :

Example 1 with DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER

use of io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER in project gravitee-management-rest-api by gravitee-io.

the class UserServiceTest method shouldResetPassword_auditEventNotMatch.

@Test
public void shouldResetPassword_auditEventNotMatch() throws TechnicalException {
    when(environment.getProperty("jwt.secret")).thenReturn(JWT_SECRET);
    when(environment.getProperty("user.creation.token.expire-after", Integer.class, DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER)).thenReturn(1000);
    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", "unknown"));
    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).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

JWT (com.auth0.jwt.JWT)1 Algorithm (com.auth0.jwt.algorithms.Algorithm)1 MetadataPage (io.gravitee.common.data.domain.MetadataPage)1 Maps (io.gravitee.common.util.Maps)1 ExpressionEvaluationException (io.gravitee.el.exceptions.ExpressionEvaluationException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)1 UserRepository (io.gravitee.repository.management.api.UserRepository)1 ApplicationType (io.gravitee.repository.management.model.ApplicationType)1 Membership (io.gravitee.repository.management.model.Membership)1 User (io.gravitee.repository.management.model.User)1 UserStatus (io.gravitee.repository.management.model.UserStatus)1 io.gravitee.rest.api.model (io.gravitee.rest.api.model)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)1 AuditEntity (io.gravitee.rest.api.model.audit.AuditEntity)1 GroupMappingEntity (io.gravitee.rest.api.model.configuration.identity.GroupMappingEntity)1 RoleMappingEntity (io.gravitee.rest.api.model.configuration.identity.RoleMappingEntity)1 SocialIdentityProviderEntity (io.gravitee.rest.api.model.configuration.identity.SocialIdentityProviderEntity)1 Key (io.gravitee.rest.api.model.parameters.Key)1