From 0aa6c36c47d3e7192fca9a6040fdbab4e7c13905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Mon, 13 Jan 2025 16:47:55 +0100 Subject: [PATCH] FIX 3001_mqtt_alarms removing dependency on external MQTT broker --- .github/workflows/functional.yml | 3 ++ .../mqtt_alarms_log_summary.test | 16 ++++--- .../mqtt_alarms_raise_and_release.test | 46 +++++++++--------- .../mqtt_alarms_raise_repeat_and_release.test | 48 ++++++++++--------- .../mosquitto_conf_for_tests.conf | 2 + test/functionalTest/mosquitto_passwd | 1 + 6 files changed, 65 insertions(+), 51 deletions(-) create mode 100644 test/functionalTest/mosquitto_conf_for_tests.conf create mode 100644 test/functionalTest/mosquitto_passwd diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index b8b4bcb597..a08bd0f2e2 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -32,6 +32,9 @@ jobs: image: eclipse-mosquitto:1.6.15 ports: - 1883:1883 + volumes: + - ./test/functionalTest/mosquitto_conf_for_tests.conf:/mosquitto/config/mosquitto.conf + - ./test/functionalTest/mosquitto_passwd:/mosquitto/config/passwd mosquitto-extra: # Needed by MQTT notification tests (multi broker) diff --git a/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_log_summary.test b/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_log_summary.test index 8f85a26087..45b8d25f08 100644 --- a/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_log_summary.test +++ b/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_log_summary.test @@ -32,8 +32,12 @@ brokerStart CB 0 IPv4 -logSummary 5 --SHELL-- # -# FIXME: this test relies on an external service (mqtt.flespi.io) which we don't control -# It would be better to use a MQTT broker running by us (docker?) +# This test requires a MQTT broker with authentication enabled. This may help: +# +# sudo cp /path/to/test/functionalTest/mosquitto_conf_for_tests.conf /etc/mosquitto/conf.d/local.conf +# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1 +# sudo chmod 640 /etc/mosquitto/passwd +# sudo chown root:mosquitto /etc/mosquitto/passwd # # 01. Sleep 6 and see 0-0 raised and 0-0 released # 02. Create MQTT sub with wrong user/pass @@ -67,8 +71,8 @@ payload='{ }, "notification": { "mqtt": { - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user", + "url": "mqtt://localhost:1883", + "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } @@ -118,8 +122,8 @@ echo "========================================" payload='{ "notification": { "mqtt": { - "url": "mqtt://mqtt.flespi.io:1883", - "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", + "url": "mqtt://localhost:1883", + "user": "user1", "passwd": "xxxx", "topic": "sub1" } diff --git a/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_and_release.test b/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_and_release.test index f531b4247f..886dc1f1f8 100644 --- a/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_and_release.test +++ b/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_and_release.test @@ -30,10 +30,12 @@ brokerStart CB 0 IPV4 --SHELL-- # -# FIXME: this test relies on an external service (mqtt.flespi.io) which we don't control -# It would be better to use a MQTT broker running by us (docker?) -# Given the MQTT broker is a remote system in the Internet, we have to wait at some points -# so subscription status and logs get consolidated before checking it +# This test requires a MQTT broker with authentication enabled. This may help: +# +# sudo cp /path/to/test/functionalTest/mosquitto_conf_for_tests.conf /etc/mosquitto/conf.d/local.conf +# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1 +# sudo chmod 640 /etc/mosquitto/passwd +# sudo chown root:mosquitto /etc/mosquitto/passwd # # 01. Create MQTT sub with wrong user/pass # 02. Upsert to trigger first MQTT notification, which fails and raises alarm @@ -59,8 +61,8 @@ payload='{ }, "notification": { "mqtt": { - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user", + "url": "mqtt://localhost:1883", + "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } @@ -125,8 +127,8 @@ echo "========================================" payload='{ "notification": { "mqtt": { - "url": "mqtt://mqtt.flespi.io:1883", - "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", + "url": "mqtt://localhost:1883", + "user": "user1", "passwd": "xxxx", "topic": "sub1" } @@ -193,7 +195,7 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 482 +Content-Length: 485 [ { @@ -210,8 +212,8 @@ Content-Length: 482 "qos": 0, "retain": false, "topic": "sub1", - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user" + "url": "mqtt://localhost:1883", + "user": "user_noexist" }, "onlyChangedAttrs": false, "timesSent": 1 @@ -248,7 +250,7 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 482 +Content-Length: 485 [ { @@ -265,8 +267,8 @@ Content-Length: 482 "qos": 0, "retain": false, "topic": "sub1", - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user" + "url": "mqtt://localhost:1883", + "user": "user_noexist" }, "onlyChangedAttrs": false, "timesSent": 2 @@ -311,7 +313,7 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 566 +Content-Length: 502 [ { @@ -328,8 +330,8 @@ Content-Length: 566 "qos": 0, "retain": false, "topic": "sub1", - "url": "mqtt://mqtt.flespi.io:1883", - "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ" + "url": "mqtt://localhost:1883", + "user": "user1" }, "onlyChangedAttrs": false, "timesSent": 3 @@ -354,16 +356,16 @@ Content-Length: 566 09. Check logs and see 1 raised alarm and 1 released alarm ========================================================== #SORT_START -Request received: POST /v2/subscriptions, request payload (181 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "user", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201 +Request received: POST /v2/subscriptions, request payload (184 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201 Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204 -Raising alarm MqttConnectionError mqtt.flespi.io:1883: Connection Refused: bad user name or password. +Raising alarm MqttConnectionError localhost:1883: Connection Refused: not authorised. Request received: GET /v2/subscriptions, response code: 200 Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204 Request received: GET /v2/subscriptions, response code: 200 -Request received: PATCH /v2/subscriptions/SUB_ID, request payload (182 bytes): { "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204 +Request received: PATCH /v2/subscriptions/SUB_ID, request payload (118 bytes): { "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user1", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204 Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204 -Releasing alarm MqttConnectionError mqtt.flespi.io:1883 -MQTT Notif delivered (subId: SUB_ID): broker: mqtt.flespi.io:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]} +Releasing alarm MqttConnectionError localhost:1883 +MQTT Notif delivered (subId: SUB_ID): broker: localhost:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]} Request received: GET /v2/subscriptions, response code: 200 #SORT_END diff --git a/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_repeat_and_release.test b/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_repeat_and_release.test index c60bf280d5..763dea67d7 100644 --- a/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_repeat_and_release.test +++ b/test/functionalTest/cases/3001_mqtt_alarms/mqtt_alarms_raise_repeat_and_release.test @@ -30,10 +30,12 @@ brokerStart CB 0 IPV4 -relogAlarms --SHELL-- # -# FIXME: this test relies on an external service (mqtt.flespi.io) which we don't control -# It would be better to use a MQTT broker running by us (docker?) -# Given the MQTT broker is a remote system in the Internet, we have to wait at some points -# so subscription status and logs get consolidated before checking it +# This test requires a MQTT broker with authentication enabled. This may help: +# +# sudo cp /path/to/test/functionalTest/mosquitto_conf_for_tests.conf /etc/mosquitto/conf.d/local.conf +# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1 +# sudo chmod 640 /etc/mosquitto/passwd +# sudo chown root:mosquitto /etc/mosquitto/passwd # # 01. Create MQTT sub with wrong user/pass # 02. Upsert to trigger first MQTT notification, which fails and raises alarm @@ -59,8 +61,8 @@ payload='{ }, "notification": { "mqtt": { - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user", + "url": "mqtt://localhost:1883", + "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } @@ -125,8 +127,8 @@ echo "========================================" payload='{ "notification": { "mqtt": { - "url": "mqtt://mqtt.flespi.io:1883", - "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", + "url": "mqtt://localhost:1883", + "user": "user1", "passwd": "xxxx", "topic": "sub1" } @@ -193,7 +195,7 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 482 +Content-Length: 485 [ { @@ -210,8 +212,8 @@ Content-Length: 482 "qos": 0, "retain": false, "topic": "sub1", - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user" + "url": "mqtt://localhost:1883", + "user": "user_noexist" }, "onlyChangedAttrs": false, "timesSent": 1 @@ -248,7 +250,7 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 482 +Content-Length: 485 [ { @@ -265,8 +267,8 @@ Content-Length: 482 "qos": 0, "retain": false, "topic": "sub1", - "url": "mqtt://mqtt.flespi.io:1883", - "user": "user" + "url": "mqtt://localhost:1883", + "user": "user_noexist" }, "onlyChangedAttrs": false, "timesSent": 2 @@ -311,7 +313,7 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 566 +Content-Length: 502 [ { @@ -328,8 +330,8 @@ Content-Length: 566 "qos": 0, "retain": false, "topic": "sub1", - "url": "mqtt://mqtt.flespi.io:1883", - "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ" + "url": "mqtt://localhost:1883", + "user": "user1" }, "onlyChangedAttrs": false, "timesSent": 3 @@ -354,17 +356,17 @@ Content-Length: 566 09. Check logs and see 1 raised alarm, 1 repeat alarm and 1 released alarm ========================================================================== #SORT_START -Request received: POST /v2/subscriptions, request payload (181 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "user", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201 +Request received: POST /v2/subscriptions, request payload (184 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201 Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204 -Raising alarm MqttConnectionError mqtt.flespi.io:1883: Connection Refused: bad user name or password. +Raising alarm MqttConnectionError localhost:1883: Connection Refused: not authorised. Request received: GET /v2/subscriptions, response code: 200 Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204 Request received: GET /v2/subscriptions, response code: 200 -Repeated MqttConnectionError mqtt.flespi.io:1883: Connection Refused: bad user name or password. -Request received: PATCH /v2/subscriptions/SUB_ID, request payload (182 bytes): { "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204 +Repeated MqttConnectionError localhost:1883: Connection Refused: not authorised. +Request received: PATCH /v2/subscriptions/SUB_ID, request payload (118 bytes): { "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user1", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204 Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204 -Releasing alarm MqttConnectionError mqtt.flespi.io:1883 -MQTT Notif delivered (subId: SUB_ID): broker: mqtt.flespi.io:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]} +Releasing alarm MqttConnectionError localhost:1883 +MQTT Notif delivered (subId: SUB_ID): broker: localhost:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]} Request received: GET /v2/subscriptions, response code: 200 #SORT_END diff --git a/test/functionalTest/mosquitto_conf_for_tests.conf b/test/functionalTest/mosquitto_conf_for_tests.conf new file mode 100644 index 0000000000..430b996c59 --- /dev/null +++ b/test/functionalTest/mosquitto_conf_for_tests.conf @@ -0,0 +1,2 @@ +password_file /etc/mosquitto/passwd +allow_anonymous true diff --git a/test/functionalTest/mosquitto_passwd b/test/functionalTest/mosquitto_passwd new file mode 100644 index 0000000000..eb65166dae --- /dev/null +++ b/test/functionalTest/mosquitto_passwd @@ -0,0 +1 @@ +user1:$7$101$eqgU7wUvh4Y3VQAm$ovEPI43qOwAskK5M+OFmNJAoXtLRx5GI2tBjTX4AOf3ZTB79IRv1CMgbHrPnKY+/K/RKMm2i/XFp9syteeOCvg==