Skip to content

Commit

Permalink
feat(tests): custom Traefik module ID
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePrincipi committed Feb 21, 2025
1 parent f33fb22 commit e7d731e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion tests/00_traefik.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Library SSHLibrary

*** Test Cases ***
Check if traefik service is loaded correctly
${output} ${rc} = Execute Command runagent -m traefik1 systemctl --user show --property=LoadState traefik
${output} ${rc} = Execute Command runagent -m ${MID} systemctl --user show --property=LoadState traefik
... return_rc=True
Should Be Equal As Integers ${rc} 0
Should Be Equal As Strings ${output} LoadState=loaded
26 changes: 13 additions & 13 deletions tests/10_traefik_routes_api.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ Resource api.resource

*** Test Cases ***
Create a path rule
${response} = Run task module/traefik1/set-route
${response} = Run task module/${MID}/set-route
... {"instance": "module1", "url": "http://127.0.0.0:2000", "path": "/foo", "lets_encrypt": false, "http2https": true, "skip_cert_verify": true, "headers": {"request": {"X-foo-add": "foo", "X-bar-remove": ""}, "response": {"X-bar-add": "bar", "X-foo-remove": ""}}}

Create a host rule
${response} = Run task module/traefik1/set-route
${response} = Run task module/${MID}/set-route
... {"instance": "module2", "url": "http://127.0.0.0:2000", "host": "foo.example.org", "lets_encrypt": true, "http2https": true, "skip_cert_verify": true, "headers": {"request": {"X-foo-add": "foo", "X-bar-remove": ""}, "response": {"X-bar-add": "bar", "X-foo-remove": ""}}}

Create a host & path rule
${response} = Run task module/traefik1/set-route
${response} = Run task module/${MID}/set-route
... {"instance": "module3", "url": "http://127.0.0.0:2000", "host": "bar.example.org", "path": "/bar", "lets_encrypt": true, "http2https": true, "skip_cert_verify": true, "user_created": true, "headers": {"request": {"X-foo-add": "foo", "X-bar-remove": ""}, "response": {"X-bar-add": "bar", "X-foo-remove": ""}}}

Create an invalid path route
Run Keyword And Expect Error * Run task module/traefik1/set-route
Run Keyword And Expect Error * Run task module/${MID}/set-route
... {"instance": "module4", "url": "http://127.0.0.0:2000", "path": "bar", "lets_encrypt": true, "http2https": true, "skip_cert_verify": true, "headers": {"request": {"X-foo-add": "foo", "X-bar-remove": ""}, "response": {"X-bar-add": "bar", "X-foo-remove": ""}}}

Get path route
${response} = Run task module/traefik1/get-route {"instance": "module1"}
${response} = Run task module/${MID}/get-route {"instance": "module1"}
Should Be Equal As Strings ${response['instance']} module1
Should Be Equal As Strings ${response['path']} /foo
Should Be Equal As Strings ${response['url']} http://127.0.0.0:2000
Expand All @@ -36,7 +36,7 @@ Get path route
Should Be Equal As Strings ${response['headers']['response']['X-foo-remove']} ${EMPTY}

Get host route
${response} = Run task module/traefik1/get-route {"instance": "module2"}
${response} = Run task module/${MID}/get-route {"instance": "module2"}
Should Be Equal As Strings ${response['instance']} module2
Should Be Equal As Strings ${response['host']} foo.example.org
Should Be Equal As Strings ${response['url']} http://127.0.0.0:2000
Expand All @@ -51,7 +51,7 @@ Get host route


Get host & path route
${response} = Run task module/traefik1/get-route {"instance": "module3"}
${response} = Run task module/${MID}/get-route {"instance": "module3"}
Should Be Equal As Strings ${response['instance']} module3
Should Be Equal As Strings ${response['path']} /bar
Should Be Equal As Strings ${response['host']} bar.example.org
Expand All @@ -67,14 +67,14 @@ Get host & path route
Should Be Equal As Strings ${response['headers']['response']['X-foo-remove']} ${EMPTY}

Get routes list
${response} = Run task module/traefik1/list-routes null
${response} = Run task module/${MID}/list-routes null
Should Contain ${response} module1
Should Contain ${response} module2
Should Contain ${response} module3
Should Contain ${response} cluster-admin

Get expanded routes list
${response} = Run task module/traefik1/list-routes {"expand_list": true}
${response} = Run task module/${MID}/list-routes {"expand_list": true}
${routes_length} = Get Length ${response}
FOR ${I} IN RANGE ${routes_length}
IF $response[$I]['instance'] == "cluster-admin"
Expand Down Expand Up @@ -135,10 +135,10 @@ Get expanded routes list
END

Delete routes
Run task module/traefik1/delete-route {"instance": "module1"}
Run task module/traefik1/delete-route {"instance": "module2"}
Run task module/traefik1/delete-route {"instance": "module3"}
Run task module/${MID}/delete-route {"instance": "module1"}
Run task module/${MID}/delete-route {"instance": "module2"}
Run task module/${MID}/delete-route {"instance": "module3"}

Expect initial routes list
${response} = Run task module/traefik1/list-routes null decode_json=${False}
${response} = Run task module/${MID}/list-routes null decode_json=${False}
Should Be Equal As Strings ${response} ["cluster-admin"]
42 changes: 21 additions & 21 deletions tests/20_traefik_certificates_api.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ Resource api.resource
*** Test Cases ***

Get default ACME server
${response} = Run task module/traefik1/get-acme-server {}
${response} = Run task module/${MID}/get-acme-server {}
Should Be Equal As Strings ${response['url']} https://acme-v02.api.letsencrypt.org/directory


Set ACME server url to Let's Encrypt Staging
${response} = Run task module/traefik1/set-acme-server
${response} = Run task module/${MID}/set-acme-server
... {"url":"https://acme-staging-v02.api.letsencrypt.org/directory"}

Get configured ACME server
${response} = Run task module/traefik1/get-acme-server {}
${response} = Run task module/${MID}/get-acme-server {}
Should Be Equal As Strings ${response['url']} https://acme-staging-v02.api.letsencrypt.org/directory

Request an invalid certificate
${response} = Run task module/traefik1/set-certificate
${response} = Run task module/${MID}/set-certificate
... {"fqdn":"example.com"}
Should Be Equal As Strings ${response['obtained']} False

Get invalid cerficate status
${response} = Run task module/traefik1/get-certificate {"fqdn": "example.com"}
${response} = Run task module/${MID}/get-certificate {"fqdn": "example.com"}
Should Be Equal As Strings ${response['fqdn']} example.com
Should Be Equal As Strings ${response['obtained']} False
Should Be Equal As Strings ${response['type']} internal

Get certificate list
${response} = Run task module/traefik1/list-certificates null
${response} = Run task module/${MID}/list-certificates null
Should Contain ${response} example.com

Get expanded certificate list
${response} = Run task module/traefik1/list-certificates {"expand_list": true}
${response} = Run task module/${MID}/list-certificates {"expand_list": true}
Should Be Equal As Strings ${response[0]['fqdn']} example.com
Should Be Equal As Strings ${response[0]['obtained']} False
Should Be Equal As Strings ${response[0]['type']} internal

Delete certificate
Run task module/traefik1/delete-certificate {"fqdn": "example.com"}
Run task module/${MID}/delete-certificate {"fqdn": "example.com"}

Get empty certificates list
${response} = Run task module/traefik1/list-certificates null
${response} = Run task module/${MID}/list-certificates null
Should Be Empty ${response}

Reject a certificate with missing or empty CN field
Expand All @@ -51,7 +51,7 @@ Reject a certificate with missing or empty CN field
# base64 encode the key and csr
${encoded_key} = Execute Command echo "${plain_key}" \| base64 -w 0
${encoded_csr} = Execute Command echo "${plain_csr}" \| base64 -w 0
${response} = Run task module/traefik1/upload-certificate
${response} = Run task module/${MID}/upload-certificate
... {"keyFile": "${encoded_key}", "certFile": "${encoded_csr}"} rc_expected=5 decode_json=False

Generate a custom private and public key
Expand All @@ -64,31 +64,31 @@ Generate a custom private and public key
Set Suite Variable ${csr} ${encoded_csr}

Upload rejected for a self-signed certificate
${response} = Run task module/traefik1/upload-certificate
${response} = Run task module/${MID}/upload-certificate
... {"keyFile": "${key}", "certFile": "${csr}"} rc_expected=33

Upload a custom certificate
# Disable strict certificate verification:
Execute Command runagent -m traefik1 python3 -c 'import agent ; agent.set_env("UPLOAD_CERTIFICATE_VERIFY_TYPE", "selfsign")'
${response} = Run task module/traefik1/upload-certificate
Execute Command runagent -m ${MID} python3 -c 'import agent ; agent.set_env("UPLOAD_CERTIFICATE_VERIFY_TYPE", "selfsign")'
${response} = Run task module/${MID}/upload-certificate
... {"keyFile": "${key}", "certFile": "${csr}"}
${response} = Run task module/traefik1/get-certificate {"fqdn": "test.example.com"}
${response} = Run task module/${MID}/get-certificate {"fqdn": "test.example.com"}
Should Be Equal As Strings ${response['fqdn']} test.example.com
Should Be Equal As Strings ${response['obtained']} True
Should Be Equal As Strings ${response['type']} custom
# check if the certificate is stored in redis
${response} = Execute Command redis-cli --raw EXISTS module/traefik1/certificate/test.example.com
${response} = Execute Command redis-cli --raw EXISTS module/${MID}/certificate/test.example.com
Should Be Equal As Integers ${response} 1
${response} = Execute Command redis-cli --raw HGET module/traefik1/certificate/test.example.com custom
${response} = Execute Command redis-cli --raw HGET module/${MID}/certificate/test.example.com custom
Should Be Equal As Strings ${response} true
# check if the certificate stored is base64 encoded
${response} = Execute Command command=redis-cli HGET module/traefik1/certificate/test.example.com cert | base64 -d return_stdout=False return_rc=True
${response} = Execute Command command=redis-cli HGET module/${MID}/certificate/test.example.com cert | base64 -d return_stdout=False return_rc=True
Should Be Equal As Integers ${response} 0
${response} = Execute Command command=redis-cli HGET module/traefik1/certificate/test.example.com key | base64 -d return_stdout=False return_rc=True
${response} = Execute Command command=redis-cli HGET module/${MID}/certificate/test.example.com key | base64 -d return_stdout=False return_rc=True
Should Be Equal As Integers ${response} 0
Execute Command runagent -m traefik1 python3 -c 'import agent ; agent.set_env("UPLOAD_CERTIFICATE_VERIFY_TYPE", "chain")'
Execute Command runagent -m ${MID} python3 -c 'import agent ; agent.set_env("UPLOAD_CERTIFICATE_VERIFY_TYPE", "chain")'

Delete custom certificate
Run task module/traefik1/delete-certificate {"fqdn": "test.example.com"}
${response} = Execute Command redis-cli --raw EXISTS module/traefik1/certificate/test.example.com
Run task module/${MID}/delete-certificate {"fqdn": "test.example.com"}
${response} = Execute Command redis-cli --raw EXISTS module/${MID}/certificate/test.example.com
Should Be Equal As Integers ${response} 0
2 changes: 2 additions & 0 deletions tests/__init__.robot
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Suite Teardown Tear down connection and test suite tools
*** Variables ***
${SSH_KEYFILE} %{HOME}/.ssh/id_ecdsa
${NODE_ADDR} 127.0.0.1
${MID} traefik1

*** Keywords ***
Connect to the node
Expand All @@ -19,6 +20,7 @@ Connect to the node
Setup connection and test suite tools
Connect to the node
Save the journal begin timestamp
Set Global Variable ${MID} ${MID}

Tear down connection and test suite tools
Collect the suite journal
Expand Down

0 comments on commit e7d731e

Please sign in to comment.