-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: gligorisaev <[email protected]>
- Loading branch information
1 parent
5d218ec
commit f0fa54f
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
tests/RobotFramework/tests/tedge/parse_root_certificate.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,71 @@ | ||
*** Settings *** | ||
Resource ../../resources/common.resource | ||
Library ThinEdgeIO | ||
Library String | ||
Library Collections | ||
|
||
Test Teardown Get Logs | ||
|
||
Test Tags theme:ca_certificates | ||
|
||
|
||
*** Test Cases *** | ||
|
||
Verify Single Certificate File | ||
[Setup] Setup With Self-Signed Certificate | ||
ThinEdgeIO.File Should Exist /etc/tedge/device-certs/tedge-certificate.pem | ||
${output_cert}= Execute Command cat /etc/tedge/device-certs/tedge-certificate.pem | ||
Should Contain ${output_cert} -----BEGIN CERTIFICATE----- | ||
|
||
Verify Single Private Key File | ||
[Setup] Setup With Self-Signed Certificate | ||
ThinEdgeIO.File Should Exist /etc/tedge/device-certs/tedge-private-key.pem | ||
${output_key}= Execute Command cat /etc/tedge/device-certs/tedge-private-key.pem | ||
Should Contain ${output_key} -----BEGIN PRIVATE KEY----- | ||
|
||
Verify Multiple Certificates in Directory | ||
[Setup] Setup With Self-Signed Certificate | ||
ThinEdgeIO.File Should Exist /etc/tedge/device-certs/tedge-certificate.pem | ||
${dir_contents}= Execute Command ls /etc/tedge/device-certs | ||
Log ${dir_contents} | ||
|
||
# List .pem files and check the result | ||
${cert_files}= Execute Command ls /etc/tedge/device-certs/*.pem | ||
${cert_files_list}= Split String ${cert_files} \n | ||
@{filtered_cert_files}= Create List | ||
FOR ${file} IN @{cert_files_list} | ||
Run Keyword If '${file}' != '' Append To List ${filtered_cert_files} ${file} | ||
END | ||
|
||
${cert_files_length}= Get Length ${filtered_cert_files} | ||
Should Be True ${cert_files_length} > 1 | ||
FOR ${cert_file} IN @{filtered_cert_files} | ||
${output_cert}= Execute Command cat ${cert_file} | ||
Should Contain Any Line ${output_cert} ${cert_file} | ||
END | ||
|
||
Verify Invalid Path | ||
[Setup] Setup With Self-Signed Certificate | ||
${result}= Execute Command ls /invalid/path/*.pem ignore_exit_code=True stderr=True stdout=True | ||
${stdout}= Set Variable ${result}[1] | ||
Should Contain ${stdout} No such file or directory | ||
|
||
|
||
*** Keywords *** | ||
Setup With Self-Signed Certificate | ||
${DEVICE_SN}= Setup skip_bootstrap=${True} | ||
Set Test Variable $DEVICE_SN | ||
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --cert-method selfsigned | ||
|
||
Setup Without Certificate | ||
${DEVICE_SN}= Setup skip_bootstrap=${True} | ||
Set Test Variable $DEVICE_SN | ||
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --install --no-bootstrap --no-connect | ||
|
||
Should Contain Any Line | ||
[Arguments] ${text} ${cert_file} | ||
${cert_present}= Run Keyword And Return Status Should Contain ${text} -----BEGIN CERTIFICATE----- | ||
${key_present}= Run Keyword And Return Status Should Contain ${text} -----BEGIN PRIVATE KEY----- | ||
Run Keyword If ${cert_present} Log Certificate found in ${cert_file} | ||
Run Keyword If ${key_present} Log Private key found in ${cert_file} | ||
Run Keyword If not ${cert_present} and not ${key_present} Fail The file ${cert_file} does not contain a valid certificate or private key. |