diff --git a/tests/RobotFramework/tests/tedge/device_id/device_id_derivation.robot b/tests/RobotFramework/tests/tedge/device_id/device_id_derivation.robot new file mode 100644 index 0000000000..6d2db3f43b --- /dev/null +++ b/tests/RobotFramework/tests/tedge/device_id/device_id_derivation.robot @@ -0,0 +1,144 @@ +*** Settings *** +Resource ../../../resources/common.resource +Library ThinEdgeIO + +Test Setup Custom Setup +Test Teardown Custom Teardown + +Test Tags theme:cli + + +*** Test Cases *** +All use default cert/key paths + Execute Command tedge config unset c8y.device.cert_path + Execute Command tedge config unset c8y.device.key_path + Execute Command tedge config unset c8y.device.cert_path --profile foo + Execute Command tedge config unset c8y.device.key_path --profile foo + + Execute Command tedge config get device.id exp_exit_code=1 + ${output}= Execute Command tedge cert create --device-id input + Should Contain ${output} CN=input + Validate device IDs input input input + +Create a certificate without device.id in tedge config settings + Execute Command tedge config get device.id exp_exit_code=1 + ${output}= Execute Command tedge cert create --device-id input + Should Contain ${output} CN=input + ${output}= Execute Command tedge config get device.id strip=${True} + Should Be Equal ${output} input + ${output}= Execute Command tedge config get c8y.device.id exp_exit_code=1 + ${output}= Execute Command tedge config get c8y.device.id --profile foo exp_exit_code=1 + +Input from --device-id is used over the value from tedge config settings when device.id is set + Execute Command tedge config set device.id testid + Validate device IDs testid testid testid + + ${output}= Execute Command tedge cert create --device-id different + Should Contain ${output} CN=different + Validate device IDs different testid testid + Execute Command tedge cert remove + + ${output}= Execute Command tedge cert create c8y --device-id different + Should Contain ${output} CN=different + Validate device IDs testid different testid + Execute Command tedge cert remove c8y + + ${output}= Execute Command tedge cert create c8y --device-id different --profile foo + Should Contain ${output} CN=different + Validate device IDs testid testid different + Execute Command tedge cert remove c8y --profile foo + +Input from --device-id is used over the values from tedge config settings when device.id and c8y.device.id are set + Execute Command tedge config set device.id testid + Execute Command tedge config set c8y.device.id c8y-testid + Validate device IDs testid c8y-testid testid + + ${output}= Execute Command tedge cert create c8y --device-id different + Should Contain ${output} CN=different + Validate device IDs testid different testid + Execute Command tedge cert remove c8y + + ${output}= Execute Command tedge cert create c8y --device-id different --profile foo + Should Contain ${output} CN=different + Validate device IDs testid c8y-testid different + Execute Command tedge cert remove c8y --profile foo + +Input from --device-id is used over the values from tedge config settings when all device.id, c8y.device.id, c8y.profiles.foo.device.id are set + Execute Command tedge config set device.id testid + Execute Command tedge config set c8y.device.id c8y-testid + Execute Command tedge config set c8y.device.id c8y-foo-testid --profile foo + Validate device IDs testid c8y-testid c8y-foo-testid + + ${output}= Execute Command tedge cert create c8y --device-id different --profile foo + Should Contain ${output} CN=different + Validate device IDs testid c8y-testid different + +Generic device.id is used as "default" value if cloud profile doesn't have its own value when device.id is set + Execute Command tedge config set device.id testid + Validate device IDs testid testid testid + + ${output}= Execute Command tedge cert create + Should Contain ${output} CN=testid + Validate device IDs testid testid testid + + ${output}= Execute Command tedge cert create c8y + Should Contain ${output} CN=testid + Validate device IDs testid testid testid + + ${output}= Execute Command tedge cert create c8y --profile foo + Should Contain ${output} CN=testid + Validate device IDs testid testid testid + +Generic device.id is used as "default" value if cloud profile doesn't have its own value when device.id and c8y.device.id are set + Execute Command tedge config set device.id testid + Execute Command tedge config set c8y.device.id c8y-testid + Validate device IDs testid c8y-testid testid + + ${output}= Execute Command tedge cert create c8y + Should Contain ${output} CN=c8y-testid + Validate device IDs testid c8y-testid testid + + ${output}= Execute Command tedge cert create c8y --profile foo + Should Contain ${output} CN=testid + Validate device IDs testid c8y-testid testid + +Generic device.id is used as "default" value if cloud profile doesn't have its own value when all device.id, c8y.device.id, c8y.profiles.foo.device.id are set + Execute Command tedge config set device.id testid + Execute Command tedge config set c8y.device.id c8y-testid + Execute Command tedge config set c8y.device.id c8y-foo-testid --profile foo + Validate device IDs testid c8y-testid c8y-foo-testid + + ${output}= Execute Command tedge cert create c8y --profile foo + Should Contain ${output} CN=c8y-foo-testid + Validate device IDs testid c8y-testid c8y-foo-testid + + +*** Keywords *** +Validate device IDs + [Arguments] ${device_id} ${c8y_device_id} ${c8y_foo_device_id} + ${output}= Execute Command tedge config get device.id strip=${True} + Should Be Equal ${output} ${device_id} + ${output}= Execute Command tedge config get c8y.device.id strip=${True} + Should Be Equal ${output} ${c8y_device_id} + ${output}= Execute Command tedge config get c8y.device.id --profile foo strip=${True} + Should Be Equal ${output} ${c8y_foo_device_id} + +Custom Setup + Setup skip_bootstrap=${True} + Execute Command ./bootstrap.sh --no-bootstrap --no-connect + Execute Command tedge config set c8y.url example.com --profile foo + Execute Command tedge config set c8y.device.cert_path /etc/tedge/device-certs/tedge-certificate@default.pem + Execute Command tedge config set c8y.device.key_path /etc/tedge/device-certs/tedge-private-key@default.pem + Execute Command + ... tedge config set c8y.device.cert_path --profile foo /etc/tedge/device-certs/tedge-certificate@foo.pem + Execute Command + ... tedge config set c8y.device.key_path --profile foo /etc/tedge/device-certs/tedge-private-key@foo.pem + +Custom Teardown + Execute Command tedge config unset device.id + Execute Command tedge config unset c8y.device.id + Execute Command tedge config unset c8y.device.id --profile foo + Execute Command tedge cert remove ignore_exit_code=${True} + Execute Command tedge cert remove c8y ignore_exit_code=${True} + Execute Command tedge cert remove c8y --profile foo ignore_exit_code=${True} + Get Logs diff --git a/tests/RobotFramework/tests/tedge/device_id/device_id_usecases.robot b/tests/RobotFramework/tests/tedge/device_id/device_id_usecases.robot new file mode 100644 index 0000000000..f4b9ca181e --- /dev/null +++ b/tests/RobotFramework/tests/tedge/device_id/device_id_usecases.robot @@ -0,0 +1,69 @@ +*** Settings *** +Documentation This suite covers all usecases in the issue #3369 + +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 *** +Use explicit device id during cert creation + Execute Command tedge config set device.id ${FOO} + ${output}= Execute Command tedge cert create --device-id ${BAR} + Should Contain ${output} CN=${BAR} + + ${output}= Execute Command tedge config get device.id strip=${True} + Should Be Equal ${output} ${BAR} + + ${output}= Execute Command tedge connect c8y ignore_exit_code=${True} + Should Contain ${output} device id: ${BAR} + +Use default device.id + Execute Command tedge config set device.id ${FOO} + ${output}= Execute Command tedge cert create + Should Contain ${output} CN=${FOO} + + ${output}= Execute Command tedge config get device.id strip=${True} + Should Be Equal ${output} ${FOO} + + ${output}= Execute Command tedge connect c8y ignore_exit_code=${True} + Should Contain ${output} device id: ${FOO} + +Use device id from cert + Execute Command tedge cert create --device-id ${FOO} + Execute Command tedge config set device.id ${BAR} + + ${output}= Execute Command tedge config get device.id strip=${True} + Should Be Equal ${output} ${FOO} + + ${output}= Execute Command tedge connect c8y ignore_exit_code=${True} + Should Contain ${output} device id: ${FOO} + +Use default device.id to create the cert + Execute Command tedge config set device.id ${FOO} + + ${output}= Execute Command tedge cert create + Should Contain ${output} CN=${FOO} + + Execute Command tedge config set device.id ${BAR} + + ${output}= Execute Command tedge config get device.id strip=${True} + Should Be Equal ${output} ${FOO} + + ${output}= Execute Command tedge connect c8y ignore_exit_code=${True} + Should Contain ${output} device id: ${FOO} + + +*** Keywords *** +Custom Setup + ${device_sn}= Setup skip_bootstrap=${True} + Execute Command ./bootstrap.sh --no-connect + Set Test Variable $FOO ${device_sn}-1 + Set Test Variable $BAR ${device_sn}-2 + Execute Command tedge cert remove diff --git a/tests/RobotFramework/tests/tedge/tedge_cert_create.robot b/tests/RobotFramework/tests/tedge/tedge_cert_create.robot index 196c829a05..5b28b1e2ea 100644 --- a/tests/RobotFramework/tests/tedge/tedge_cert_create.robot +++ b/tests/RobotFramework/tests/tedge/tedge_cert_create.robot @@ -77,123 +77,8 @@ Run tedge cert create with cloud profile ... openssl x509 -noout -subject -in /etc/tedge/device-certs/tedge-certificate@third.pem Should Match Regexp ${subject} pattern=^subject=CN = ${THIRD_DEVICE_SN},.+$ -Device ID derivation - Execute Command tedge config get device.id exp_exit_code=1 - Execute Command tedge config set c8y.url example.com --profile foo - - ### All cert/key paths are the default - ${output}= Execute Command tedge cert create --device-id input - Should Contain ${output} CN=input - Validate device IDs input input input - Execute Command tedge cert remove - - ### Set specific cert/key paths per cloud profile - Execute Command tedge config set c8y.device.cert_path /etc/tedge/device-certs/tedge-certificate@default.pem - Execute Command tedge config set c8y.device.key_path /etc/tedge/device-certs/tedge-private-key@default.pem - Execute Command - ... tedge config set c8y.device.cert_path --profile foo /etc/tedge/device-certs/tedge-certificate@foo.pem - Execute Command - ... tedge config set c8y.device.key_path --profile foo /etc/tedge/device-certs/tedge-private-key@foo.pem - - ### No device ids are set in tedge config settings - # create a certificate without device.id in tedge config settings - ${output}= Execute Command tedge cert create --device-id input - Should Contain ${output} CN=input - ${output}= Execute Command tedge config get device.id strip=${True} - Should Be Equal ${output} input - ${output}= Execute Command tedge config get c8y.device.id exp_exit_code=1 - ${output}= Execute Command tedge config get c8y.device.id --profile foo exp_exit_code=1 - Execute Command tedge cert remove - - ### Only device.id is set - Execute Command tedge config set device.id testid - Validate device IDs testid testid testid - - # the input from --device-id is used over the value from tedge config - ${output}= Execute Command tedge cert create --device-id different - Should Contain ${output} CN=different - Validate device IDs different testid testid - Execute Command tedge cert remove - - ${output}= Execute Command tedge cert create c8y --device-id different - Should Contain ${output} CN=different - Validate device IDs testid different testid - Execute Command tedge cert remove c8y - - ${output}= Execute Command tedge cert create c8y --device-id different --profile foo - Should Contain ${output} CN=different - Validate device IDs testid testid different - Execute Command tedge cert remove c8y --profile foo - - # the generic device.id is used as "default" value if cloud profile doesn't have its own value - ${output}= Execute Command tedge cert create - Should Contain ${output} CN=testid - Validate device IDs testid testid testid - Execute Command tedge cert remove - - ${output}= Execute Command tedge cert create c8y - Should Contain ${output} CN=testid - Validate device IDs testid testid testid - Execute Command tedge cert remove c8y - - ${output}= Execute Command tedge cert create c8y --profile foo - Should Contain ${output} CN=testid - Validate device IDs testid testid testid - Execute Command tedge cert remove c8y --profile foo - - ### Both device.id and c8y.device.id are set in tedge config settings - Execute Command tedge config set c8y.device.id c8y-testid - Validate device IDs testid c8y-testid testid - - # the input from --device-id is used over the value from tedge config - ${output}= Execute Command tedge cert create c8y --device-id different - Should Contain ${output} CN=different - Validate device IDs testid different testid - Execute Command tedge cert remove c8y - - ${output}= Execute Command tedge cert create c8y --device-id different --profile foo - Should Contain ${output} CN=different - Validate device IDs testid c8y-testid different - Execute Command tedge cert remove c8y --profile foo - - # the device id value from cloud profile is used over the "default" value from the generic device.id - ${output}= Execute Command tedge cert create c8y - Should Contain ${output} CN=c8y-testid - Validate device IDs testid c8y-testid testid - Execute Command tedge cert remove c8y - - ${output}= Execute Command tedge cert create c8y --profile foo - Should Contain ${output} CN=testid - Validate device IDs testid c8y-testid testid - Execute Command tedge cert remove c8y --profile foo - - ### All device.id, c8y.device.id, c8y.profiles.foo.device.id are set - Execute Command tedge config set c8y.device.id c8y-foo-testid --profile foo - Validate device IDs testid c8y-testid c8y-foo-testid - - # the input from --device-id is used over the value from tedge config - ${output}= Execute Command tedge cert create c8y --device-id different --profile foo - Should Contain ${output} CN=different - Validate device IDs testid c8y-testid different - Execute Command tedge cert remove c8y --profile foo - - # the device id value from cloud profile is used over the "default" value from the generic device.id - ${output}= Execute Command tedge cert create c8y --profile foo - Should Contain ${output} CN=c8y-foo-testid - Validate device IDs testid c8y-testid c8y-foo-testid - Execute Command tedge cert remove c8y --profile foo - *** Keywords *** -Validate device IDs - [Arguments] ${device_id} ${c8y_device_id} ${c8y_foo_device_id} - ${output}= Execute Command tedge config get device.id strip=${True} - Should Be Equal ${output} ${device_id} - ${output}= Execute Command tedge config get c8y.device.id strip=${True} - Should Be Equal ${output} ${c8y_device_id} - ${output}= Execute Command tedge config get c8y.device.id --profile foo strip=${True} - Should Be Equal ${output} ${c8y_foo_device_id} - Custom Setup ${device_sn}= Setup skip_bootstrap=${True} Execute Command ./bootstrap.sh --no-bootstrap --no-connect