|
|
|
@ -20,8 +20,11 @@ import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
|
import org.springframework.test.web.servlet.ResultMatcher; |
|
|
|
import org.testcontainers.shaded.org.awaitility.Awaitility; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.EdgeUtils; |
|
|
|
import org.thingsboard.server.common.data.StringUtils; |
|
|
|
import org.thingsboard.server.common.data.User; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
@ -41,6 +44,7 @@ import org.thingsboard.server.service.security.model.ChangePasswordRequest; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
import static org.thingsboard.server.dao.user.UserServiceImpl.DEFAULT_TOKEN_LENGTH; |
|
|
|
@ -148,6 +152,43 @@ public class UserEdgeTest extends AbstractEdgeTest { |
|
|
|
testAutoGeneratedCodeByProtobuf(userCredentialsUpdateMsg); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSendUserDeleteFromEdgeToCloud() throws Exception { |
|
|
|
// create customer
|
|
|
|
Customer savedCustomer = createAndAssignCustomerToEdge(); |
|
|
|
|
|
|
|
// create user
|
|
|
|
User customerUser = buildUser(Authority.CUSTOMER_USER, savedCustomer.getId()); |
|
|
|
User savedCustomerUser = createAndVerifyUserOnEdge(customerUser); |
|
|
|
|
|
|
|
// simulate user removal event from edge to cloud
|
|
|
|
UserUpdateMsg.Builder userUpdateMsg = UserUpdateMsg.newBuilder().setMsgType(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE) |
|
|
|
.setIdMSB(savedCustomerUser.getUuidId().getMostSignificantBits()) |
|
|
|
.setIdLSB(savedCustomerUser.getUuidId().getLeastSignificantBits()); |
|
|
|
|
|
|
|
UplinkMsg uplink = UplinkMsg.newBuilder() |
|
|
|
.setUplinkMsgId(EdgeUtils.nextPositiveInt()) |
|
|
|
.addUserUpdateMsg(userUpdateMsg).build(); |
|
|
|
|
|
|
|
testAutoGeneratedCodeByProtobuf(userUpdateMsg); |
|
|
|
|
|
|
|
// expect edge message sent & cloud message response
|
|
|
|
edgeImitator.expectResponsesAmount(1); |
|
|
|
edgeImitator.sendUplinkMsg(uplink); |
|
|
|
Assert.assertTrue(edgeImitator.waitForResponses()); |
|
|
|
|
|
|
|
loginTenantAdmin(); |
|
|
|
Awaitility.await().atMost(10, TimeUnit.SECONDS) |
|
|
|
.until(() -> { |
|
|
|
try { |
|
|
|
doGet("/api/user/" + savedCustomerUser.getId(), User.class, status().isNotFound()); |
|
|
|
return true; |
|
|
|
} catch (Throwable ex) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private Customer createAndAssignCustomerToEdge() throws Exception { |
|
|
|
edgeImitator.expectMessageAmount(1); |
|
|
|
Customer customer = new Customer(); |
|
|
|
|