From 73bf42916dce723c3b4005f999f5b4cdc7a4da91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 03:15:57 +0100 Subject: [PATCH 1/4] fix(auth): name the region in the local login answer The device plugin starts with fetchCountryInfo. It gets countryCode and serverCode from the app. The app takes them from the stored login answer: "country" becomes RRUser.countryIso and "region" becomes RRUser.region, which is the serverCode. If serverCode is empty, the plugin reads areaServerMap[countryCode].code. No entry of that map has a code, so the call throws. The catch block calls fetchCountryInfo again at once, so the plugin loops forever and sends no request. Without a cloud snapshot, the login answer had no "region", and its "country" was "EU". So the a307 plugin never got to the agreement check or the map. Send "region" in lower case, as the cloud does, and send "DE" as the country of the EU region. The EU cloud answers "region": "eu", "country": "DE" and "countrycode": "49". --- src/roborock_local_server/server.py | 13 ++++++++-- tests/conftest.py | 2 ++ tests/test_protocol_auth.py | 37 +++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/roborock_local_server/server.py b/src/roborock_local_server/server.py index 99371d23..90b37d14 100644 --- a/src/roborock_local_server/server.py +++ b/src/roborock_local_server/server.py @@ -74,6 +74,11 @@ "EU": "49", "RU": "7", } +# The login answer names a country, and "EU" is none. The EU cloud answers +# "DE", which fits the dialing code 49. +_REGION_COUNTRY = { + "EU": "DE", +} PROJECT_SUPPORT = { "title": "Support This Project", "text": ( @@ -590,12 +595,16 @@ def _local_protocol_identity(self) -> dict[str, Any]: normalized_email = email.casefold() digest = hashlib.sha256(normalized_email.encode("utf-8")).hexdigest() uid = (int(digest[:12], 16) % 900_000_000) + 100_000_000 - region_upper = self.config.network.region.upper() + region = self.config.network.region.lower() + region_upper = region.upper() return { "uid": uid, "rruid": f"rrls-{digest[:20]}", "email": email, - "country": region_upper, + # The app keeps "region" as RRUser.region. The device plugin needs + # it in fetchCountryInfo and retries forever without it. + "region": region, + "country": _REGION_COUNTRY.get(region_upper, region_upper), "countrycode": self._default_country_code_for_region(region_upper), "nickname": "Local User", "hasPassword": True, diff --git a/tests/conftest.py b/tests/conftest.py index f4b4d43b..412df966 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,6 +18,7 @@ def write_release_config( tmp_path: Path, *, stack_fqdn: str = "api-roborock.example.com", + region: str = "us", listener_mode: str = "local_tls", https_port: int = 443, mqtt_tls_port: int = 8883, @@ -38,6 +39,7 @@ def write_release_config( f""" [network] stack_fqdn = "{stack_fqdn}" +region = "{region}" listener_mode = "{listener_mode}" https_port = {https_port} mqtt_tls_port = {mqtt_tls_port} diff --git a/tests/test_protocol_auth.py b/tests/test_protocol_auth.py index 49ffd175..7baba69b 100644 --- a/tests/test_protocol_auth.py +++ b/tests/test_protocol_auth.py @@ -3,6 +3,7 @@ from pathlib import Path from fastapi.testclient import TestClient +import pytest from conftest import write_release_config from roborock_local_server.config import load_config, resolve_paths @@ -72,8 +73,13 @@ def _token_headers(login_payload: dict[str, object]) -> dict[str, str]: } -def _build_supervisor(tmp_path: Path, *, with_snapshot: bool = True) -> tuple[ReleaseSupervisor, object]: - config_file = write_release_config(tmp_path) +def _build_supervisor( + tmp_path: Path, + *, + with_snapshot: bool = True, + region: str = "us", +) -> tuple[ReleaseSupervisor, object]: + config_file = write_release_config(tmp_path, region=region) config = load_config(config_file) paths = resolve_paths(config_file, config) _write_json(paths.inventory_path, {"home": {"id": 12345, "name": "Test Home"}, "devices": []}) @@ -228,6 +234,33 @@ def test_local_pin_login_succeeds_without_imported_cloud_snapshot(tmp_path: Path assert user_info.json()["data"]["email"] == "user@example.com" +@pytest.mark.parametrize( + ("region", "country", "countrycode"), + [("eu", "DE", "49"), ("us", "US", "1")], +) +def test_local_pin_login_names_the_region_and_country_of_the_config( + tmp_path: Path, + region: str, + country: str, + countrycode: str, +) -> None: + supervisor, _paths = _build_supervisor(tmp_path, with_snapshot=False, region=region) + client = TestClient(supervisor.app) + + login_response = client.post( + "/api/v5/auth/email/login/code", + data={"country": "DE", "countryCode": "49", "email": "user@example.com", "code": "123456"}, + ) + assert login_response.status_code == 200 + login_payload = login_response.json()["data"] + # The app stores "region" as RRUser.region, and the device plugin reads it + # as serverCode in fetchCountryInfo. Without it, the plugin looks the + # country up in its own server map, fails, and retries forever. + assert login_payload["region"] == region + assert login_payload["country"] == country + assert login_payload["countrycode"] == countrycode + + def test_protected_routes_skip_protocol_auth_when_disabled(tmp_path: Path) -> None: supervisor, _paths = _build_supervisor_with_protocol_toggle(tmp_path, protocol_auth_enabled=False) client = TestClient(supervisor.app) From 36a84178b49bdac4b581a9cbebb04fd649b99fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 03:01:58 +0100 Subject: [PATCH 2/4] fix(api): answer /api/v5/product with signed agreement versions The device plugin checks the privacy agreements before it asks for the map. It reads the latest versions of its product with getProductAgreements. The app fills them from "agreements" in /api/v5/product. It reads the signed versions with getPluginAgreements. The app fills them from userPluginAgreementList in /api/v1/checkAppAgreement. The check passes only if both lists hold USER_AGREEMENT and PRIVACY_POLICY and no signed version is lower than the latest one. The route sent "agreements": [], so the check always failed. The plugin then took its privacy dialog path instead of going on to app_get_init_status and the map. Send both agreement types with the version that /api/v1/checkAppAgreement reports as signed. The entries use the cloud's shape, for example {"type": "PRIVACY_POLICY", "version": 36, "minorVersion": 0} for the a307. --- .../routes/api/product_service.py | 7 +++- .../https_server/routes/api/v1/agreement.py | 13 +++++++ tests/test_product_response.py | 39 ++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/product_service.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/product_service.py index e450d8e9..d912e2d7 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/product_service.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/product_service.py @@ -9,6 +9,7 @@ from ..plugin.common import snapshot_plugin_catalog_data from ..user.homes.service import home_payload +from .v1.agreement import product_agreements def build_product_response(ctx: ServerContext) -> dict[str, Any]: @@ -57,8 +58,10 @@ def build_product_response(ctx: ServerContext) -> dict[str, Any]: "ncMode": "global", "status": 10, # Read by PluginSDKModule.getProductAgreements; a missing field is - # null and the device plugin's privacy check never completes. - "agreements": [], + # null and the device plugin's privacy check never completes. An + # empty list fails the check and sends the plugin to its privacy + # dialog path before it requests the map. + "agreements": product_agreements(), } icon_url = product.get("iconUrl") if isinstance(icon_url, str) and icon_url: diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/agreement.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/agreement.py index 5bd4692b..7b595764 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/agreement.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/agreement.py @@ -39,6 +39,19 @@ def _home_device_ids(ctx: ServerContext) -> list[str]: return device_ids +def product_agreements() -> list[dict[str, Any]]: + """Latest agreement versions of a product, as in /api/v5/product. + + The device plugin compares these with the signed versions from + plugin_agreements(). It opens without a privacy dialog only if both lists + name both types and no signed version is lower than the latest version. + """ + return [ + {"type": agreement_type, "version": PLUGIN_AGREEMENT_VERSION, "minorVersion": 0} + for agreement_type in PLUGIN_AGREEMENT_TYPES + ] + + def plugin_agreements(ctx: ServerContext) -> list[dict[str, Any]]: """One accepted plugin agreement per agreement type and home device. diff --git a/tests/test_product_response.py b/tests/test_product_response.py index 35c05ebb..58d165b3 100644 --- a/tests/test_product_response.py +++ b/tests/test_product_response.py @@ -56,6 +56,22 @@ def _products_v5(tmp_path: Path, devices: list[dict[str, object]]) -> dict: return payload["data"] +def _plugin_agreements(tmp_path: Path) -> list[dict]: + _route, payload = resolve_route( + rules=default_endpoint_rules(), + context=_make_context(tmp_path), + clean_path="/api/v1/checkAppAgreement", + query_params={}, + body_params={}, + method="GET", + ) + return payload["data"]["userPluginAgreementList"] + + +def _versions_by_type(agreements: list[dict]) -> dict[str, int]: + return {agreement["type"]: agreement["version"] for agreement in agreements} + + _DEVICE = { "duid": "device-a", "name": "Vacuum A", @@ -74,7 +90,28 @@ def test_product_entry_carries_rriotid_category_id_and_agreements(tmp_path: Path # Product.rriotid is what the app joins the home data device's productId on. assert product["rriotid"] == "iot-product-a" assert product["categoryId"] == category["id"] - assert product["agreements"] == [] + assert [agreement["type"] for agreement in product["agreements"]] == [ + "USER_AGREEMENT", + "PRIVACY_POLICY", + ] + + +def test_product_agreements_are_signed_in_plugin_agreements(tmp_path: Path) -> None: + device = dict(_DEVICE, model="roborock.vacuum.a307") + data = _products_v5(tmp_path, [device]) + plugin_agreements = _plugin_agreements(tmp_path) + + [product] = data["categoryDetailList"][0]["productList"] + latest = _versions_by_type(product["agreements"]) + signed = _versions_by_type( + [agreement for agreement in plugin_agreements if agreement["deviceId"] == "device-a"] + ) + + # hasSignLastestPluginPrivacyAgreement in the device plugin returns true + # only if both lists name both types and every signed version is at least + # the latest version. Otherwise the plugin goes to its privacy dialog path. + for agreement_type in ("USER_AGREEMENT", "PRIVACY_POLICY"): + assert signed[agreement_type] >= latest[agreement_type] def test_product_category_carries_code(tmp_path: Path) -> None: From d91aacbec1d516482d8546ff2db13d3ff005de87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sat, 21 Nov 2026 20:02:03 +0100 Subject: [PATCH 3/4] fix(api): name the same country in getUrlByEmail and userInfo The local login answer names "DE" as the country of the EU region, but /api/v1/getUrlByEmail and /api/v1/userInfo still answered "EU". So one account showed two countries. All three routes now take the country from REGION_COUNTRY in shared/constants.py, and a country from the cloud snapshot still wins in /api/v1/userInfo. --- .../https_server/routes/api/v1/user.py | 11 ++++- .../bundled_backend/shared/constants.py | 6 +++ src/roborock_local_server/server.py | 9 +--- tests/test_protocol_auth.py | 41 +++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py index ce950a81..158a002b 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py @@ -2,6 +2,7 @@ from typing import Any +from shared.constants import REGION_COUNTRY from shared.context import ServerContext from shared.data_helpers import as_bool, get_value @@ -22,6 +23,11 @@ def _default_country_code_for_region(region: str) -> str: return _REGION_COUNTRY_CODE.get(region.upper(), "1") +def _default_country_for_region(region: str) -> str: + region_upper = region.upper() + return REGION_COUNTRY.get(region_upper, region_upper) + + def match_get_url_by_email(path: str) -> bool: return path.rstrip("/") == "/api/v1/getUrlByEmail" @@ -49,7 +55,7 @@ def build_get_url_by_email( { "url": ctx.api_url(), "countrycode": _default_country_code_for_region(region_upper), - "country": region_upper, + "country": _default_country_for_region(region_upper), } ) @@ -77,7 +83,8 @@ def build_user_info( mobile = username region_upper = ctx.region.upper() - country = str(get_value(cloud_user_data, "country", default=region_upper) or region_upper) + default_country = _default_country_for_region(region_upper) + country = str(get_value(cloud_user_data, "country", default=default_country) or default_country) countrycode = str( get_value( cloud_user_data, diff --git a/src/roborock_local_server/bundled_backend/shared/constants.py b/src/roborock_local_server/bundled_backend/shared/constants.py index 561bb070..27805c0c 100644 --- a/src/roborock_local_server/bundled_backend/shared/constants.py +++ b/src/roborock_local_server/bundled_backend/shared/constants.py @@ -133,6 +133,12 @@ "roborock.vacuum.sc05": 10001, } +# The login and user answers name a country, and "EU" is none. The EU cloud +# answers "DE", which fits the dialing code 49. +REGION_COUNTRY = { + "EU": "DE", +} + MQTT_TYPES = { 1: "CONNECT", 2: "CONNACK", diff --git a/src/roborock_local_server/server.py b/src/roborock_local_server/server.py index 90b37d14..420cde2c 100644 --- a/src/roborock_local_server/server.py +++ b/src/roborock_local_server/server.py @@ -24,7 +24,7 @@ from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware from .certs import CertificateManager -from .bundled_backend.shared.constants import DEFAULT_PRODUCT_SCHEMA +from .bundled_backend.shared.constants import DEFAULT_PRODUCT_SCHEMA, REGION_COUNTRY from .bundled_backend.shared.data_helpers import utcnow_iso from .product_registry import resolve_product_metadata from .bundled_backend.shared.runtime_state import ONBOARDING_STEP_LABELS, REQUIRED_ONBOARDING_STEPS @@ -74,11 +74,6 @@ "EU": "49", "RU": "7", } -# The login answer names a country, and "EU" is none. The EU cloud answers -# "DE", which fits the dialing code 49. -_REGION_COUNTRY = { - "EU": "DE", -} PROJECT_SUPPORT = { "title": "Support This Project", "text": ( @@ -604,7 +599,7 @@ def _local_protocol_identity(self) -> dict[str, Any]: # The app keeps "region" as RRUser.region. The device plugin needs # it in fetchCountryInfo and retries forever without it. "region": region, - "country": _REGION_COUNTRY.get(region_upper, region_upper), + "country": REGION_COUNTRY.get(region_upper, region_upper), "countrycode": self._default_country_code_for_region(region_upper), "nickname": "Local User", "hasPassword": True, diff --git a/tests/test_protocol_auth.py b/tests/test_protocol_auth.py index 7baba69b..0c9dd85d 100644 --- a/tests/test_protocol_auth.py +++ b/tests/test_protocol_auth.py @@ -261,6 +261,47 @@ def test_local_pin_login_names_the_region_and_country_of_the_config( assert login_payload["countrycode"] == countrycode +@pytest.mark.parametrize(("region", "country"), [("eu", "DE"), ("us", "US")]) +def test_url_and_user_info_routes_name_the_country_of_the_login_answer( + tmp_path: Path, + region: str, + country: str, +) -> None: + supervisor, _paths = _build_supervisor(tmp_path, with_snapshot=False, region=region) + client = TestClient(supervisor.app) + + login_response = client.post( + "/api/v5/auth/email/login/code", + data={"email": "user@example.com", "code": "123456"}, + ) + assert login_response.status_code == 200 + login_payload = login_response.json()["data"] + assert login_payload["country"] == country + + url_response = client.post("/api/v1/getUrlByEmail", data={"email": "user@example.com"}) + assert url_response.status_code == 200 + assert url_response.json()["data"]["country"] == country + + user_info = client.get("/api/v1/userInfo", headers=_token_headers(login_payload)) + assert user_info.status_code == 200 + assert user_info.json()["data"]["country"] == country + + +def test_user_info_prefers_the_country_of_the_cloud_snapshot(tmp_path: Path) -> None: + supervisor, paths = _build_supervisor(tmp_path, region="eu") + snapshot = json.loads(paths.cloud_snapshot_path.read_text(encoding="utf-8")) + snapshot["user_data"]["country"] = "AT" + _write_json(paths.cloud_snapshot_path, snapshot) + client = TestClient(supervisor.app) + + user_info = client.get( + "/api/v1/userInfo", + headers={"Authorization": "local-token-123", "header_username": "local-rruid-123"}, + ) + assert user_info.status_code == 200 + assert user_info.json()["data"]["country"] == "AT" + + def test_protected_routes_skip_protocol_auth_when_disabled(tmp_path: Path) -> None: supervisor, _paths = _build_supervisor_with_protocol_toggle(tmp_path, protocol_auth_enabled=False) client = TestClient(supervisor.app) From 5b4eae292867373b1e4738aed5fedc3017101189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20R=2E=20H=C3=B6lzlwimmer?= Date: Sun, 22 Nov 2026 17:55:14 +0100 Subject: [PATCH 4/4] refactor(api): name the country and dialing code of a region in one place server.py and routes/api/v1/user.py each had a table of dialing codes and a helper, and REGION_COUNTRY in shared.constants named the country. One table in shared.constants now holds both, and region_country returns them. The login, getUrlByEmail and userInfo answers use it, and a test checks that all three name the same dialing code. --- .../https_server/routes/api/v1/user.py | 35 ++++--------------- .../bundled_backend/shared/constants.py | 16 +++++++-- src/roborock_local_server/server.py | 17 +++------ tests/test_protocol_auth.py | 11 +++--- 4 files changed, 30 insertions(+), 49 deletions(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py index 158a002b..738e00ae 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/api/v1/user.py @@ -2,7 +2,7 @@ from typing import Any -from shared.constants import REGION_COUNTRY +from shared.constants import region_country from shared.context import ServerContext from shared.data_helpers import as_bool, get_value @@ -11,21 +11,6 @@ from ...auth.service import ok _DEFAULT_AVATAR_URL = "https://files.roborock.com/iot/default_avatar.png" -_REGION_COUNTRY_CODE = { - "US": "1", - "CN": "86", - "EU": "49", - "RU": "7", -} - - -def _default_country_code_for_region(region: str) -> str: - return _REGION_COUNTRY_CODE.get(region.upper(), "1") - - -def _default_country_for_region(region: str) -> str: - region_upper = region.upper() - return REGION_COUNTRY.get(region_upper, region_upper) def match_get_url_by_email(path: str) -> bool: @@ -50,12 +35,12 @@ def build_get_url_by_email( _body_params: dict[str, list[str]], _clean_path: str, ) -> dict[str, Any]: - region_upper = ctx.region.upper() + country, countrycode = region_country(ctx.region) return ok( { "url": ctx.api_url(), - "countrycode": _default_country_code_for_region(region_upper), - "country": _default_country_for_region(region_upper), + "countrycode": countrycode, + "country": country, } ) @@ -82,17 +67,9 @@ def build_user_info( if not mobile and username.isdigit(): mobile = username - region_upper = ctx.region.upper() - default_country = _default_country_for_region(region_upper) + default_country, default_countrycode = region_country(ctx.region) country = str(get_value(cloud_user_data, "country", default=default_country) or default_country) - countrycode = str( - get_value( - cloud_user_data, - "countrycode", - default=_default_country_code_for_region(region_upper), - ) - or _default_country_code_for_region(region_upper) - ) + countrycode = str(get_value(cloud_user_data, "countrycode", default=default_countrycode) or default_countrycode) nickname = str(get_value(cloud_user_data, "nickname", default="Local User") or "Local User") avatarurl = str(get_value(cloud_user_data, "avatarurl", "avatarUrl", default="") or "") if not avatarurl: diff --git a/src/roborock_local_server/bundled_backend/shared/constants.py b/src/roborock_local_server/bundled_backend/shared/constants.py index 27805c0c..12c2fd91 100644 --- a/src/roborock_local_server/bundled_backend/shared/constants.py +++ b/src/roborock_local_server/bundled_backend/shared/constants.py @@ -133,12 +133,22 @@ "roborock.vacuum.sc05": 10001, } -# The login and user answers name a country, and "EU" is none. The EU cloud -# answers "DE", which fits the dialing code 49. +# The login and user answers name a country and its dialing code. "EU" is no +# country, so the EU cloud answers "DE", which fits the dialing code 49. REGION_COUNTRY = { - "EU": "DE", + "US": ("US", "1"), + "CN": ("CN", "86"), + "EU": ("DE", "49"), + "RU": ("RU", "7"), } + +def region_country(region: str) -> tuple[str, str]: + """Return the country and its dialing code for a cloud region.""" + region_upper = str(region or "").upper() + return REGION_COUNTRY.get(region_upper, (region_upper, "1")) + + MQTT_TYPES = { 1: "CONNECT", 2: "CONNACK", diff --git a/src/roborock_local_server/server.py b/src/roborock_local_server/server.py index 420cde2c..0d293e0d 100644 --- a/src/roborock_local_server/server.py +++ b/src/roborock_local_server/server.py @@ -24,7 +24,7 @@ from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware from .certs import CertificateManager -from .bundled_backend.shared.constants import DEFAULT_PRODUCT_SCHEMA, REGION_COUNTRY +from .bundled_backend.shared.constants import DEFAULT_PRODUCT_SCHEMA, region_country from .bundled_backend.shared.data_helpers import utcnow_iso from .product_registry import resolve_product_metadata from .bundled_backend.shared.runtime_state import ONBOARDING_STEP_LABELS, REQUIRED_ONBOARDING_STEPS @@ -68,12 +68,6 @@ ALL_HTTP_METHODS = ("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") PROTOCOL_AUTH_SYNC_PATH = "/internal/protocol/user-data" PROTOCOL_AUTH_SYNC_SECRET_HEADER = "x-local-sync-secret" -_REGION_COUNTRY_CODE = { - "US": "1", - "CN": "86", - "EU": "49", - "RU": "7", -} PROJECT_SUPPORT = { "title": "Support This Project", "text": ( @@ -581,10 +575,6 @@ def _protocol_login_pin_matches(self, pin: str) -> bool: self.config.admin.protocol_login_pin_hash, ) - @staticmethod - def _default_country_code_for_region(region: str) -> str: - return _REGION_COUNTRY_CODE.get(str(region or "").upper(), "1") - def _local_protocol_identity(self) -> dict[str, Any]: email = self._protocol_login_email() normalized_email = email.casefold() @@ -592,6 +582,7 @@ def _local_protocol_identity(self) -> dict[str, Any]: uid = (int(digest[:12], 16) % 900_000_000) + 100_000_000 region = self.config.network.region.lower() region_upper = region.upper() + country, countrycode = region_country(region) return { "uid": uid, "rruid": f"rrls-{digest[:20]}", @@ -599,8 +590,8 @@ def _local_protocol_identity(self) -> dict[str, Any]: # The app keeps "region" as RRUser.region. The device plugin needs # it in fetchCountryInfo and retries forever without it. "region": region, - "country": REGION_COUNTRY.get(region_upper, region_upper), - "countrycode": self._default_country_code_for_region(region_upper), + "country": country, + "countrycode": countrycode, "nickname": "Local User", "hasPassword": True, "rriot": { diff --git a/tests/test_protocol_auth.py b/tests/test_protocol_auth.py index 0c9dd85d..67921133 100644 --- a/tests/test_protocol_auth.py +++ b/tests/test_protocol_auth.py @@ -261,11 +261,12 @@ def test_local_pin_login_names_the_region_and_country_of_the_config( assert login_payload["countrycode"] == countrycode -@pytest.mark.parametrize(("region", "country"), [("eu", "DE"), ("us", "US")]) +@pytest.mark.parametrize(("region", "country", "countrycode"), [("eu", "DE", "49"), ("us", "US", "1")]) def test_url_and_user_info_routes_name_the_country_of_the_login_answer( tmp_path: Path, region: str, country: str, + countrycode: str, ) -> None: supervisor, _paths = _build_supervisor(tmp_path, with_snapshot=False, region=region) client = TestClient(supervisor.app) @@ -276,15 +277,17 @@ def test_url_and_user_info_routes_name_the_country_of_the_login_answer( ) assert login_response.status_code == 200 login_payload = login_response.json()["data"] - assert login_payload["country"] == country + assert (login_payload["country"], login_payload["countrycode"]) == (country, countrycode) url_response = client.post("/api/v1/getUrlByEmail", data={"email": "user@example.com"}) assert url_response.status_code == 200 - assert url_response.json()["data"]["country"] == country + url_data = url_response.json()["data"] + assert (url_data["country"], url_data["countrycode"]) == (country, countrycode) user_info = client.get("/api/v1/userInfo", headers=_token_headers(login_payload)) assert user_info.status_code == 200 - assert user_info.json()["data"]["country"] == country + user_data = user_info.json()["data"] + assert (user_data["country"], user_data["countrycode"]) == (country, countrycode) def test_user_info_prefers_the_country_of_the_cloud_snapshot(tmp_path: Path) -> None: