|
|
|
@ -16,10 +16,13 @@ |
|
|
|
package org.thingsboard.server.transport.lwm2m.security.sql; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.eclipse.leshan.client.object.Security; |
|
|
|
import org.eclipse.leshan.core.util.Hex; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.test.web.servlet.MvcResult; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials; |
|
|
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential; |
|
|
|
@ -27,7 +30,6 @@ import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTrans |
|
|
|
import org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import static org.eclipse.leshan.client.object.Security.psk; |
|
|
|
import static org.eclipse.leshan.client.object.Security.pskBootstrap; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
@ -37,6 +39,7 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MClient |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType.BOTH; |
|
|
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType.NONE; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTest { |
|
|
|
|
|
|
|
//Lwm2m only
|
|
|
|
@ -66,6 +69,82 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes |
|
|
|
ON_REGISTRATION_SUCCESS, |
|
|
|
true); |
|
|
|
} |
|
|
|
@Test |
|
|
|
public void testWithPskConnectLwm2mOneObserveSuccessUpdateProfileManyObserveUpdateRegistrationSuccess() throws Exception { |
|
|
|
String clientEndpoint = CLIENT_ENDPOINT_PSK; |
|
|
|
String identity = CLIENT_PSK_IDENTITY; |
|
|
|
String keyPsk = CLIENT_PSK_KEY; |
|
|
|
PSKClientCredential clientCredentials = new PSKClientCredential(); |
|
|
|
clientCredentials.setEndpoint(clientEndpoint); |
|
|
|
clientCredentials.setIdentity(identity); |
|
|
|
clientCredentials.setKey(keyPsk); |
|
|
|
Security security = psk(SECURE_URI, |
|
|
|
shortServerId, |
|
|
|
identity.getBytes(StandardCharsets.UTF_8), |
|
|
|
Hex.decodeHex(keyPsk.toCharArray())); |
|
|
|
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_ONE_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); |
|
|
|
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false); |
|
|
|
String awaitAlias = "await on client state (Psk_Lwm2m)"; |
|
|
|
Device lwm2mDevice = this.basicTestConnection(security, |
|
|
|
null, |
|
|
|
deviceCredentials, |
|
|
|
clientEndpoint, |
|
|
|
transportConfiguration, |
|
|
|
awaitAlias, |
|
|
|
expectedStatusesRegistrationLwm2mSuccess, |
|
|
|
false, |
|
|
|
ON_REGISTRATION_SUCCESS, |
|
|
|
true); |
|
|
|
|
|
|
|
awaitObserveReadAll(1, lwm2mDevice.getId().getId().toString()); |
|
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + lwm2mDevice.getDeviceProfileId().getId().toString(), DeviceProfile.class); |
|
|
|
transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_MANY_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); |
|
|
|
foundDeviceProfile.getProfileData().setTransportConfiguration(transportConfiguration); |
|
|
|
DeviceProfile lwm2mDeviceProfileManyParams = doPost("/api/deviceProfile", foundDeviceProfile, DeviceProfile.class); |
|
|
|
Assert.assertNotNull(lwm2mDeviceProfileManyParams); |
|
|
|
awaitObserveReadAll(2, lwm2mDevice.getId().getId().toString()); |
|
|
|
awaitUpdateReg(3); |
|
|
|
} |
|
|
|
@Test |
|
|
|
public void testWithPskConnectLwm2mSuccessObserveSuccessUnRegClientUpdateProfileObserveConnectLwm2mSuccessOWithNewObserve() throws Exception { |
|
|
|
String clientEndpoint = CLIENT_ENDPOINT_PSK; |
|
|
|
String identity = CLIENT_PSK_IDENTITY; |
|
|
|
String keyPsk = CLIENT_PSK_KEY; |
|
|
|
PSKClientCredential clientCredentials = new PSKClientCredential(); |
|
|
|
clientCredentials.setEndpoint(clientEndpoint); |
|
|
|
clientCredentials.setIdentity(identity); |
|
|
|
clientCredentials.setKey(keyPsk); |
|
|
|
Security security = psk(SECURE_URI, |
|
|
|
shortServerId, |
|
|
|
identity.getBytes(StandardCharsets.UTF_8), |
|
|
|
Hex.decodeHex(keyPsk.toCharArray())); |
|
|
|
Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_ONE_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); |
|
|
|
LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false); |
|
|
|
String awaitAlias = "await on client state (Psk_Lwm2m)"; |
|
|
|
Device lwm2mDevice = this.basicTestConnection(security, |
|
|
|
null, |
|
|
|
deviceCredentials, |
|
|
|
clientEndpoint, |
|
|
|
transportConfiguration, |
|
|
|
awaitAlias, |
|
|
|
expectedStatusesRegistrationLwm2mSuccess, |
|
|
|
false, |
|
|
|
ON_REGISTRATION_SUCCESS, |
|
|
|
true); |
|
|
|
|
|
|
|
awaitObserveReadAll(1, lwm2mDevice.getId().getId().toString()); |
|
|
|
lwM2MTestClient.stop(true); |
|
|
|
|
|
|
|
DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + lwm2mDevice.getDeviceProfileId().getId().toString(), DeviceProfile.class); |
|
|
|
transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_MANY_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); |
|
|
|
foundDeviceProfile.getProfileData().setTransportConfiguration(transportConfiguration); |
|
|
|
DeviceProfile lwm2mDeviceProfileManyParams = doPost("/api/deviceProfile", foundDeviceProfile, DeviceProfile.class); |
|
|
|
Assert.assertNotNull(lwm2mDeviceProfileManyParams); |
|
|
|
|
|
|
|
lwM2MTestClient.start(true); |
|
|
|
awaitObserveReadAll(2, lwm2mDevice.getId().getId().toString()); |
|
|
|
awaitUpdateReg(3); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testWithPskConnectLwm2mBadPskKeyByLength_BAD_REQUEST() throws Exception { |
|
|
|
|