Skip to content

Commit

Permalink
fixup! fixup! fix: device.id is derived from device certificate if ce…
Browse files Browse the repository at this point in the history
…rtificate exists

Signed-off-by: Rina Fujino <rina.fujino.23@gmail.com>
  • Loading branch information
rina23q committed Feb 3, 2025
1 parent ef49eeb commit 88e81bc
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 117 deletions.
147 changes: 147 additions & 0 deletions tests/RobotFramework/tests/tedge/device_id/device_id_derivation.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
*** Settings ***
Resource ../../../resources/common.resource
Library ThinEdgeIO

Suite Setup Custom Suite Setup
Test Setup Custom Test 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 Suite Setup
Setup skip_bootstrap=${True}
Execute Command ./bootstrap.sh --no-bootstrap --no-connect

Custom Test Setup
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*** Settings ***
Documentation This suite covers all usecases in the issue #3369
Resource ../../resources/common.resource
Resource ../../../resources/common.resource
Library Cumulocity
Library ThinEdgeIO
Library ../../.venv/lib/python3.11/site-packages/robot/libraries/String.py
Expand Down Expand Up @@ -35,7 +35,7 @@ Use default device.id
${output}= Execute Command tedge connect c8y ignore_exit_code=${True}
Should Contain ${output} device id: ${FOO}

Use default device.id 2
Use device id from cert
Execute Command tedge cert create --device-id ${FOO}
Execute Command tedge config set device.id ${BAR}

Expand Down
115 changes: 0 additions & 115 deletions tests/RobotFramework/tests/tedge/tedge_cert_create.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88e81bc

Please sign in to comment.