Browse Source

Merge pull request #5580 from thingsboard/lwm2m_test_base64

[3.3.3] lwm2m - Test base64 and new profile
pull/5599/head
Andrew Shvayka 5 years ago
committed by GitHub
parent
commit
5c229d616e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java
  2. 69
      application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java
  3. 64
      application/src/test/java/org/thingsboard/server/transport/lwm2m/rpc/AbstractRpcLwM2MIntegrationTest.java
  4. 2
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsServiceImpl.java
  5. 29
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java

64
application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java

@ -82,38 +82,46 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
" ],\n" + " ],\n" +
" \"attributeLwm2m\": {}\n" + " \"attributeLwm2m\": {}\n" +
" },\n" + " },\n" +
" \"bootstrap\": {\n" + " \"bootstrap\": [\n" +
" \"servers\": {\n" + " {\n" +
" \"binding\": \"U\",\n" + " \"host\": \"0.0.0.0\",\n" +
" \"shortId\": 123,\n" + " \"port\": 5687,\n" +
" \"lifetime\": 300,\n" + " \"binding\": \"U\",\n" +
" \"notifIfDisabled\": true,\n" + " \"lifetime\": 300,\n" +
" \"defaultMinPeriod\": 1\n" + " \"securityMode\": \"NO_SEC\",\n" +
" \"shortServerId\": 111,\n" +
" \"notifIfDisabled\": true,\n" +
" \"serverPublicKey\": \"\",\n" +
" \"defaultMinPeriod\": 1,\n" +
" \"bootstrapServerIs\": true,\n" +
" \"clientHoldOffTime\": 1,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" +
" },\n" + " },\n" +
" \"lwm2mServer\": {\n" + " {\n" +
" \"host\": \"localhost\",\n" + " \"host\": \"0.0.0.0\",\n" +
" \"port\": 5686,\n" + " \"port\": 5685,\n" +
" \"serverId\": 123,\n" + " \"binding\": \"U\",\n" +
" \"serverPublicKey\": \"\",\n" + " \"lifetime\": 300,\n" +
" \"bootstrapServerIs\": false,\n" + " \"securityMode\": \"NO_SEC\",\n" +
" \"clientHoldOffTime\": 1,\n" + " \"shortServerId\": 123,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" + " \"notifIfDisabled\": true,\n" +
" },\n" + " \"serverPublicKey\": \"\",\n" +
" \"bootstrapServer\": {\n" + " \"defaultMinPeriod\": 1,\n" +
" \"host\": \"localhost\",\n" + " \"bootstrapServerIs\": false,\n" +
" \"port\": 5687,\n" + " \"clientHoldOffTime\": 1,\n" +
" \"serverId\": 111,\n" + " \"bootstrapServerAccountTimeout\": 0\n" +
" \"securityMode\": \"NO_SEC\",\n" +
" \"serverPublicKey\": \"\",\n" +
" \"bootstrapServerIs\": true,\n" +
" \"clientHoldOffTime\": 1,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" +
" }\n" + " }\n" +
" },\n" + " ],\n" +
" \"clientLwM2mSettings\": {\n" + " \"clientLwM2mSettings\": {\n" +
" \"clientOnlyObserveAfterConnect\": 1,\n" + " \"edrxCycle\": null,\n" +
" \"powerMode\": \"DRX\",\n" +
" \"fwUpdateResource\": null,\n" +
" \"fwUpdateStrategy\": 1,\n" + " \"fwUpdateStrategy\": 1,\n" +
" \"swUpdateStrategy\": 1\n" + " \"psmActivityTimer\": null,\n" +
" \"swUpdateResource\": null,\n" +
" \"swUpdateStrategy\": 1,\n" +
" \"pagingTransmissionWindow\": null,\n" +
" \"clientOnlyObserveAfterConnect\": 1\n" +
" }\n" + " }\n" +
"}"; "}";

69
application/src/test/java/org/thingsboard/server/transport/lwm2m/ota/sql/OtaLwM2MIntegrationTest.java

@ -54,6 +54,7 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
public static final int TIMEOUT = 30; public static final int TIMEOUT = 30;
private final String OTA_TRANSPORT_CONFIGURATION = "{\n" + private final String OTA_TRANSPORT_CONFIGURATION = "{\n" +
" \"type\": \"LWM2M\",\n" +
" \"observeAttr\": {\n" + " \"observeAttr\": {\n" +
" \"keyName\": {\n" + " \"keyName\": {\n" +
" \"/5_1.0/0/3\": \"state\",\n" + " \"/5_1.0/0/3\": \"state\",\n" +
@ -91,43 +92,47 @@ public class OtaLwM2MIntegrationTest extends AbstractOtaLwM2MIntegrationTest {
" ],\n" + " ],\n" +
" \"attributeLwm2m\": {}\n" + " \"attributeLwm2m\": {}\n" +
" },\n" + " },\n" +
" \"bootstrap\": {\n" + " \"bootstrap\": [\n" +
" \"servers\": {\n" + " {\n" +
" \"binding\": \"UQ\",\n" + " \"host\": \"0.0.0.0\",\n" +
" \"shortId\": 123,\n" + " \"port\": 5687,\n" +
" \"lifetime\": 300,\n" + " \"binding\": \"U\",\n" +
" \"notifIfDisabled\": true,\n" + " \"lifetime\": 300,\n" +
" \"defaultMinPeriod\": 1\n" + " \"securityMode\": \"NO_SEC\",\n" +
" \"shortServerId\": 111,\n" +
" \"notifIfDisabled\": true,\n" +
" \"serverPublicKey\": \"\",\n" +
" \"defaultMinPeriod\": 1,\n" +
" \"bootstrapServerIs\": true,\n" +
" \"clientHoldOffTime\": 1,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" +
" },\n" + " },\n" +
" \"lwm2mServer\": {\n" + " {\n" +
" \"host\": \"localhost\",\n" + " \"host\": \"0.0.0.0\",\n" +
" \"port\": 5685,\n" + " \"port\": 5685,\n" +
" \"serverId\": 123,\n" + " \"binding\": \"U\",\n" +
" \"securityMode\": \"NO_SEC\",\n" + " \"lifetime\": 300,\n" +
" \"serverPublicKey\": \"\",\n" + " \"securityMode\": \"NO_SEC\",\n" +
" \"clientHoldOffTime\": 1,\n" + " \"shortServerId\": 123,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" + " \"notifIfDisabled\": true,\n" +
" },\n" + " \"serverPublicKey\": \"\",\n" +
" \"bootstrapServer\": {\n" + " \"defaultMinPeriod\": 1,\n" +
" \"host\": \"localhost\",\n" + " \"bootstrapServerIs\": false,\n" +
" \"port\": 5687,\n" + " \"clientHoldOffTime\": 1,\n" +
" \"serverId\": 111,\n" + " \"bootstrapServerAccountTimeout\": 0\n" +
" \"securityMode\": \"NO_SEC\",\n" +
" \"serverPublicKey\": \"\",\n" +
" \"clientHoldOffTime\": 1,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" +
" }\n" + " }\n" +
" },\n" + " ],\n" +
" \"clientLwM2mSettings\": {\n" + " \"clientLwM2mSettings\": {\n" +
" \"edrxCycle\": null,\n" +
" \"powerMode\": \"DRX\",\n" +
" \"fwUpdateResource\": null,\n" +
" \"fwUpdateStrategy\": 1,\n" + " \"fwUpdateStrategy\": 1,\n" +
" \"psmActivityTimer\": null,\n" +
" \"swUpdateResource\": null,\n" +
" \"swUpdateStrategy\": 1,\n" + " \"swUpdateStrategy\": 1,\n" +
" \"clientOnlyObserveAfterConnect\": 1,\n" + " \"pagingTransmissionWindow\": null,\n" +
" \"powerMode\": \"PSM\",\n" + " \"clientOnlyObserveAfterConnect\": 1\n" +
" \"fwUpdateResource\": \"\",\n" + " }\n" +
" \"swUpdateResource\": \"\",\n" +
" \"compositeOperationsSupport\": false\n" +
" },\n" +
" \"type\": \"LWM2M\"\n" +
"}"; "}";
@Test @Test

64
application/src/test/java/org/thingsboard/server/transport/lwm2m/rpc/AbstractRpcLwM2MIntegrationTest.java

@ -142,38 +142,46 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractLwM2MInteg
" ],\n" + " ],\n" +
" \"attributeLwm2m\": {}\n" + " \"attributeLwm2m\": {}\n" +
" },\n" + " },\n" +
" \"bootstrap\": {\n" + " \"bootstrap\": [\n" +
" \"servers\": {\n" + " {\n" +
" \"binding\": \"U\",\n" + " \"host\": \"0.0.0.0\",\n" +
" \"shortId\": 123,\n" + " \"port\": 5687,\n" +
" \"lifetime\": 300,\n" + " \"binding\": \"U\",\n" +
" \"notifIfDisabled\": true,\n" + " \"lifetime\": 300,\n" +
" \"defaultMinPeriod\": 1\n" + " \"securityMode\": \"NO_SEC\",\n" +
" \"shortServerId\": 111,\n" +
" \"notifIfDisabled\": true,\n" +
" \"serverPublicKey\": \"\",\n" +
" \"defaultMinPeriod\": 1,\n" +
" \"bootstrapServerIs\": true,\n" +
" \"clientHoldOffTime\": 1,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" +
" },\n" + " },\n" +
" \"lwm2mServer\": {\n" + " {\n" +
" \"host\": \"localhost\",\n" + " \"host\": \"0.0.0.0\",\n" +
" \"port\": 5686,\n" + " \"port\": 5685,\n" +
" \"serverId\": 123,\n" + " \"binding\": \"U\",\n" +
" \"serverPublicKey\": \"\",\n" + " \"lifetime\": 300,\n" +
" \"bootstrapServerIs\": false,\n" + " \"securityMode\": \"NO_SEC\",\n" +
" \"clientHoldOffTime\": 1,\n" + " \"shortServerId\": 123,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" + " \"notifIfDisabled\": true,\n" +
" },\n" + " \"serverPublicKey\": \"\",\n" +
" \"bootstrapServer\": {\n" + " \"defaultMinPeriod\": 1,\n" +
" \"host\": \"localhost\",\n" + " \"bootstrapServerIs\": false,\n" +
" \"port\": 5687,\n" + " \"clientHoldOffTime\": 1,\n" +
" \"serverId\": 111,\n" + " \"bootstrapServerAccountTimeout\": 0\n" +
" \"securityMode\": \"NO_SEC\",\n" +
" \"serverPublicKey\": \"\",\n" +
" \"bootstrapServerIs\": true,\n" +
" \"clientHoldOffTime\": 1,\n" +
" \"bootstrapServerAccountTimeout\": 0\n" +
" }\n" + " }\n" +
" },\n" + " ],\n" +
" \"clientLwM2mSettings\": {\n" + " \"clientLwM2mSettings\": {\n" +
" \"clientOnlyObserveAfterConnect\": 1,\n" + " \"edrxCycle\": null,\n" +
" \"powerMode\": \"DRX\",\n" +
" \"fwUpdateResource\": null,\n" +
" \"fwUpdateStrategy\": 1,\n" + " \"fwUpdateStrategy\": 1,\n" +
" \"swUpdateStrategy\": 1\n" + " \"psmActivityTimer\": null,\n" +
" \"swUpdateResource\": null,\n" +
" \"swUpdateStrategy\": 1,\n" +
" \"pagingTransmissionWindow\": null,\n" +
" \"clientOnlyObserveAfterConnect\": 1\n" +
" }\n" + " }\n" +
"}"; "}";
createDeviceProfile(RPC_TRANSPORT_CONFIGURATION); createDeviceProfile(RPC_TRANSPORT_CONFIGURATION);

2
dao/src/main/java/org/thingsboard/server/dao/device/DeviceCredentialsServiceImpl.java

@ -89,7 +89,7 @@ public class DeviceCredentialsServiceImpl extends AbstractEntityService implemen
private DeviceCredentials saveOrUpdate(TenantId tenantId, DeviceCredentials deviceCredentials) { private DeviceCredentials saveOrUpdate(TenantId tenantId, DeviceCredentials deviceCredentials) {
if (deviceCredentials.getCredentialsType() == null) { if (deviceCredentials.getCredentialsType() == null) {
throw new DataValidationException("Device credentials type must be specified"); throw new DataValidationException("Device credentials type should be specified");
} }
formatCredentials(deviceCredentials); formatCredentials(deviceCredentials);
log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials); log.trace("Executing updateDeviceCredentials [{}]", deviceCredentials);

29
dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java

@ -46,6 +46,7 @@ import org.thingsboard.server.common.data.DeviceProfileType;
import org.thingsboard.server.common.data.DeviceTransportType; import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.OtaPackage; import org.thingsboard.server.common.data.OtaPackage;
import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode;
import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration;
import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration;
import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration; import org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration;
@ -59,6 +60,7 @@ import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTrans
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration;
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.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential;
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential; import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential;
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential; import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential;
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential; import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential;
@ -418,6 +420,7 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
} }
} else if (transportConfiguration instanceof Lwm2mDeviceProfileTransportConfiguration) { } else if (transportConfiguration instanceof Lwm2mDeviceProfileTransportConfiguration) {
List<LwM2MBootstrapServerCredential> lwM2MBootstrapServersConfigurations = ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).getBootstrap(); List<LwM2MBootstrapServerCredential> lwM2MBootstrapServersConfigurations = ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).getBootstrap();
validateLwm2mServersConfigOfBootstrapForClient(lwM2MBootstrapServersConfigurations);
for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) { for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) {
validateLwm2mServersCredentialOfBootstrapForClient(bootstrapServerCredential); validateLwm2mServersCredentialOfBootstrapForClient(bootstrapServerCredential);
} }
@ -704,6 +707,32 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
} }
} }
private void validateLwm2mServersConfigOfBootstrapForClient(List<LwM2MBootstrapServerCredential> lwM2MBootstrapServersConfigurations) {
Set <String> uris = new HashSet<>();
for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) {
AbstractLwM2MBootstrapServerCredential serverConfig = (AbstractLwM2MBootstrapServerCredential) bootstrapServerCredential;
String server = serverConfig.isBootstrapServerIs() ? "Bootstrap Server" : "LwM2M Server" + " shortServerId: " + serverConfig.getShortServerId() + ":";
if (serverConfig.getShortServerId() < 1 || serverConfig.getShortServerId() > 65534) {
throw new DeviceCredentialsValidationException(server + " ShortServerId must not be less than 1 and more than 65534!");
}
String uri = serverConfig.getHost() + ":" + serverConfig.getPort();
if (!uris.add(uri)){
throw new DeviceCredentialsValidationException(server + " \"Host + port\" value = " + uri + ". This value must be a unique value for all servers!");
};
Integer port;
if (LwM2MSecurityMode.NO_SEC.equals(serverConfig.getSecurityMode())) {
port = serverConfig.isBootstrapServerIs() ? 5687 : 5685;
}
else {
port = serverConfig.isBootstrapServerIs() ? 5688 : 5686;
}
if (serverConfig.getPort() == null || serverConfig.getPort().intValue() != port) {
throw new DeviceCredentialsValidationException(server + " \"Port\" value = " + serverConfig.getPort() + ". This value for security " + serverConfig.getSecurityMode().name() + " must be " + port + "!");
}
}
}
private void validateLwm2mServersCredentialOfBootstrapForClient(LwM2MBootstrapServerCredential bootstrapServerConfig) { private void validateLwm2mServersCredentialOfBootstrapForClient(LwM2MBootstrapServerCredential bootstrapServerConfig) {
String server; String server;
switch (bootstrapServerConfig.getSecurityMode()) { switch (bootstrapServerConfig.getSecurityMode()) {

Loading…
Cancel
Save