From 37e730a75fe07647c0da37b38af4dfe812e1bcb3 Mon Sep 17 00:00:00 2001 From: Sergey Matvienko Date: Tue, 30 Apr 2024 10:02:40 +0200 Subject: [PATCH] TbCoapDtlsSettingsTest --- common/coap-server/pom.xml | 10 +++ .../server/coapserver/TbCoapDtlsSettings.java | 2 + .../coapserver/TbCoapDtlsSettingsTest.java | 62 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java diff --git a/common/coap-server/pom.xml b/common/coap-server/pom.xml index 675f030305..59640b586d 100644 --- a/common/coap-server/pom.xml +++ b/common/coap-server/pom.xml @@ -67,6 +67,16 @@ org.eclipse.californium scandium + + org.springframework.boot + spring-boot-starter-test + test + + + org.awaitility + awaitility + test + diff --git a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java index 9c6e606af5..c2cf1a4603 100644 --- a/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java +++ b/common/coap-server/src/main/java/org/thingsboard/server/coapserver/TbCoapDtlsSettings.java @@ -15,6 +15,7 @@ */ package org.thingsboard.server.coapserver; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.eclipse.californium.elements.config.Configuration; import org.eclipse.californium.elements.util.SslContextUtil; @@ -47,6 +48,7 @@ import static org.eclipse.californium.scandium.config.DtlsConfig.DTLS_RETRANSMIS import static org.eclipse.californium.scandium.config.DtlsConfig.DTLS_ROLE; import static org.eclipse.californium.scandium.config.DtlsConfig.DtlsRole.SERVER_ONLY; +@Getter @Slf4j @ConditionalOnProperty(prefix = "transport.coap.dtls", value = "enabled", havingValue = "true", matchIfMissing = false) @Component diff --git a/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java b/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java new file mode 100644 index 0000000000..72f5b964ae --- /dev/null +++ b/common/coap-server/src/test/java/org/thingsboard/server/coapserver/TbCoapDtlsSettingsTest.java @@ -0,0 +1,62 @@ +/** + * Copyright © 2016-2024 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.coapserver; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.TestPropertySource; +import org.thingsboard.server.common.transport.TransportService; +import org.thingsboard.server.common.transport.config.ssl.SslCredentialsConfig; +import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = TbCoapDtlsSettings.class) +@TestPropertySource(properties = { + "transport.coap.dtls.enabled=true", + "transport.coap.dtls.bind_address=192.168.1.1", + "transport.coap.dtls.bind_port=1234", + "transport.coap.dtls.retransmission_timeout=100", + "transport.coap.dtls.connection_id_length=500", + "transport.coap.dtls.x509.skip_validity_check_for_client_cert=true", + "transport.coap.dtls.x509.dtls_session_inactivity_timeout=1000", + "transport.coap.dtls.x509.dtls_session_report_timeout=3000", +}) +class TbCoapDtlsSettingsTest { + + @Autowired + TbCoapDtlsSettings coapDtlsSettings; + @MockBean + SslCredentialsConfig sslCredentialsConfig; + @MockBean + private TransportService transportService; + @MockBean + private TbServiceInfoProvider serviceInfoProvider; + + @Test + public void testCoapDtlsProperties() { + assertThat(coapDtlsSettings).as("bean created").isNotNull(); + assertThat(coapDtlsSettings.getHost()).as("host").isEqualTo("192.168.1.1"); + assertThat(coapDtlsSettings.getPort()).as("port").isEqualTo(1234); + assertThat(coapDtlsSettings.getDtlsRetransmissionTimeout()).as("retransmission_timeout").isEqualTo(100); + assertThat(coapDtlsSettings.isSkipValidityCheckForClientCert()).as("skip_validity_check_for_client_cert").isTrue(); + assertThat(coapDtlsSettings.getDtlsSessionInactivityTimeout()).as("dtls_session_inactivity_timeout").isEqualTo(1000); + assertThat(coapDtlsSettings.getDtlsSessionReportTimeout()).as("dtls_session_report_timeout").isEqualTo(3000); + } + +}