Commit e292944210967ed5183a15e3d73601dae6abf5ae
Committed by
GitHub
Merge pull request #5231 from YevhenBondarenko/lwm2m-improvements
LwM2M tests improvements
Showing
3 changed files
with
18 additions
and
6 deletions
... | ... | @@ -36,7 +36,10 @@ import org.thingsboard.server.common.data.DeviceTransportType; |
36 | 36 | import org.thingsboard.server.common.data.OtaPackageInfo; |
37 | 37 | import org.thingsboard.server.common.data.ResourceType; |
38 | 38 | import org.thingsboard.server.common.data.TbResource; |
39 | +import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapCredentials; | |
39 | 40 | import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredentials; |
41 | +import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials; | |
42 | +import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecServerCredentials; | |
40 | 43 | import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; |
41 | 44 | import org.thingsboard.server.common.data.device.profile.DeviceProfileData; |
42 | 45 | import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration; |
... | ... | @@ -57,7 +60,6 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd; |
57 | 60 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; |
58 | 61 | import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd; |
59 | 62 | import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient; |
60 | -import org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MCredentials; | |
61 | 63 | |
62 | 64 | import java.io.IOException; |
63 | 65 | import java.io.InputStream; |
... | ... | @@ -178,6 +180,8 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest |
178 | 180 | protected static final Security SECURITY = noSec("coap://localhost:" + PORT, 123); |
179 | 181 | protected static final NetworkConfig COAP_CONFIG = new NetworkConfig().setString("COAP_PORT", Integer.toString(PORT)); |
180 | 182 | |
183 | + private final LwM2MBootstrapCredentials defaultBootstrapCredentials; | |
184 | + | |
181 | 185 | public AbstractLwM2MIntegrationTest() { |
182 | 186 | // create client credentials |
183 | 187 | try { |
... | ... | @@ -258,6 +262,13 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest |
258 | 262 | } catch (GeneralSecurityException | IOException e) { |
259 | 263 | throw new RuntimeException(e); |
260 | 264 | } |
265 | + | |
266 | + defaultBootstrapCredentials = new LwM2MBootstrapCredentials(); | |
267 | + | |
268 | + NoSecServerCredentials serverCredentials = new NoSecServerCredentials(); | |
269 | + | |
270 | + defaultBootstrapCredentials.setBootstrapServer(serverCredentials); | |
271 | + defaultBootstrapCredentials.setLwm2mServer(serverCredentials); | |
261 | 272 | } |
262 | 273 | |
263 | 274 | @Before |
... | ... | @@ -314,9 +325,10 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest |
314 | 325 | Assert.assertEquals(device.getId(), deviceCredentials.getDeviceId()); |
315 | 326 | deviceCredentials.setCredentialsType(DeviceCredentialsType.LWM2M_CREDENTIALS); |
316 | 327 | |
317 | - LwM2MCredentials credentials = new LwM2MCredentials(); | |
328 | + LwM2MDeviceCredentials credentials = new LwM2MDeviceCredentials(); | |
318 | 329 | |
319 | 330 | credentials.setClient(clientCredentials); |
331 | + credentials.setBootstrap(defaultBootstrapCredentials); | |
320 | 332 | |
321 | 333 | deviceCredentials.setCredentialsValue(JacksonUtil.toString(credentials)); |
322 | 334 | doPost("/api/device/credentials", deviceCredentials).andExpect(status().isOk()); |
... | ... | @@ -408,7 +420,7 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest |
408 | 420 | var tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("batteryLevel"); |
409 | 421 | Assert.assertEquals(42, Long.parseLong(tsValue.getValue())); |
410 | 422 | } finally { |
411 | - if(client != null) { | |
423 | + if (client != null) { | |
412 | 424 | client.destroy(); |
413 | 425 | } |
414 | 426 | } | ... | ... |
... | ... | @@ -30,7 +30,7 @@ public class PskLwm2mIntegrationTest extends AbstractLwM2MIntegrationTest { |
30 | 30 | @Test |
31 | 31 | public void testConnectWithPSKAndObserveTelemetry() throws Exception { |
32 | 32 | String pskIdentity = "SOME_PSK_ID"; |
33 | - String pskKey = "73656372657450534b"; | |
33 | + String pskKey = "73656372657450534b73656372657450"; | |
34 | 34 | PSKClientCredentials clientCredentials = new PSKClientCredentials(); |
35 | 35 | clientCredentials.setEndpoint(ENDPOINT); |
36 | 36 | clientCredentials.setKey(pskKey); | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.dao.device; |
17 | 17 | |
18 | 18 | |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | -import org.apache.commons.codec.binary.Hex; | |
20 | +import org.eclipse.leshan.core.util.Base64; | |
21 | 21 | import org.eclipse.leshan.core.util.SecurityUtil; |
22 | 22 | import org.hibernate.exception.ConstraintViolationException; |
23 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -274,7 +274,7 @@ public class DeviceCredentialsServiceImpl extends AbstractEntityService implemen |
274 | 274 | X509ClientCredentials x509CCredentials = (X509ClientCredentials) clientCredentials; |
275 | 275 | if (x509CCredentials.getCert() != null) { |
276 | 276 | try { |
277 | - SecurityUtil.certificate.decode(Hex.decodeHex(x509CCredentials.getCert().toLowerCase().toCharArray())); | |
277 | + SecurityUtil.certificate.decode(Base64.decodeBase64(x509CCredentials.getCert())); | |
278 | 278 | } catch (Exception e) { |
279 | 279 | throw new DeviceCredentialsValidationException("LwM2M client X509 certificate should be in DER-encoded X.509 format!"); |
280 | 280 | } | ... | ... |