-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fix: device.id is derived from device certificate if ce…
…rtificate exists Signed-off-by: Rina Fujino <rina.fujino.23@gmail.com>
- Loading branch information
Showing
3 changed files
with
213 additions
and
115 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
tests/RobotFramework/tests/tedge/device_id/device_id_derivation.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
69 changes: 69 additions & 0 deletions
69
tests/RobotFramework/tests/tedge/device_id/device_id_usecases.robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters