From 8fd8ad844dd147f971d8f24d7e24f3f644a8225f Mon Sep 17 00:00:00 2001 From: Rina Fujino Date: Fri, 10 Jan 2025 23:22:30 +0000 Subject: [PATCH] test: add and update regarding device.id and tedge connect * tedge connect c8y uses device.id directly. The CN from certificate is no longer used to determine device.id * tedge connect c8y returns an error if device.id mismatches the certificate's CN when auth method is certificate Signed-off-by: Rina Fujino --- .../smartrest_one/smartrest_one.robot | 6 ++++ .../tedge_connect_cn_validation.robot | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/RobotFramework/tests/tedge_connect/tedge_connect_cn_validation.robot diff --git a/tests/RobotFramework/tests/cumulocity/smartrest_one/smartrest_one.robot b/tests/RobotFramework/tests/cumulocity/smartrest_one/smartrest_one.robot index 027d988bf45..53088c72048 100644 --- a/tests/RobotFramework/tests/cumulocity/smartrest_one/smartrest_one.robot +++ b/tests/RobotFramework/tests/cumulocity/smartrest_one/smartrest_one.robot @@ -31,6 +31,12 @@ Register and Use SmartREST 1.0. Templates [Arguments] ${use_builtin_bridge} Custom Setup use_builtin_bridge=${use_builtin_bridge} + # device.id should be set by tedge config and confirm the test doesn't use certificate + Execute Command tedge config set device.id ${DEVICE_SN} + Execute Command tedge cert remove + File Should Not Exist /etc/tedge/device-certs/tedge-certificate.pem + File Should Not Exist /etc/tedge/device-certs/tedge-private-key.pem + ${TEMPLATE_XID}= Get Random Name prefix=TST_Template Set Test Variable $TEMPLATE_XID Execute Command tedge config set c8y.smartrest1.templates "${TEMPLATE_XID}" diff --git a/tests/RobotFramework/tests/tedge_connect/tedge_connect_cn_validation.robot b/tests/RobotFramework/tests/tedge_connect/tedge_connect_cn_validation.robot new file mode 100644 index 00000000000..b28a3f67762 --- /dev/null +++ b/tests/RobotFramework/tests/tedge_connect/tedge_connect_cn_validation.robot @@ -0,0 +1,34 @@ +*** Settings *** +Resource ../../resources/common.resource +Library Cumulocity +Library ThinEdgeIO +Library ../../.venv/lib/python3.11/site-packages/robot/libraries/String.py + +Suite Teardown Get Logs +Test Setup Custom Setup + +Test Tags theme:c8y theme:cli + + +*** Test Cases *** +Certificate's CN must match device.id + ${cert_output}= Execute Command tedge cert show + Should Contain ${cert_output} ${DEVICE_SN} + + Execute Command tedge config set device.id foo + ${output}= Execute Command tedge connect c8y + ... exp_exit_code=1 + ... stdout=False + ... stderr=True + ... timeout=0 + ... strip=True + Should Be Equal + ... ${output} + ... error: device.id 'foo' mismatches to the device certificate's CN '${DEVICE_SN}' + + +*** Keywords *** +Custom Setup + ${device_sn}= Setup skip_bootstrap=${True} + Execute Command ./bootstrap.sh --no-connect + Set Test Variable $DEVICE_SN ${device_sn}