Skip to content

Commit edc3b0b

Browse files
committed
test: add end-to-end coverage for the config-exposure feature
Add a Robot Framework suite verifying the agent's own retained config topics and HTTP routes, including that a secret setting (device.key_pin) never appears on either surface, and a second suite covering a bootstrapped c8y mapper's own retained config topics and HTTP routes, verifying the cloud/profile qualifier is stripped and other clouds' settings are absent. Signed-off-by: Albin Suresh <albin.suresh@cumulocity.com>
1 parent 22e7c87 commit edc3b0b

3 files changed

Lines changed: 139 additions & 2 deletions

File tree

openspec/changes/expose-tedge-configs/tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757
## 9. End-to-end tests
5858

59-
- [ ] 9.1 Add a Robot Framework suite verifying the agent's retained config topics and HTTP routes, including that secret settings never appear
60-
- [ ] 9.2 Extend the suite to cover a bootstrapped c8y mapper's retained config topics and HTTP routes
59+
- [x] 9.1 Add a Robot Framework suite verifying the agent's retained config topics and HTTP routes, including that secret settings never appear
60+
- [x] 9.2 Extend the suite to cover a bootstrapped c8y mapper's retained config topics and HTTP routes
6161

6262
## 10. Documentation
6363

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
*** Settings ***
2+
Documentation Verify that a bootstrapped c8y mapper publishes its own exposable cloud
3+
... configuration as retained MQTT messages under its own service topic, with the
4+
... cloud qualifier stripped from the key, and that the agent serves them over the
5+
... GET /te/v1/entities/<service>/config[/<key>] HTTP routes.
6+
7+
Resource ../resources/common.resource
8+
Library Cumulocity
9+
Library ThinEdgeIO
10+
11+
Suite Setup Custom Setup
12+
Test Teardown Get Logs ${DEVICE_SN}
13+
14+
Test Tags theme:c8y
15+
16+
17+
*** Variables ***
18+
${DEVICE_SN} ${EMPTY} # Main device serial number
19+
20+
21+
*** Test Cases ***
22+
Mapper publishes its own url setting with the cloud qualifier stripped
23+
${url}= Execute Command tedge config get c8y.url strip=${True}
24+
${retained}= Execute Command
25+
... tedge mqtt sub te/device/main/service/tedge-mapper-c8y/config/url --retained-only --no-topic --duration 1s
26+
... strip=${True}
27+
Should Be Equal ${retained} ${url}
28+
29+
Mapper does not publish another cloud's settings
30+
Should Not Have Retained MQTT Messages
31+
... topic=te/device/main/service/tedge-mapper-c8y/config/az.url
32+
Should Not Have Retained MQTT Messages
33+
... topic=te/device/main/service/tedge-mapper-c8y/config/aws.url
34+
35+
Agent serves the mapper's single exposed value over HTTP
36+
${url}= Execute Command tedge config get c8y.url strip=${True}
37+
${get}= Execute Command
38+
... curl --silent --write-out "|%\{http_code\}" http://localhost:8000/te/v1/entities/device/main/service/tedge-mapper-c8y/config/url
39+
Should Be Equal ${get} ${url}|200
40+
41+
Agent serves the mapper's whole exposed config as a JSON object over HTTP
42+
${url}= Execute Command tedge config get c8y.url strip=${True}
43+
${topic_prefix}= Execute Command tedge config get c8y.bridge.topic_prefix strip=${True}
44+
${get}= Execute Command
45+
... curl --silent http://localhost:8000/te/v1/entities/device/main/service/tedge-mapper-c8y/config
46+
Should Contain ${get} "url":"${url}"
47+
Should Contain ${get} "bridge.topic_prefix":"${topic_prefix}"
48+
49+
A non-exposed c8y secret setting never appears on the retained config topic
50+
Should Not Have Retained MQTT Messages
51+
... topic=te/device/main/service/tedge-mapper-c8y/config/device.key_pin
52+
53+
A non-exposed c8y secret setting never appears in the HTTP config view
54+
${get}= Execute Command
55+
... curl --silent http://localhost:8000/te/v1/entities/device/main/service/tedge-mapper-c8y/config
56+
Should Not Contain ${get} key_pin
57+
Should Not Contain ${get} credentials_path
58+
59+
60+
*** Keywords ***
61+
Custom Setup
62+
${DEVICE_SN}= Setup
63+
Set Suite Variable $DEVICE_SN
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
*** Settings ***
2+
Documentation Verify that tedge-agent publishes its own exposable configuration as retained
3+
... MQTT messages under its own service topic, and serves them over the
4+
... GET /te/v1/entities/<service>/config[/<key>] HTTP routes, while secret settings
5+
... never appear on either surface.
6+
7+
Resource ../../../resources/common.resource
8+
Library Cumulocity
9+
Library ThinEdgeIO
10+
11+
Suite Setup Custom Setup
12+
Test Teardown Get Logs ${DEVICE_SN}
13+
14+
Test Tags theme:tedge_agent
15+
16+
17+
*** Variables ***
18+
${DEVICE_SN} ${EMPTY} # Main device serial number
19+
20+
21+
*** Test Cases ***
22+
Agent publishes an exposed core setting as a retained MQTT message
23+
${device_id}= Execute Command tedge config get device.id strip=${True}
24+
${retained}= Execute Command
25+
... tedge mqtt sub te/device/main/service/tedge-agent/config/device.id --retained-only --no-topic --duration 1s
26+
... strip=${True}
27+
Should Be Equal ${retained} ${device_id}
28+
29+
Agent serves a single exposed value over HTTP
30+
${device_id}= Execute Command tedge config get device.id strip=${True}
31+
${get}= Execute Command
32+
... curl --silent --write-out "|%\{http_code\}" http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config/device.id
33+
Should Be Equal ${get} ${device_id}|200
34+
35+
Agent serves the whole exposed config as a JSON object over HTTP
36+
${device_id}= Execute Command tedge config get device.id strip=${True}
37+
${mqtt_port}= Execute Command tedge config get mqtt.client.port strip=${True}
38+
${get}= Execute Command
39+
... curl --silent http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config
40+
Should Contain ${get} "device.id":"${device_id}"
41+
Should Contain ${get} "mqtt.client.port":"${mqtt_port}"
42+
43+
A non-exposed secret setting never appears on the retained config topic
44+
Should Not Have Retained MQTT Messages
45+
... topic=te/device/main/service/tedge-agent/config/device.key_pin
46+
47+
A non-exposed secret setting never appears in the HTTP config view
48+
${get}= Execute Command
49+
... curl --silent http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config
50+
Should Not Contain ${get} key_pin
51+
52+
A non-exposed key returns 404, indistinguishable from an unknown key
53+
${secret}= Execute Command
54+
... curl --silent --write-out "%\{http_code\}" -o /dev/null http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config/device.key_pin
55+
Should Be Equal ${secret} 404
56+
57+
${unknown}= Execute Command
58+
... curl --silent --write-out "%\{http_code\}" -o /dev/null http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config/no.such.key
59+
Should Be Equal ${unknown} 404
60+
61+
The config HTTP view rejects writes
62+
${put}= Execute Command
63+
... curl --silent --write-out "%\{http_code\}" -o /dev/null -X PUT http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config/device.id -d 'other-value'
64+
Should Be Equal ${put} 405
65+
66+
${delete}= Execute Command
67+
... curl --silent --write-out "%\{http_code\}" -o /dev/null -X DELETE http://localhost:8000/te/v1/entities/device/main/service/tedge-agent/config/device.id
68+
Should Be Equal ${delete} 405
69+
70+
71+
*** Keywords ***
72+
Custom Setup
73+
${DEVICE_SN}= Setup
74+
Set Suite Variable $DEVICE_SN

0 commit comments

Comments
 (0)