Skip to content

Commit 386d025

Browse files
authored
feat(http,td,client): add BasicAuth to WoT TD + default client header (#112)
feat(http,td,client): add BasicAuth to WoT TD + default client header; tests & docs - handlers: ThingDescriptionHandler.add_security_definitions() now emits TD.securityDefinitions & TD.security with Basic scheme - TD model: supports security metadata generation - client (HTTP): ObjectProxy attaches Authorization header on every request when username/password are provided - tests: extend test_13_protocols_http for basic and basic-auth flows - docs: README section on enabling Basic Auth + client usage (not updated it)
1 parent 4f24e2d commit 386d025

File tree

8 files changed

+1069
-709
lines changed

8 files changed

+1069
-709
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"editor.rulers": [
3-
80,120
43
],
54
"editor.formatOnSave": true,
65
}

hololinked/client/factory.py

Lines changed: 163 additions & 132 deletions
Large diffs are not rendered by default.

hololinked/client/http/consumed_interactions.py

Lines changed: 279 additions & 167 deletions
Large diffs are not rendered by default.

hololinked/client/proxy.py

Lines changed: 244 additions & 211 deletions
Large diffs are not rendered by default.

hololinked/server/http/handlers.py

Lines changed: 342 additions & 197 deletions
Large diffs are not rendered by default.

run_testthing_basic.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# run_testthing_basic.py
2+
import logging, time, uuid
3+
from tests.things.test_thing import TestThing
4+
from hololinked.server.security import BcryptBasicSecurity
5+
6+
thing_id = f"tt-{uuid.uuid4().hex[:6]}"
7+
port = 60110
8+
sec = BcryptBasicSecurity(username="cliuser", password="clipass")
9+
10+
thing = TestThing(id=thing_id, log_level=logging.INFO)
11+
thing.run_with_http_server(
12+
forked=True, port=port, config={"allow_cors": True}, security_schemes=[sec]
13+
)
14+
15+
print(f"TD: http://127.0.0.1:{port}/{thing_id}/resources/wot-td")
16+
print(f"Prop: http://127.0.0.1:{port}/{thing_id}/base-property")
17+
while True: time.sleep(5)

tests/test_13_protocols_http.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,29 @@ def test_11_object_proxy_basic(self):
703703
self.assertEqual(object_proxy.read_property("integration_time"), 1200)
704704
self.stop_server(port=port, thing_ids=[thing_id])
705705

706+
def test_12_object_proxy_with_basic_auth(self):
707+
security_scheme = BcryptBasicSecurity(username="cliuser", password="clipass")
708+
port = 60013
709+
thing_id = f"test-basic-proxy-{uuid.uuid4().hex[0:8]}"
710+
thing = OceanOpticsSpectrometer(
711+
id=thing_id, serial_number="simulation", log_level=logging.ERROR + 10
712+
)
713+
thing.run_with_http_server(
714+
forked=True,
715+
port=port,
716+
config={"allow_cors": True},
717+
security_schemes=[security_scheme],
718+
)
719+
time.sleep(2)
720+
721+
object_proxy = ClientFactory.http(
722+
url=f"http://127.0.0.1:{port}/{thing_id}/resources/wot-td",
723+
username="cliuser",
724+
password="clipass",
725+
)
726+
self.assertEqual(object_proxy.read_property("max_intensity"), 16384)
727+
self.stop_server(port=port, thing_ids=[thing_id])
728+
706729
@classmethod
707730
def stop_server(cls, port, thing_ids: list[str] = [], **request_kwargs):
708731
session = requests.Session()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)