From 51e0f136d67359bc0bb1fd78fcbde85a6471a051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 9 Oct 2026 21:59:44 +0500 Subject: [PATCH] feat(phase15): release and security hardening, DPAPI key store, probe & protocol hardening, secret redaction, audit and readiness report --- README.md | 13 +- crates/coa-control-proto/src/app.rs | 217 ++- crates/coa-control-proto/src/coord.rs | 235 ++- crates/coa-control-proto/src/lib.rs | 1 - crates/coa-control-proto/src/noise.rs | 212 ++- crates/coa-control-proto/src/relay.rs | 83 +- .../coa-control-proto/tests/hostile_input.rs | 266 +++ crates/coa-core/examples/backup_e2e.rs | 64 +- crates/coa-core/examples/client_probe.rs | 60 +- crates/coa-core/examples/client_scan.rs | 6 +- crates/coa-core/examples/companions_e2e.rs | 20 +- crates/coa-core/examples/config_check.rs | 41 +- .../coa-core/examples/coordinated_package.rs | 64 +- .../examples/coordinated_squid_e2e.rs | 101 +- .../examples/coordinated_update_e2e.rs | 129 +- crates/coa-core/examples/dl.rs | 11 +- crates/coa-core/examples/docker_install.rs | 30 +- crates/coa-core/examples/drive.rs | 4 +- .../coa-core/examples/hotfix_history_e2e.rs | 176 +- .../coa-core/examples/hotfix_preview_e2e.rs | 51 +- .../examples/hotfix_transition_e2e.rs | 374 ++-- crates/coa-core/examples/install_e2e.rs | 112 +- crates/coa-core/examples/install_pkg.rs | 18 +- crates/coa-core/examples/install_url.rs | 18 +- crates/coa-core/examples/keygen.rs | 21 +- crates/coa-core/examples/migrate_e2e.rs | 114 +- crates/coa-core/examples/mkpkg.rs | 43 +- crates/coa-core/examples/multiworld_e2e.rs | 53 +- crates/coa-core/examples/net_check.rs | 11 +- crates/coa-core/examples/portable_smoke.rs | 488 ++++- crates/coa-core/examples/ra_account.rs | 7 +- crates/coa-core/examples/realm_e2e.rs | 89 +- crates/coa-core/examples/repair_e2e.rs | 103 +- crates/coa-core/examples/rq.rs | 9 +- crates/coa-core/examples/scan.rs | 4 +- crates/coa-core/examples/schema_e2e.rs | 22 +- crates/coa-core/examples/sign.rs | 19 +- crates/coa-core/examples/sqlq.rs | 5 +- crates/coa-core/examples/update_e2e.rs | 107 +- .../coa-core/examples/update_recovery_e2e.rs | 137 +- .../coa-core/examples/update_startup_e2e.rs | 21 +- crates/coa-core/examples/update_url.rs | 50 +- crates/coa-core/examples/verify.rs | 4 +- .../coa-core/examples/wildcard_repair_e2e.rs | 115 +- crates/coa-core/src/accounts.rs | 97 +- crates/coa-core/src/allsettings.rs | 158 +- crates/coa-core/src/backup.rs | 428 ++++- crates/coa-core/src/cleanbase.rs | 236 ++- crates/coa-core/src/client.rs | 475 ++++- crates/coa-core/src/clientdl.rs | 417 ++++- crates/coa-core/src/companions.rs | 44 +- crates/coa-core/src/config/merge.rs | 23 +- crates/coa-core/src/config/mod.rs | 664 +++++-- crates/coa-core/src/config/parser.rs | 94 +- crates/coa-core/src/config/schema.rs | 50 +- crates/coa-core/src/console.rs | 50 +- crates/coa-core/src/control/backend.rs | 139 +- crates/coa-core/src/control/direct_ingress.rs | 114 +- crates/coa-core/src/control/direct_route.rs | 188 +- crates/coa-core/src/control/host_link.rs | 187 +- crates/coa-core/src/control/host_manager.rs | 123 +- crates/coa-core/src/control/identity.rs | 47 +- crates/coa-core/src/control/join.rs | 298 ++- crates/coa-core/src/control/mod.rs | 1 - crates/coa-core/src/control/nat_pmp.rs | 16 +- crates/coa-core/src/control/player.rs | 50 +- crates/coa-core/src/control/relay_link.rs | 69 +- crates/coa-core/src/control/secrets.rs | 137 +- crates/coa-core/src/control/service.rs | 1582 +++++++++++++--- crates/coa-core/src/control/store.rs | 236 ++- crates/coa-core/src/control/transport.rs | 79 +- crates/coa-core/src/dashboard.rs | 292 ++- crates/coa-core/src/db.rs | 317 +++- crates/coa-core/src/diag.rs | 832 +++++++-- crates/coa-core/src/docker/cli.rs | 41 +- crates/coa-core/src/docker/fixture.rs | 36 +- crates/coa-core/src/docker/install.rs | 473 ++++- crates/coa-core/src/docker/lifecycle.rs | 750 ++++++-- crates/coa-core/src/docker/mod.rs | 146 +- crates/coa-core/src/download.rs | 175 +- crates/coa-core/src/driver.rs | 236 ++- crates/coa-core/src/error.rs | 19 +- crates/coa-core/src/firewall.rs | 80 +- crates/coa-core/src/friends.rs | 256 ++- crates/coa-core/src/fsx.rs | 105 +- crates/coa-core/src/health.rs | 38 +- crates/coa-core/src/install.rs | 260 ++- crates/coa-core/src/layout.rs | 244 ++- crates/coa-core/src/lib.rs | 39 +- crates/coa-core/src/logging.rs | 47 +- crates/coa-core/src/manifest.rs | 56 +- crates/coa-core/src/migrations.rs | 419 ++++- crates/coa-core/src/modules.rs | 726 ++++++-- crates/coa-core/src/multiworld.rs | 244 ++- crates/coa-core/src/net.rs | 220 ++- crates/coa-core/src/package.rs | 363 +++- crates/coa-core/src/pkgsource.rs | 52 +- crates/coa-core/src/population.rs | 108 +- crates/coa-core/src/portable/capabilities.rs | 357 +++- crates/coa-core/src/portable/collection.rs | 66 +- crates/coa-core/src/portable/compat.rs | 522 +++++- crates/coa-core/src/portable/error.rs | 51 +- crates/coa-core/src/portable/extension.rs | 356 +++- crates/coa-core/src/portable/fixtures.rs | 156 +- crates/coa-core/src/portable/ids.rs | 65 +- crates/coa-core/src/portable/merge.rs | 681 +++++-- crates/coa-core/src/portable/merge/tests.rs | 403 +++- crates/coa-core/src/portable/mod.rs | 4 +- crates/coa-core/src/portable/model.rs | 136 +- .../coa-core/src/portable/projection/mod.rs | 114 +- .../src/portable/projection/settings.rs | 74 +- .../src/portable/projection/testing.rs | 65 +- .../coa-core/src/portable/projection/tests.rs | 285 ++- .../coa-core/src/portable/realm/blockers.rs | 29 +- .../src/portable/realm/collections.rs | 81 +- crates/coa-core/src/portable/realm/export.rs | 279 ++- crates/coa-core/src/portable/realm/import.rs | 442 ++++- .../src/portable/realm/import_tests.rs | 457 ++++- .../coa-core/src/portable/realm/knowledge.rs | 63 +- crates/coa-core/src/portable/realm/live.rs | 127 +- .../src/portable/realm/live_import.rs | 626 +++++-- .../src/portable/realm/live_profile.rs | 224 ++- .../src/portable/realm/live_projection.rs | 238 ++- .../src/portable/realm/live_roundtrip.rs | 432 ++++- .../src/portable/realm/live_update.rs | 803 ++++++-- .../src/portable/realm/live_wardrobe.rs | 227 ++- crates/coa-core/src/portable/realm/mod.rs | 145 +- crates/coa-core/src/portable/realm/online.rs | 227 ++- crates/coa-core/src/portable/realm/plan.rs | 510 +++++- crates/coa-core/src/portable/realm/policy.rs | 61 +- crates/coa-core/src/portable/realm/profile.rs | 167 +- crates/coa-core/src/portable/realm/project.rs | 224 ++- .../coa-core/src/portable/realm/reconcile.rs | 736 ++++++-- .../coa-core/src/portable/realm/registry.rs | 108 +- crates/coa-core/src/portable/realm/script.rs | 433 ++++- crates/coa-core/src/portable/realm/sqlenc.rs | 155 +- crates/coa-core/src/portable/realm/tests.rs | 654 ++++++- crates/coa-core/src/portable/realm/update.rs | 668 +++++-- .../src/portable/realm/update_tests.rs | 374 +++- .../coa-core/src/portable/realm/wardrobe.rs | 83 +- .../coa-core/src/portable/service/access.rs | 110 +- .../src/portable/service/delta_probe.rs | 25 +- .../coa-core/src/portable/service/engine.rs | 971 ++++++++-- .../src/portable/service/live_service.rs | 360 +++- .../coa-core/src/portable/service/runtime.rs | 35 +- crates/coa-core/src/portable/service/view.rs | 22 +- .../coa-core/src/portable/session/bridge.rs | 25 +- .../src/portable/session/collection_tests.rs | 469 ++++- crates/coa-core/src/portable/session/fake.rs | 179 +- crates/coa-core/src/portable/session/host.rs | 570 +++++- crates/coa-core/src/portable/session/live.rs | 113 +- .../src/portable/session/live_projection.rs | 463 ++++- .../src/portable/session/live_session.rs | 707 +++++-- crates/coa-core/src/portable/session/mod.rs | 12 +- crates/coa-core/src/portable/session/owner.rs | 21 +- .../src/portable/session/profile_tests.rs | 237 ++- .../src/portable/session/projection_tests.rs | 383 +++- .../coa-core/src/portable/session/protocol.rs | 181 +- crates/coa-core/src/portable/session/tests.rs | 672 +++++-- crates/coa-core/src/portable/snapshot.rs | 209 ++- crates/coa-core/src/portable/store.rs | 762 ++++++-- crates/coa-core/src/portable/store/host.rs | 506 ++++- crates/coa-core/src/portable/store/journal.rs | 282 ++- crates/coa-core/src/portable/store/owner.rs | 260 ++- crates/coa-core/src/portable/store/profile.rs | 105 +- .../coa-core/src/portable/store/projection.rs | 72 +- crates/coa-core/src/portable/store/sync.rs | 295 ++- crates/coa-core/src/portable/store/tests.rs | 1353 +++++++++++--- crates/coa-core/src/process.rs | 149 +- crates/coa-core/src/ra.rs | 227 ++- crates/coa-core/src/realm_registry/advert.rs | 231 ++- crates/coa-core/src/realm_registry/browse.rs | 79 +- crates/coa-core/src/realm_registry/client.rs | 104 +- crates/coa-core/src/realm_registry/host.rs | 258 ++- crates/coa-core/src/realm_registry/keys.rs | 265 ++- crates/coa-core/src/realm_registry/runtime.rs | 104 +- .../coa-core/src/realm_registry/settings.rs | 108 +- crates/coa-core/src/realmlist.rs | 211 ++- crates/coa-core/src/realms.rs | 382 +++- crates/coa-core/src/registry.rs | 61 +- crates/coa-core/src/release.rs | 239 ++- crates/coa-core/src/release_schema.rs | 215 ++- crates/coa-core/src/remote_client.rs | 52 +- crates/coa-core/src/repair.rs | 223 ++- crates/coa-core/src/report.rs | 82 +- crates/coa-core/src/schema_check.rs | 217 ++- crates/coa-core/src/signing.rs | 8 +- crates/coa-core/src/squid.rs | 202 +- crates/coa-core/src/srp6.rs | 9 +- crates/coa-core/src/update.rs | 1628 ++++++++++++++--- crates/coa-core/src/upnp.rs | 113 +- crates/coa-registry-proto/src/browse.rs | 176 +- crates/coa-registry-proto/src/caps.rs | 125 +- crates/coa-registry-proto/src/sign.rs | 239 ++- crates/coa-registry-proto/src/wire.rs | 269 ++- crates/coa-release/src/main.rs | 154 +- docs/RELEASE_HARDENING_AUDIT.md | 99 + docs/RELEASE_READINESS.md | 139 ++ docs/THIRD_PARTY_NOTICES.md | 63 + .../tests/phase14_direct_and_relay.rs | 6 + services/coa-coordinator/src/lib.rs | 37 +- services/coa-coordinator/tests/coord.rs | 43 + services/coa-registry/deploy/backup-db.sh | 40 + services/coa-registry/deploy/restore-db.sh | 40 + services/coa-relay/src/hub.rs | 2 +- src-tauri/src/control_cmds.rs | 397 ++-- src-tauri/src/lib.rs | 1398 +++++++++++--- 207 files changed, 38235 insertions(+), 7770 deletions(-) create mode 100644 crates/coa-control-proto/tests/hostile_input.rs create mode 100644 docs/RELEASE_HARDENING_AUDIT.md create mode 100644 docs/RELEASE_READINESS.md create mode 100644 docs/THIRD_PARTY_NOTICES.md create mode 100644 services/coa-registry/deploy/backup-db.sh create mode 100644 services/coa-registry/deploy/restore-db.sh diff --git a/README.md b/README.md index 928fa27..c92268b 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,16 @@ Manager at the one you have, or let it download one for you. ## Status -Phases 0–10 of the plan in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) are done: foundation, import, start/stop, -config engine, backups, clean install from signed packages, updates, companions, client launch, friends, polish. -Remaining work (translation review by native speakers, optional extras) is listed in section 9 of that document. Translation notes: [docs/TRANSLATIONS.md](docs/TRANSLATIONS.md). +Phases 0–15 are complete: foundation, import, start/stop, config engine, backups, clean install from signed packages, +updates, companions, client launch, friends, public registry, end-to-end control plane (Noise XX), portable characters +with remote transfer and level projection, game relay fallback, verified direct connectivity (UPnP / NAT-PMP), +and security/release hardening. + +### Known Limitations +* **Native client login prefill**: Ascension's 3.3.5 client does not accept command-line credentials; users type their password once or link an existing account. +* **Non-Windows SecretStore**: Windows uses DPAPI (`CryptProtectData`) with domain separation entropy. On Linux/macOS, keys fall back to strict 0600 file permissions. +* **Direct to Relay migration**: Established direct TCP sessions cannot migrate mid-stream to Relay; network breaks trigger automatic fallback on the next JOIN. +* **WorkerThreads**: `CharacterDatabase.WorkerThreads` must be set to `1` (the default) for safe remote portable character imports. ## Develop ``` diff --git a/crates/coa-control-proto/src/app.rs b/crates/coa-control-proto/src/app.rs index 37dee1e..cbbc792 100644 --- a/crates/coa-control-proto/src/app.rs +++ b/crates/coa-control-proto/src/app.rs @@ -18,7 +18,10 @@ pub const MAX_CHARACTERS: usize = 200; /// A game account name: 3 to 16 ASCII letters, digits or `_`, not beginning or ending with `_`. pub fn valid_username(s: &str) -> bool { - (MIN_USERNAME..=MAX_USERNAME).contains(&s.len()) && s.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_') && !s.starts_with('_') && !s.ends_with('_') + (MIN_USERNAME..=MAX_USERNAME).contains(&s.len()) + && s.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_') + && !s.starts_with('_') + && !s.ends_with('_') } /// A game account password: 8 to 16 ASCII letters and digits (the game compares passwords case-insensitively, so letters carry no extra strength; digits and length do). @@ -43,17 +46,28 @@ pub fn generate_password() -> String { /// The account name wanted, made fit for the game: letters and digits only, upper case, at most 16 characters. pub fn sanitize_username(wanted: &str) -> String { - let base: String = wanted.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_uppercase(); + let base: String = wanted + .chars() + .filter(char::is_ascii_alphanumeric) + .collect::() + .to_ascii_uppercase(); let base: String = base.chars().take(MAX_USERNAME).collect(); - if base.len() >= MIN_USERNAME { base } else { format!("{base}PLAYER").chars().take(MAX_USERNAME).collect() } + if base.len() >= MIN_USERNAME { + base + } else { + format!("{base}PLAYER").chars().take(MAX_USERNAME).collect() + } } /// The stable alternative of an occupied name: `DMITRY` becomes `DMITRY_7K4M`. The suffix is derived from the player's id, so the same player gets the same alternative. pub fn alternative_username(base: &str, player: &Uuid, attempt: u32) -> String { const ALPHABET: &[u8; 32] = b"ABCDEFGHJKLMNPQRSTUVWXYZ23456789"; let bytes = player.as_bytes(); - let mix = u32::from_be_bytes([bytes[12], bytes[13], bytes[14], bytes[15]]).wrapping_add(attempt.wrapping_mul(0x9E37_79B1)); - let suffix: String = (0..4).map(|i| ALPHABET[((mix >> (i * 5)) & 31) as usize] as char).collect(); + let mix = u32::from_be_bytes([bytes[12], bytes[13], bytes[14], bytes[15]]) + .wrapping_add(attempt.wrapping_mul(0x9E37_79B1)); + let suffix: String = (0..4) + .map(|i| ALPHABET[((mix >> (i * 5)) & 31) as usize] as char) + .collect(); let keep = MAX_USERNAME - 5; let head: String = base.chars().take(keep).collect(); format!("{head}_{suffix}") @@ -62,14 +76,28 @@ pub fn alternative_username(base: &str, player: &Uuid, attempt: u32) -> String { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "op", rename_all = "snake_case", deny_unknown_fields)] pub enum Request { - Hello { protocol: u32, client: String }, + Hello { + protocol: u32, + client: String, + }, /// Make the player's account on this realm, or reuse it. `password` is the one the player's Manager keeps for this realm; it travels only inside the channel. - Provision { desired: Option, password: String, have_credentials: bool }, + Provision { + desired: Option, + password: String, + have_credentials: bool, + }, ListCharacters, - Claim { token: u32 }, - ClaimAck { character_id: Uuid }, + Claim { + token: u32, + }, + ClaimAck { + character_id: Uuid, + }, /// Link an account the realm already has (one time). - Link { login: String, password: String }, + Link { + login: String, + password: String, + }, Route, /// Phase 12.1: Start or resume a remote portable character transfer. TransferOffer { @@ -105,7 +133,6 @@ pub enum Request { }, } - #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum AppError { @@ -144,19 +171,45 @@ pub struct CharacterEntry { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "op", rename_all = "snake_case")] pub enum Response { - Welcome { realm_id: coa_registry_proto::RealmId, automatic: bool, existing_only: bool, route: Option }, - Provisioned { username: String, created: bool, reset: bool }, - Characters { characters: Vec }, + Welcome { + realm_id: coa_registry_proto::RealmId, + automatic: bool, + existing_only: bool, + route: Option, + }, + Provisioned { + username: String, + created: bool, + reset: bool, + }, + Characters { + characters: Vec, + }, /// The character as the Host exported it: `payload` is the base64 of the encoded portable snapshot, `sha256` the hash of its canonical JSON, `collections` the account's /// appearance and vanity ids the Host holds for the account (kind -> ids). - Claimed { character_id: Uuid, sha256: String, payload: String, collections: BTreeMap> }, - Linked { username: String }, + Claimed { + character_id: Uuid, + sha256: String, + payload: String, + collections: BTreeMap>, + }, + Linked { + username: String, + }, Done, - RouteInfo { address: Option }, + RouteInfo { + address: Option, + }, /// The Host is ready to receive transfer chunks (or indicates an offset to resume from). - TransferReady { transfer_id: Uuid, received_offset: usize }, + TransferReady { + transfer_id: Uuid, + received_offset: usize, + }, /// Acknowledgement of a transfer chunk. - TransferChunkAck { transfer_id: Uuid, received_offset: usize }, + TransferChunkAck { + transfer_id: Uuid, + received_offset: usize, + }, /// Successful commit and session arm. TransferCommitted { transfer_id: Uuid, @@ -174,10 +227,12 @@ pub enum Response { token: String, expires_at: i64, }, - Error { code: AppError, message: String }, + Error { + code: AppError, + message: String, + }, } - pub fn encode_request(r: &Request) -> Vec { serde_json::to_vec(r).expect("a request serialises") } @@ -186,13 +241,26 @@ pub fn decode_request(bytes: &[u8]) -> Result { if bytes.len() > MAX_TRANSFER_REQUEST_BYTES { return Err(ControlError::Limit("a request is too long".into())); } - let r: Request = serde_json::from_slice(bytes).map_err(|_| ControlError::Invalid("a request is not valid".into()))?; - if !matches!(&r, Request::TransferOffer { .. } | Request::TransferChunk { .. }) && bytes.len() > MAX_CONTROL_REQUEST_BYTES { - return Err(ControlError::Limit("a standard control request exceeds 4096 bytes".into())); + let r: Request = serde_json::from_slice(bytes) + .map_err(|_| ControlError::Invalid("a request is not valid".into()))?; + if !matches!( + &r, + Request::TransferOffer { .. } | Request::TransferChunk { .. } + ) && bytes.len() > MAX_CONTROL_REQUEST_BYTES + { + return Err(ControlError::Limit( + "a standard control request exceeds 4096 bytes".into(), + )); } match &r { - Request::Provision { desired, password, .. } => { - if !valid_password(password) || desired.as_deref().is_some_and(|d| d.len() > 64 || d.chars().any(char::is_control)) { + Request::Provision { + desired, password, .. + } => { + if !valid_password(password) + || desired + .as_deref() + .is_some_and(|d| d.len() > 64 || d.chars().any(char::is_control)) + { return invalid("a provisioning request has an unusable password or name"); } } @@ -201,20 +269,41 @@ pub fn decode_request(bytes: &[u8]) -> Result { return invalid("a link request has an unusable login or password"); } } - Request::Hello { client, .. } if client.len() > 64 => return invalid("the client name is too long"), - Request::TransferOffer { content_hash, total_size, collections, .. } => { + Request::Hello { client, .. } if client.len() > 64 => { + return invalid("the client name is too long") + } + Request::TransferOffer { + content_hash, + total_size, + collections, + .. + } => { if content_hash.len() != 64 || !content_hash.chars().all(|c| c.is_ascii_hexdigit()) { return invalid("transfer content hash must be 64 hex characters"); } if *total_size > crate::noise::MAX_MESSAGE_BYTES { - return Err(ControlError::Limit("transfer total size is too large".into())); + return Err(ControlError::Limit( + "transfer total size is too large".into(), + )); + } + if collections.len() > 1000 { + return Err(ControlError::Limit( + "collections dictionary exceeds 1,000 keys".into(), + )); } let total_items: usize = collections.values().map(|v| v.len()).sum(); if total_items > 100_000 { - return Err(ControlError::Limit("collection mapping exceeds 100,000 entries".into())); + return Err(ControlError::Limit( + "collection mapping exceeds 100,000 entries".into(), + )); } } - Request::TransferChunk { data, .. } => { + Request::TransferChunk { offset, data, .. } => { + if *offset > MAX_TRANSFER_REQUEST_BYTES { + return Err(ControlError::Limit( + "transfer chunk offset exceeds limit".into(), + )); + } if data.len() > MAX_TRANSFER_REQUEST_BYTES { return Err(ControlError::Limit("transfer chunk is too large".into())); } @@ -226,7 +315,9 @@ pub fn decode_request(bytes: &[u8]) -> Result { /// An existing account's password may be anything the game accepts (6 to 16 printable characters without spaces or quotes). pub fn valid_password_for_link(s: &str) -> bool { - (6..=16).contains(&s.len()) && s.chars().all(|c| c.is_ascii_graphic() && c != '"' && c != '\'' && c != '\\') + (6..=16).contains(&s.len()) + && s.chars() + .all(|c| c.is_ascii_graphic() && c != '"' && c != '\'' && c != '\\') } pub fn encode_response(r: &Response) -> Vec { @@ -234,7 +325,11 @@ pub fn encode_response(r: &Response) -> Vec { } pub fn decode_response(bytes: &[u8]) -> Result { - serde_json::from_slice(bytes).map_err(|_| ControlError::Invalid("a response is not valid".into())) + if bytes.len() > MAX_TRANSFER_REQUEST_BYTES { + return Err(ControlError::Limit("a response is too long".into())); + } + serde_json::from_slice(bytes) + .map_err(|_| ControlError::Invalid("a response is not valid".into())) } #[cfg(test)] @@ -246,12 +341,20 @@ mod tests { let a = generate_password(); let b = generate_password(); assert_ne!(a, b); - assert!(valid_password(&a) && a.len() == 16 && a.bytes().all(|c| c.is_ascii_uppercase() || c.is_ascii_digit()), "{a}"); + assert!( + valid_password(&a) + && a.len() == 16 + && a.bytes() + .all(|c| c.is_ascii_uppercase() || c.is_ascii_digit()), + "{a}" + ); let mut seen = std::collections::HashSet::new(); for _ in 0..200 { assert!(seen.insert(generate_password()), "no repeats"); } - let symbols: std::collections::HashSet = (0..200).flat_map(|_| generate_password().chars().collect::>()).collect(); + let symbols: std::collections::HashSet = (0..200) + .flat_map(|_| generate_password().chars().collect::>()) + .collect(); assert_eq!(symbols.len(), 36, "every symbol occurs"); } @@ -260,21 +363,45 @@ mod tests { assert_eq!(sanitize_username("Dmitry"), "DMITRY"); assert_eq!(sanitize_username("d m-i_t.r y"), "DMITRY"); assert_eq!(sanitize_username("ab"), "ABPLAYER"); - assert_eq!(sanitize_username("a very long player name indeed"), "AVERYLONGPLAYERN"); + assert_eq!( + sanitize_username("a very long player name indeed"), + "AVERYLONGPLAYERN" + ); assert_eq!(sanitize_username("