Search in sources :

Example 11 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testFirmwareUpdateByObject5.

@Test
public void testFirmwareUpdateByObject5() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS_OTA, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA5, false, null);
    device.setFirmwareId(createFirmware().getId());
    final Device savedDevice = doPost("/api/device", device, Device.class);
    Thread.sleep(1000);
    assertThat(savedDevice).as("saved device").isNotNull();
    assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
    final List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
    List<TsKvEntry> ts = await("await on timeseries").atMost(30, TimeUnit.SECONDS).until(() -> toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
    })), hasSize(expectedStatuses.size()));
    List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    Assert.assertEquals(expectedStatuses, statuses);
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Device(org.thingsboard.server.common.data.Device) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Example 12 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testSoftwareUpdateByObject9.

/**
 * This is the example how to use the AWAITILITY instead Thread.sleep()
 * Test will finish as fast as possible, but will await until TIMEOUT if a build machine is busy or slow
 * Check the detailed log output to learn how Awaitility polling the API and when exactly expected result appears
 */
@Test
public void testSoftwareUpdateByObject9() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS_OTA, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA9));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA9);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA9, false, null);
    Thread.sleep(1000);
    device.setSoftwareId(createSoftware().getId());
    // sync call
    final Device savedDevice = doPost("/api/device", device, Device.class);
    Thread.sleep(1000);
    assertThat(savedDevice).as("saved device").isNotNull();
    assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
    final List<OtaPackageUpdateStatus> expectedStatuses = List.of(QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED);
    log.warn("AWAIT atMost {} SECONDS on timeseries List<TsKvEntry> by API with list size {}...", TIMEOUT, expectedStatuses.size());
    List<TsKvEntry> ts = await("await on timeseries").atMost(30, TimeUnit.SECONDS).until(() -> getSwStateTelemetryFromAPI(device.getId().getId()), hasSize(expectedStatuses.size()));
    log.warn("Got the ts: {}", ts);
    ts.sort(Comparator.comparingLong(TsKvEntry::getTs));
    log.warn("Ts ordered: {}", ts);
    ts.forEach((x) -> log.warn("ts: {        Thread.sleep(1000);} ", x));
    List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    log.warn("Converted ts to statuses: {}", statuses);
    assertThat(statuses).isEqualTo(expectedStatuses);
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Device(org.thingsboard.server.common.data.Device) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Example 13 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class AbstractSecurityLwM2MIntegrationTest method basicTestConnectionBootstrapRequestTriggerBefore.

public void basicTestConnectionBootstrapRequestTriggerBefore(String clientEndpoint, String awaitAlias, LwM2MProfileBootstrapConfigType type) throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsNoSec(type));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
    this.basicTestConnectionBootstrapRequestTrigger(SECURITY_NO_SEC, deviceCredentials, COAP_CONFIG, clientEndpoint, transportConfiguration, awaitAlias, expectedStatusesRegistrationLwm2mSuccess, expectedStatusesRegistrationBsSuccess, false, SECURITY_NO_SEC_BS);
}
Also used : LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)

Example 14 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class PskLwm2mIntegrationTest method testWithPskConnectBsSuccess_UpdateTwoSectionsBootstrapAndLm2m_ConnectLwm2mSuccess.

// Bootstrap + Lwm2m
@Test
public void testWithPskConnectBsSuccess_UpdateTwoSectionsBootstrapAndLm2m_ConnectLwm2mSuccess() throws Exception {
    String clientEndpoint = CLIENT_ENDPOINT_PSK_BS;
    String identity = CLIENT_PSK_IDENTITY_BS;
    String keyPsk = CLIENT_PSK_KEY;
    PSKClientCredential clientCredentials = new PSKClientCredential();
    clientCredentials.setEndpoint(clientEndpoint);
    clientCredentials.setIdentity(identity);
    clientCredentials.setKey(keyPsk);
    Security securityBs = pskBootstrap(SECURE_URI_BS, identity.getBytes(StandardCharsets.UTF_8), Hex.decodeHex(keyPsk.toCharArray()));
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, BOTH));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false);
    this.basicTestConnection(securityBs, deviceCredentials, COAP_CONFIG_BS, clientEndpoint, transportConfiguration, "await on client state (PskBS two section)", expectedStatusesRegistrationBsSuccess, true, ON_REGISTRATION_SUCCESS, true);
}
Also used : LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) PSKClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential) Security(org.eclipse.leshan.client.object.Security) Test(org.junit.Test) AbstractSecurityLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)

Example 15 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class PskLwm2mIntegrationTest method testWithPskConnectLwm2mSuccess.

// Lwm2m only
@Test
public void testWithPskConnectLwm2mSuccess() 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(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false);
    this.basicTestConnection(security, deviceCredentials, COAP_CONFIG, clientEndpoint, transportConfiguration, "await on client state (Psk_Lwm2m)", expectedStatusesRegistrationLwm2mSuccess, false, ON_REGISTRATION_SUCCESS, true);
}
Also used : LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) PSKClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential) Security(org.eclipse.leshan.client.object.Security) Test(org.junit.Test) AbstractSecurityLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)

Aggregations

LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)25 Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)19 Test (org.junit.Test)17 AbstractSecurityLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)14 PrivateKey (java.security.PrivateKey)10 X509Certificate (java.security.cert.X509Certificate)10 Security (org.eclipse.leshan.client.object.Security)8 X509ClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredential)7 Device (org.thingsboard.server.common.data.Device)6 MvcResult (org.springframework.test.web.servlet.MvcResult)5 RPKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential)4 PSKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential)3 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)3 OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)3 AbstractOtaLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)3 LwM2MBootstrapClientCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials)2 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 LwM2MClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredential)1