|
|
@ -36,7 +36,10 @@ import org.junit.rules.TestRule; |
|
|
import org.junit.rules.TestWatcher; |
|
|
import org.junit.rules.TestWatcher; |
|
|
import org.junit.runner.Description; |
|
|
import org.junit.runner.Description; |
|
|
import org.mockito.Mockito; |
|
|
import org.mockito.Mockito; |
|
|
|
|
|
import org.mockito.invocation.InvocationOnMock; |
|
|
|
|
|
import org.mockito.stubbing.Answer; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
|
|
import org.springframework.http.HttpHeaders; |
|
|
import org.springframework.http.HttpHeaders; |
|
|
import org.springframework.http.MediaType; |
|
|
import org.springframework.http.MediaType; |
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
@ -52,6 +55,9 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde |
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
import org.springframework.util.MultiValueMap; |
|
|
import org.springframework.util.MultiValueMap; |
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
import org.springframework.web.context.WebApplicationContext; |
|
|
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
|
|
import org.thingsboard.rule.engine.api.MailService; |
|
|
|
|
|
import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
import org.thingsboard.server.common.data.DeviceProfileType; |
|
|
import org.thingsboard.server.common.data.DeviceProfileType; |
|
|
@ -69,6 +75,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; |
|
|
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; |
|
|
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; |
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
import org.thingsboard.server.common.data.id.HasId; |
|
|
import org.thingsboard.server.common.data.id.HasId; |
|
|
@ -83,7 +90,6 @@ import org.thingsboard.server.common.data.security.Authority; |
|
|
import org.thingsboard.server.config.ThingsboardSecurityConfiguration; |
|
|
import org.thingsboard.server.config.ThingsboardSecurityConfiguration; |
|
|
import org.thingsboard.server.dao.Dao; |
|
|
import org.thingsboard.server.dao.Dao; |
|
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|
|
import org.thingsboard.server.service.mail.TestMailService; |
|
|
|
|
|
import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest; |
|
|
import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRequest; |
|
|
import org.thingsboard.server.service.security.auth.rest.LoginRequest; |
|
|
import org.thingsboard.server.service.security.auth.rest.LoginRequest; |
|
|
|
|
|
|
|
|
@ -98,6 +104,7 @@ import java.util.List; |
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyString; |
|
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; |
|
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; |
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; |
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; |
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
|
|
@ -144,6 +151,9 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { |
|
|
|
|
|
|
|
|
protected MockMvc mockMvc; |
|
|
protected MockMvc mockMvc; |
|
|
|
|
|
|
|
|
|
|
|
protected String currentActivateToken; |
|
|
|
|
|
protected String currentResetPasswordToken; |
|
|
|
|
|
|
|
|
protected String token; |
|
|
protected String token; |
|
|
protected String refreshToken; |
|
|
protected String refreshToken; |
|
|
protected String username; |
|
|
protected String username; |
|
|
@ -168,6 +178,9 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private TenantProfileService tenantProfileService; |
|
|
private TenantProfileService tenantProfileService; |
|
|
|
|
|
|
|
|
|
|
|
@SpyBean |
|
|
|
|
|
protected MailService mailService; |
|
|
|
|
|
|
|
|
@Rule |
|
|
@Rule |
|
|
public TestRule watcher = new TestWatcher() { |
|
|
public TestRule watcher = new TestWatcher() { |
|
|
protected void starting(Description description) { |
|
|
protected void starting(Description description) { |
|
|
@ -200,6 +213,8 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { |
|
|
public void setupWebTest() throws Exception { |
|
|
public void setupWebTest() throws Exception { |
|
|
log.info("Executing web test setup"); |
|
|
log.info("Executing web test setup"); |
|
|
|
|
|
|
|
|
|
|
|
setupMailServiceMock(); |
|
|
|
|
|
|
|
|
if (this.mockMvc == null) { |
|
|
if (this.mockMvc == null) { |
|
|
this.mockMvc = webAppContextSetup(webApplicationContext) |
|
|
this.mockMvc = webAppContextSetup(webApplicationContext) |
|
|
.apply(springSecurity()).build(); |
|
|
.apply(springSecurity()).build(); |
|
|
@ -241,6 +256,27 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { |
|
|
log.info("Executed web test setup"); |
|
|
log.info("Executed web test setup"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setupMailServiceMock() throws ThingsboardException { |
|
|
|
|
|
Mockito.doNothing().when(mailService).sendAccountActivatedEmail(anyString(), anyString()); |
|
|
|
|
|
Mockito.doAnswer(new Answer<Void>() { |
|
|
|
|
|
public Void answer(InvocationOnMock invocation) { |
|
|
|
|
|
Object[] args = invocation.getArguments(); |
|
|
|
|
|
String activationLink = (String) args[0]; |
|
|
|
|
|
currentActivateToken = activationLink.split("=")[1]; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
}).when(mailService).sendActivationEmail(anyString(), anyString()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.doAnswer(new Answer<Void>() { |
|
|
|
|
|
public Void answer(InvocationOnMock invocation) { |
|
|
|
|
|
Object[] args = invocation.getArguments(); |
|
|
|
|
|
String passwordResetLink = (String) args[0]; |
|
|
|
|
|
currentResetPasswordToken = passwordResetLink.split("=")[1]; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
}).when(mailService).sendResetPasswordEmailAsync(anyString(), anyString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@After |
|
|
@After |
|
|
public void teardownWebTest() throws Exception { |
|
|
public void teardownWebTest() throws Exception { |
|
|
log.info("Executing web test teardown"); |
|
|
log.info("Executing web test teardown"); |
|
|
@ -368,11 +404,11 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private JsonNode getActivateRequest(String password) throws Exception { |
|
|
private JsonNode getActivateRequest(String password) throws Exception { |
|
|
doGet("/api/noauth/activate?activateToken={activateToken}", TestMailService.currentActivateToken) |
|
|
doGet("/api/noauth/activate?activateToken={activateToken}", this.currentActivateToken) |
|
|
.andExpect(status().isSeeOther()) |
|
|
.andExpect(status().isSeeOther()) |
|
|
.andExpect(header().string(HttpHeaders.LOCATION, "/login/createPassword?activateToken=" + TestMailService.currentActivateToken)); |
|
|
.andExpect(header().string(HttpHeaders.LOCATION, "/login/createPassword?activateToken=" + this.currentActivateToken)); |
|
|
return new ObjectMapper().createObjectNode() |
|
|
return new ObjectMapper().createObjectNode() |
|
|
.put("activateToken", TestMailService.currentActivateToken) |
|
|
.put("activateToken", this.currentActivateToken) |
|
|
.put("password", password); |
|
|
.put("password", password); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|