renamed DeviceConnectivityUtil const
This commit is contained in:
parent
c57ec93e6a
commit
0079c6d3d0
@ -50,7 +50,7 @@ import static org.thingsboard.server.controller.ControllerConstants.DEVICE_ID_PA
|
||||
import static org.thingsboard.server.controller.ControllerConstants.PROTOCOL;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.PROTOCOL_PARAM_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.CA_FILE_PEM;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.CA_ROOT_CERT_PEM;
|
||||
|
||||
@RestController
|
||||
@TbCoreComponent
|
||||
@ -129,8 +129,8 @@ public class DeviceConnectivityController extends BaseController {
|
||||
checkNotNull(deviceConnectivityService.getPemCertFile(protocol), protocol + " pem cert file is not found!");
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + CA_FILE_PEM)
|
||||
.header("x-filename", CA_FILE_PEM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + CA_ROOT_CERT_PEM)
|
||||
.header("x-filename", CA_ROOT_CERT_PEM)
|
||||
.contentLength(pemCert.contentLength())
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(pemCert);
|
||||
|
||||
@ -1179,8 +1179,8 @@ device:
|
||||
host: "${DEVICE_CONNECTIVITY_MQTTS_HOST:}"
|
||||
# Port of mqtt transport service. If empty default port for mqtts will be used.
|
||||
port: "${DEVICE_CONNECTIVITY_MQTTS_PORT:8883}"
|
||||
# Path to the mqtt certificate authority file
|
||||
pem_cert_file: "${DEVICE_CONNECTIVITY_MQTT_SSL_PEM_CERT:cafile.pem}"
|
||||
# Path to the MQTT CA root certificate file
|
||||
pem_cert_file: "${DEVICE_CONNECTIVITY_MQTTS_CA_ROOT_CERT:cafile.pem}"
|
||||
coap:
|
||||
# If true coap command will be included to the list of all test commands using DEVICE_CONNECTIVITY_COAP_HOST and DEVICE_CONNECTIVITY_COAP_PORT.
|
||||
enabled: "${DEVICE_CONNECTIVITY_COAP_ENABLED:true}"
|
||||
|
||||
@ -62,14 +62,14 @@ import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.HTTP;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.HTTPS;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.MQTT;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.MQTTS;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.CA_FILE_PEM;
|
||||
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.CA_ROOT_CERT_PEM;
|
||||
|
||||
@TestPropertySource(properties = {
|
||||
"device.connectivity.https.enabled=true",
|
||||
"device.connectivity.http.port=8080",
|
||||
"device.connectivity.https.port=444",
|
||||
"device.connectivity.mqtts.enabled=true",
|
||||
"device.connectivity.mqtts.pem_cert_file=/tmp/" + CA_FILE_PEM,
|
||||
"device.connectivity.mqtts.pem_cert_file=/tmp/" + CA_ROOT_CERT_PEM,
|
||||
"device.connectivity.coaps.enabled=true",
|
||||
})
|
||||
@ContextConfiguration(classes = {DeviceConnectivityControllerTest.Config.class})
|
||||
@ -202,8 +202,8 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
assertThat(mqttCommands.get(MQTT).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 -h localhost -p 1883 -t v1/devices/me/telemetry " +
|
||||
"-u %s -m \"{temperature:25}\"",
|
||||
credentials.getCredentialsId()));
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o cafile.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile cafile.pem -h localhost -p 8883 " +
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 " +
|
||||
"-t v1/devices/me/telemetry -u %s -m \"{temperature:25}\"", credentials.getCredentialsId()));
|
||||
|
||||
JsonNode dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
@ -211,8 +211,8 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
" -p 1883 -t v1/devices/me/telemetry -u %s -m \"{temperature:25}\"",
|
||||
credentials.getCredentialsId()));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o cafile.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile cafile.pem -h localhost -p 8883 -t v1/devices/me/telemetry -u %s -m \"{temperature:25}\"\"",
|
||||
"/bin/sh -c \"curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 -t v1/devices/me/telemetry -u %s -m \"{temperature:25}\"\"",
|
||||
credentials.getCredentialsId()));
|
||||
|
||||
JsonNode linuxCoapCommands = commands.get(COAP);
|
||||
@ -240,8 +240,8 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
JsonNode mqttCommands = commands.get(MQTT);
|
||||
assertThat(mqttCommands.get(MQTT).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 -h localhost -p 1883 -t %s " +
|
||||
"-u %s -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o cafile.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile cafile.pem -h localhost -p 8883 " +
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 " +
|
||||
"-t %s -u %s -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
|
||||
JsonNode dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
@ -249,8 +249,8 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
" -p 1883 -t %s -u %s -m \"{temperature:25}\"",
|
||||
DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o cafile.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile cafile.pem -h localhost -p 8883 -t %s -u %s -m \"{temperature:25}\"\"",
|
||||
"/bin/sh -c \"curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 -t %s -u %s -m \"{temperature:25}\"\"",
|
||||
DEVICE_TELEMETRY_TOPIC, credentials.getCredentialsId()));
|
||||
}
|
||||
|
||||
@ -284,8 +284,8 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
JsonNode mqttCommands = commands.get(MQTT);
|
||||
assertThat(mqttCommands.get(MQTT).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 -h localhost -p 1883 -t %s " +
|
||||
"-i %s -u %s -P %s -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o cafile.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile cafile.pem -h localhost -p 8883 " +
|
||||
assertThat(mqttCommands.get(MQTTS).get(0).asText()).isEqualTo("curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download");
|
||||
assertThat(mqttCommands.get(MQTTS).get(1).asText()).isEqualTo(String.format("mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 " +
|
||||
"-t %s -i %s -u %s -P %s -m \"{temperature:25}\"", DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
|
||||
JsonNode dockerMqttCommands = commands.get(MQTT).get(DOCKER);
|
||||
@ -293,8 +293,8 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
" -p 1883 -t %s -i %s -u %s -P %s -m \"{temperature:25}\"",
|
||||
DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
assertThat(dockerMqttCommands.get(MQTTS).asText()).isEqualTo(String.format("docker run --rm -it thingsboard/mosquitto-clients " +
|
||||
"/bin/sh -c \"curl -f -S -o cafile.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile cafile.pem -h localhost -p 8883 -t %s -i %s -u %s -P %s -m \"{temperature:25}\"\"",
|
||||
"/bin/sh -c \"curl -f -S -o ca-root.pem http://localhost:80/api/device-connectivity/mqtts/certificate/download && " +
|
||||
"mosquitto_pub -d -q 1 --cafile ca-root.pem -h localhost -p 8883 -t %s -i %s -u %s -P %s -m \"{temperature:25}\"\"",
|
||||
DEVICE_TELEMETRY_TOPIC, clientId, userName, password));
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testDownloadMqttCert() throws Exception {
|
||||
Path path = Files.createFile(Path.of("/tmp/" + CA_FILE_PEM));
|
||||
Path path = Files.createFile(Path.of("/tmp/" + CA_ROOT_CERT_PEM));
|
||||
Files.writeString(path, CERT);
|
||||
|
||||
try {
|
||||
@ -382,7 +382,7 @@ public class DeviceConnectivityControllerTest extends AbstractControllerTest {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testDownloadMqttCertFromFileWithPrivateKey() throws Exception {
|
||||
Path path = Files.createFile(Path.of("/tmp/" + CA_FILE_PEM));
|
||||
Path path = Files.createFile(Path.of("/tmp/" + CA_ROOT_CERT_PEM));
|
||||
Files.writeString(path, CERT + P_KEY);
|
||||
|
||||
try {
|
||||
|
||||
@ -31,7 +31,7 @@ public class DeviceConnectivityUtil {
|
||||
public static final String MQTTS = "mqtts";
|
||||
public static final String COAP = "coap";
|
||||
public static final String COAPS = "coaps";
|
||||
public static final String CA_FILE_PEM = "cafile.pem";
|
||||
public static final String CA_ROOT_CERT_PEM = "ca-root.pem";
|
||||
public static final String CHECK_DOCUMENTATION = "Check documentation";
|
||||
public static final String JSON_EXAMPLE_PAYLOAD = "\"{temperature:25}\"";
|
||||
public static final String DOCKER_RUN = "docker run --rm -it ";
|
||||
@ -47,7 +47,7 @@ public class DeviceConnectivityUtil {
|
||||
public static String getMqttPublishCommand(String protocol, String host, String port, String deviceTelemetryTopic, DeviceCredentials deviceCredentials) {
|
||||
StringBuilder command = new StringBuilder("mosquitto_pub -d -q 1");
|
||||
if (MQTTS.equals(protocol)) {
|
||||
command.append(" --cafile ").append(CA_FILE_PEM);
|
||||
command.append(" --cafile ").append(CA_ROOT_CERT_PEM);
|
||||
}
|
||||
command.append(" -h ").append(host).append(port == null ? "" : " -p " + port);
|
||||
command.append(" -t ").append(deviceTelemetryTopic);
|
||||
@ -151,7 +151,7 @@ public class DeviceConnectivityUtil {
|
||||
}
|
||||
|
||||
public static String getCurlPemCertCommand(String baseUrl, String protocol) {
|
||||
return String.format("curl -f -S -o %s %s/api/device-connectivity/%s/certificate/download", CA_FILE_PEM, baseUrl, protocol);
|
||||
return String.format("curl -f -S -o %s %s/api/device-connectivity/%s/certificate/download", CA_ROOT_CERT_PEM, baseUrl, protocol);
|
||||
}
|
||||
|
||||
public static String getCoapPublishCommand(String protocol, String host, String port, DeviceCredentials deviceCredentials) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user