Debian Codegraph @

debian/patches/dgit-changes

raw
1 From:
2 Subject: Debian changes
3
4 The Debian packaging of hass-nabucasa is maintained in git, using a workflow
5 similar to the one described in dgit-maint-merge(7).
6 The Debian delta is represented by this one combined patch; there isn't a
7 patch queue that can be represented as a quilt series.
8
9 A detailed breakdown of the changes is available from their canonical
10 representation -- git commits in the packaging repository.
11 For example, to see the changes made by the Debian maintainer in the first
12 upload of upstream version 1.2.3, you could use:
13
14 % git clone https://git.dgit.debian.org/hass-nabucasa
15 % cd hass-nabucasa
16 % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
17
18 (If you have dgit, use `dgit clone hass-nabucasa`, rather than plain `git clone`.)
19
20 We don't use debian/source/options single-debian-patch because it has bugs.
21 Therefore, NMUs etc. may nevertheless have made additional patches.
22
23 ---
24
25 diff --git a/hass_nabucasa/instance_api.py b/hass_nabucasa/instance_api.py
26 index 7927086..d341417 100644
27 --- a/hass_nabucasa/instance_api.py
28 +++ b/hass_nabucasa/instance_api.py
29 @@ -57,6 +57,7 @@ class InstanceSnitunTokenDetails(TypedDict):
30 server: str
31 valid: int
32 throttling: int
33 + protocol_version: NotRequired[int]
34
35
36 class PingResult(TypedDict):
37 diff --git a/hass_nabucasa/remote.py b/hass_nabucasa/remote.py
38 index 8d23e50..aae9862 100644
39 --- a/hass_nabucasa/remote.py
40 +++ b/hass_nabucasa/remote.py
41 @@ -13,6 +13,7 @@ from typing import TYPE_CHECKING, TypedDict
42 import aiohttp
43 import attr
44 from snitun.exceptions import SniTunConnectionError
45 +from snitun.utils import DEFAULT_PROTOCOL_VERSION
46 from snitun.utils.aes import generate_aes_keyset
47 from snitun.utils.aiohttp_client import SniTunClientAioHttp
48
49 @@ -77,6 +78,7 @@ class SniTunToken:
50 aes_iv = attr.ib(type=bytes)
51 valid = attr.ib(type=datetime)
52 throttling = attr.ib(type=int)
53 + protocol_version = attr.ib(type=int, default=DEFAULT_PROTOCOL_VERSION)
54
55
56 @attr.s
57 @@ -402,7 +404,7 @@ class RemoteUI:
58
59 _LOGGER.debug("Starting SniTun")
60 is_cloud_request.set(True)
61 - await self._snitun.start(False, self._recreate_backend)
62 + await self._snitun.start()
63 self.cloud.client.dispatcher_message(const.DISPATCH_REMOTE_BACKEND_UP)
64
65 _LOGGER.debug(
66 @@ -477,6 +479,7 @@ class RemoteUI:
67 aes_iv,
68 utils.utc_from_timestamp(data["valid"]),
69 data["throttling"],
70 + data.get("protocol_version", DEFAULT_PROTOCOL_VERSION),
71 )
72
73 async def connect(self) -> None:
74 @@ -505,6 +508,7 @@ class RemoteUI:
75 self._token.aes_key,
76 self._token.aes_iv,
77 throttling=self._token.throttling,
78 + protocol_version=self._token.protocol_version,
79 )
80 _LOGGER.debug("Connected")
81
82 diff --git a/hass_nabucasa/utils.py b/hass_nabucasa/utils.py
83 index 0489b97..bb1319e 100644
84 --- a/hass_nabucasa/utils.py
85 +++ b/hass_nabucasa/utils.py
86 @@ -19,6 +19,7 @@ from .exceptions import NabuCasaBaseError
87
88 CALLABLE_T = TypeVar("CALLABLE_T", bound=Callable) # pylint: disable=invalid-name
89 UTC = dt.UTC
90 +UNIX_EPOCH = dt.datetime(1970, 1, 1, tzinfo=UTC)
91
92 _LOGGER = logging.getLogger(__name__)
93
94 @@ -48,7 +49,7 @@ def utcnow() -> dt.datetime:
95
96 def utc_from_timestamp(timestamp: float) -> dt.datetime:
97 """Return a UTC time from a timestamp."""
98 - return dt.datetime.fromtimestamp(timestamp, UTC)
99 + return UNIX_EPOCH + dt.timedelta(seconds=timestamp)
100
101
102 def parse_date(dt_str: str) -> dt.date | None:
103 diff --git a/pyproject.toml b/pyproject.toml
104 index 6e8ebbb..47b8d48 100644
105 --- a/pyproject.toml
106 +++ b/pyproject.toml
107 @@ -30,7 +30,7 @@ dependencies = [
108 "pycognito==2024.5.1",
109 "PyJWT>=2.8.0",
110 "requests>=2.0,<3",
111 - "snitun==0.45.1",
112 + "snitun==0.46.1",
113 "voluptuous>=0.15",
114 "webrtc-models<1.0.0",
115 "yarl>=1.20,<2",
116 diff --git a/tests/common.py b/tests/common.py
117 index d9a704a..3f660b3 100644
118 --- a/tests/common.py
119 +++ b/tests/common.py
120 @@ -3,7 +3,6 @@
121 from __future__ import annotations
122
123 import asyncio
124 -from collections.abc import Coroutine
125 import json
126 from pathlib import Path
127 import threading
128 @@ -16,6 +15,7 @@ from freezegun.api import (
129 TickingDateTimeFactory,
130 )
131 import pytest
132 +from snitun.client.access_list import AccessList
133
134 from hass_nabucasa.client import CloudClient
135
136 @@ -263,11 +263,11 @@ class MockSnitun:
137 self.call_disconnect = False
138 self.init_args = None
139 self.connect_args = None
140 + self.connect_kwargs = None
141 self.init_kwarg = None
142 self.wait_task = asyncio.Event()
143
144 - self.start_whitelist = None
145 - self.start_endpoint_connection_error_callback = None
146 + self.start_access_list = None
147
148 @property
149 def is_connected(self):
150 @@ -280,14 +280,10 @@ class MockSnitun:
151
152 async def start(
153 self,
154 - whitelist: bool = False,
155 - endpoint_connection_error_callback: Coroutine[Any, Any, None] | None = None,
156 - ):
157 + access_list: AccessList | None = None,
158 + ) -> None:
159 """Start snitun."""
160 - self.start_whitelist = whitelist
161 - self.start_endpoint_connection_error_callback = (
162 - endpoint_connection_error_callback
163 - )
164 + self.start_access_list = access_list
165 self.call_start = True
166
167 async def stop(self):
168 @@ -299,11 +295,16 @@ class MockSnitun:
169 token: bytes,
170 aes_key: bytes,
171 aes_iv: bytes,
172 - throttling=None,
173 - ):
174 + throttling: int | None = None,
175 + protocol_version: int = 0,
176 + ) -> None:
177 """Connect snitun."""
178 self.call_connect = True
179 self.connect_args = [token, aes_key, aes_iv, throttling]
180 + self.connect_kwargs = {
181 + "throttling": throttling,
182 + "protocol_version": protocol_version,
183 + }
184
185 async def disconnect(self):
186 """Disconnect snitun."""
187 diff --git a/tests/conftest.py b/tests/conftest.py
188 index fa519be..84a03e4 100644
189 --- a/tests/conftest.py
190 +++ b/tests/conftest.py
191 @@ -55,7 +55,10 @@ async def loop_fixture():
192 async def aioclient_mock(loop):
193 """Fixture to mock aioclient calls."""
194 with mock_aiohttp_client(loop) as mock_session:
195 - yield mock_session
196 + try:
197 + yield mock_session
198 + finally:
199 + await mock_session.close_sessions()
200
201
202 @pytest.fixture
203 diff --git a/tests/test_remote.py b/tests/test_remote.py
204 index 3d7c3fe..0c58f48 100644
205 --- a/tests/test_remote.py
206 +++ b/tests/test_remote.py
207 @@ -12,6 +12,7 @@ from acme import client, messages
208 import aiohttp
209 import pytest
210 from requests.exceptions import RequestException
211 +from snitun.utils import DEFAULT_PROTOCOL_VERSION
212 from syrupy import SnapshotAssertion
213
214 from hass_nabucasa import Cloud, utils
215 @@ -151,13 +152,14 @@ async def test_load_backend_exists_cert(
216 "snitun_port": 443,
217 }
218
219 - assert snitun_mock.start_whitelist is not None
220 - assert snitun_mock.start_endpoint_connection_error_callback is not None
221 + assert snitun_mock.start_access_list is None
222
223 await asyncio.sleep(0.1)
224 assert snitun_mock.call_connect
225 assert snitun_mock.connect_args[0] == b"test-token"
226 assert snitun_mock.connect_args[3] == 400
227 + # No protocol_version in the token response -> library default
228 + assert snitun_mock.connect_kwargs["protocol_version"] == DEFAULT_PROTOCOL_VERSION
229 assert cloud.remote.is_connected
230
231 assert cloud.remote._acme_task
232 @@ -188,6 +190,45 @@ async def test_load_backend_exists_cert(
233 assert cloud.remote.certificate_status == CertificateStatus.READY
234
235
236 +async def test_load_backend_with_protocol_version(
237 + cloud: Cloud,
238 + valid_acme_mock: MockAcme,
239 + aioclient_mock: AiohttpClientMocker,
240 + snitun_mock: MockSnitun,
241 +) -> None:
242 + """Connect uses the protocol_version provided by the token response."""
243 + valid = utcnow() + timedelta(days=1)
244 +
245 + aioclient_mock.post(
246 + f"https://{cloud.api_server}/instance/register",
247 + json={
248 + "domain": "test.dui.nabu.casa",
249 + "email": "[email protected]",
250 + "server": "rest-remote.nabu.casa",
251 + },
252 + )
253 + aioclient_mock.post(
254 + f"https://{cloud.api_server}/instance/snitun_token",
255 + json={
256 + "token": "test-token",
257 + "server": "rest-remote.nabu.casa",
258 + "valid": valid.timestamp(),
259 + "throttling": 400,
260 + "protocol_version": 2,
261 + },
262 + )
263 +
264 + await cloud.remote.start()
265 + await cloud.remote._info_loaded.wait()
266 + await asyncio.sleep(0.1)
267 +
268 + assert snitun_mock.call_connect
269 + assert snitun_mock.connect_kwargs["protocol_version"] == 2
270 +
271 + await cloud.remote.stop()
272 + await asyncio.sleep(0.1)
273 +
274 +
275 async def test_load_backend_not_exists_cert(
276 cloud: Cloud,
277 acme_mock: MockAcme,
278 diff --git a/tests/test_utils.py b/tests/test_utils.py
279 index d918ad2..f5de183 100644
280 --- a/tests/test_utils.py
281 +++ b/tests/test_utils.py
282 @@ -10,6 +10,14 @@ from syrupy import SnapshotAssertion
283 from hass_nabucasa import utils
284
285
286 +def test_utc_from_timestamp_after_32bit_time_t() -> None:
287 + """Test utc_from_timestamp handles timestamps after 2038 on 32-bit platforms."""
288 + assert (
289 + utils.utc_from_timestamp(9999999999).isoformat()
290 + == "2286-11-20T17:46:39+00:00"
291 + )
292 +
293 +
294 @pytest.mark.parametrize(
295 "input_str",
296 [
297 diff --git a/tests/utils/aiohttp.py b/tests/utils/aiohttp.py
298 index 0f33e52..af87938 100644
299 --- a/tests/utils/aiohttp.py
300 +++ b/tests/utils/aiohttp.py
301 @@ -34,6 +34,7 @@ class AiohttpClientMocker:
302 self._mocks = []
303 self._cookies = {}
304 self.mock_calls = []
305 + self._sessions = []
306
307 def request(
308 self,
309 @@ -110,10 +111,17 @@ class AiohttpClientMocker:
310 def create_session(self, loop):
311 """Create a ClientSession that is bound to this mocker."""
312 session = ClientSession(loop=loop)
313 + self._sessions.append(session)
314 # Setting directly on `session` will raise deprecation warning
315 object.__setattr__(session, "_request", self.match_request)
316 return session
317
318 + async def close_sessions(self):
319 + """Close all sessions created by this mocker."""
320 + for session in self._sessions:
321 + if not session.closed:
322 + await session.close()
323 +
324 async def match_request(
325 self,
326 method,