Skip to content

Commit 89ef562

Browse files
committed
fix: c8y mapper config should use the value of c8y.mqtt as mqtt endpoint
When C8yMapperConfig is constructed from tedge config, by mistake, the http endpoint was used as the mqtt endpoint. Signed-off-by: Rina Fujino <rina.fujino.23@gmail.com>
1 parent 8f751e7 commit 89ef562

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

crates/extensions/c8y_mapper_ext/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl C8yMapperConfig {
171171
let device_topic_id = EntityTopicId::from_str(&tedge_config.mqtt.device_topic_id)?;
172172
let service = tedge_config.service.clone();
173173
let c8y_host = c8y_config.http.or_config_not_set()?.to_string();
174+
let c8y_mqtt = c8y_config.mqtt.or_config_not_set()?.to_string();
174175
let tedge_http_address = tedge_config.http.client.host.clone();
175176
let tedge_http_port = tedge_config.http.client.port;
176177
let mqtt_schema = MqttSchema::with_root(tedge_config.mqtt.topic_root.clone());
@@ -237,8 +238,8 @@ impl C8yMapperConfig {
237238
device_topic_id,
238239
device_type,
239240
service,
240-
c8y_host.clone(),
241241
c8y_host,
242+
c8y_mqtt,
242243
tedge_http_host,
243244
topics,
244245
capabilities,

crates/extensions/c8y_mapper_ext/src/operations/handlers/config_update.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,54 @@ mod tests {
138138
.await;
139139
}
140140

141+
#[tokio::test]
142+
async fn mapper_replaces_remote_url_with_proxy_url_3545() {
143+
let ttd = TempTedgeDir::new();
144+
let config = C8yMapperConfig {
145+
c8y_host: "my.custom.domain.com:443".into(),
146+
c8y_mqtt: "t12345.cumulocity.com:8883".into(),
147+
..test_mapper_config(&ttd)
148+
};
149+
let test_handle = spawn_c8y_mapper_actor_with_config(&ttd, config, true).await;
150+
let TestHandle { mqtt, .. } = test_handle;
151+
let mut mqtt = mqtt.with_timeout(TEST_TIMEOUT_MS);
152+
153+
skip_init_messages(&mut mqtt).await;
154+
155+
// Simulate c8y_DownloadConfigFile operation delivered via JSON over MQTT
156+
mqtt.send(MqttMessage::new(
157+
&C8yDeviceControlTopic::topic(&"c8y".try_into().unwrap()),
158+
json!({
159+
"id": "123456",
160+
"c8y_DownloadConfigFile": {
161+
"type": "path/config/A",
162+
"url": "https://t12345.cumulocity.com/inventory/binaries/654321"
163+
},
164+
"externalSource": {
165+
"externalId": "test-device",
166+
"type": "c8y_Serial"
167+
}
168+
})
169+
.to_string(),
170+
))
171+
.await
172+
.expect("Send failed");
173+
174+
assert_received_includes_json(
175+
&mut mqtt,
176+
[(
177+
"te/device/main///cmd/config_update/c8y-mapper-123456",
178+
json!({
179+
"status": "init",
180+
"remoteUrl": "http://127.0.0.1:8001/c8y/inventory/binaries/654321",
181+
"serverUrl": "https://t12345.cumulocity.com/inventory/binaries/654321",
182+
"type": "path/config/A",
183+
}),
184+
)],
185+
)
186+
.await;
187+
}
188+
141189
#[tokio::test]
142190
async fn mapper_converts_config_download_op_for_child_device() {
143191
let ttd = TempTedgeDir::new();

0 commit comments

Comments
 (0)