Lwm2m test fix bug device credential
This commit is contained in:
parent
9e9a8238db
commit
2d9448900f
@ -30,8 +30,11 @@ 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.ResourceType;
|
import org.thingsboard.server.common.data.ResourceType;
|
||||||
import org.thingsboard.server.common.data.TbResource;
|
import org.thingsboard.server.common.data.TbResource;
|
||||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapCredentials;
|
||||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredentials;
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredentials;
|
||||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials;
|
||||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredentials;
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredentials;
|
||||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecServerCredentials;
|
||||||
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
|
||||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
||||||
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
|
||||||
@ -267,9 +270,15 @@ public abstract class AbstractRpcLwM2MIntegrationTest extends AbstractWebsocketT
|
|||||||
doGet("/api/device/" + device.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
doGet("/api/device/" + device.getId().getId().toString() + "/credentials", DeviceCredentials.class);
|
||||||
Assert.assertEquals(device.getId(), deviceCredentials.getDeviceId());
|
Assert.assertEquals(device.getId(), deviceCredentials.getDeviceId());
|
||||||
deviceCredentials.setCredentialsType(DeviceCredentialsType.LWM2M_CREDENTIALS);
|
deviceCredentials.setCredentialsType(DeviceCredentialsType.LWM2M_CREDENTIALS);
|
||||||
LwM2MCredentials credentials = new LwM2MCredentials();
|
|
||||||
|
LwM2MDeviceCredentials credentials = new LwM2MDeviceCredentials();
|
||||||
credentials.setClient(clientCredentials);
|
credentials.setClient(clientCredentials);
|
||||||
credentials.setBootstrap(createBootstrapConfig());
|
LwM2MBootstrapCredentials defaultBootstrapCredentials = new LwM2MBootstrapCredentials();
|
||||||
|
NoSecServerCredentials serverCredentials = new NoSecServerCredentials();
|
||||||
|
defaultBootstrapCredentials.setBootstrapServer(serverCredentials);
|
||||||
|
defaultBootstrapCredentials.setLwm2mServer(serverCredentials);
|
||||||
|
|
||||||
|
credentials.setBootstrap(defaultBootstrapCredentials);
|
||||||
deviceCredentials.setCredentialsValue(JacksonUtil.toString(credentials));
|
deviceCredentials.setCredentialsValue(JacksonUtil.toString(credentials));
|
||||||
doPost("/api/device/credentials", deviceCredentials).andExpect(status().isOk());
|
doPost("/api/device/credentials", deviceCredentials).andExpect(status().isOk());
|
||||||
return device;
|
return device;
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2016-2021 The Thingsboard Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.thingsboard.server.transport.lwm2m.security.sql;
|
||||||
|
|
||||||
|
import org.eclipse.leshan.client.object.Security;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredentials;
|
||||||
|
import org.thingsboard.server.common.transport.util.SslUtil;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.security.AbstractLwM2MIntegrationTest;
|
||||||
|
|
||||||
|
import static org.eclipse.leshan.client.object.Security.x509;
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SECURE_COAP_CONFIG;
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SECURE_URI;
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SHORT_SERVER_ID;
|
||||||
|
|
||||||
|
public class X509_NoTrustLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConnectWithCertAndObserveTelemetry() throws Exception {
|
||||||
|
X509ClientCredentials credentials = new X509ClientCredentials();
|
||||||
|
credentials.setEndpoint(ENDPOINT);
|
||||||
|
credentials.setCert(SslUtil.getCertificateString(clientX509CertNotTrusted));
|
||||||
|
Security security = x509(SECURE_URI,
|
||||||
|
123,
|
||||||
|
clientX509CertNotTrusted.getEncoded(),
|
||||||
|
clientPrivateKeyFromCert.getEncoded(),
|
||||||
|
serverX509Cert.getEncoded());
|
||||||
|
super.basicTestConnectionObserveTelemetry(security, credentials, SECURE_COAP_CONFIG, ENDPOINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -25,7 +25,7 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SECURE_COAP
|
|||||||
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SECURE_URI;
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SECURE_URI;
|
||||||
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SHORT_SERVER_ID;
|
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.SHORT_SERVER_ID;
|
||||||
|
|
||||||
public class X509LwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
public class X509_TrustLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectAndObserveTelemetry() throws Exception {
|
public void testConnectAndObserveTelemetry() throws Exception {
|
||||||
@ -39,18 +39,4 @@ public class X509LwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
|
|||||||
super.basicTestConnectionObserveTelemetry(security, credentials, SECURE_COAP_CONFIG, ENDPOINT);
|
super.basicTestConnectionObserveTelemetry(security, credentials, SECURE_COAP_CONFIG, ENDPOINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Ignore //See LwM2mClientContextImpl.unregister
|
|
||||||
// @Test
|
|
||||||
// public void testConnectWithCertAndObserveTelemetry() throws Exception {
|
|
||||||
// X509ClientCredentials credentials = new X509ClientCredentials();
|
|
||||||
// credentials.setEndpoint(ENDPOINT);
|
|
||||||
// credentials.setCert(SslUtil.getCertificateString(clientX509CertNotTrusted));
|
|
||||||
// Security security = x509(SECURE_URI,
|
|
||||||
// 123,
|
|
||||||
// clientX509CertNotTrusted.getEncoded(),
|
|
||||||
// clientPrivateKeyFromCert.getEncoded(),
|
|
||||||
// serverX509Cert.getEncoded());
|
|
||||||
// super.basicTestConnectionObserveTelemetry(security, credentials, SECURE_COAP_CONFIG, ENDPOINT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user