PONGo_ios/AuthModels.swift
Jon Vanvik 203465913c Apply code-review fixes: identity/pagination, load races, TLS pin, leaks
Addresses a multi-agent code review (26 confirmed findings + a URLSession
leak) across correctness, concurrency, security, and cleanup:

- MongoDocument.id: deterministic fallback (was UUID() on every access) to stop
  SwiftUI List/ForEach identity churn; getAll pagination drives its cursor off
  the real _id via documentId, so a missing _id stops paging instead of looping
  on a fabricated cursor.
- View models: per-load generation guard (+ captured-tab guard on ONU detail)
  so a cancelled or overlapping load can't commit stale results or land data on
  the wrong tab.
- JSONValue.intValue: guard Int(d) against NaN/inf/out-of-range (crash).
- ServerTrustEvaluator: hash the real SubjectPublicKeyInfo (prepend the
  algorithm-specific ASN.1 SPKI header) so a standard openssl-captured
  public-key pin actually matches; unknown key types fail closed.
- AppEnvironment.configure: clear stale cookies + Keychain creds on host change.
- FirmwareFile.isCompatible: empty metadata no longer passes as compatible-for-all.
- APIClient: invalidate URLSession on deinit (per-configure/probe leak).
- Dashboard best-effort sections keep last-good on transient failure; unified
  optical thresholds; LoginView prefill-once; populatedBuckets unique ForEach id;
  Format rounding rollover; dead-code/docstring/dedup cleanups.

Verification pending on the Mac (no Swift toolchain on the Linux dev box).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 16:36:49 +02:00

37 lines
1.4 KiB
Swift

import Foundation
/// `POST /v{n}/users/authenticate/`
struct AuthRequest: Encodable {
let email: String
let password: String
}
/// A successful login replies `{"status":"success"}` with no `data` (dev guide
/// §Response format). We don't depend on a payload auth state lives in
/// cookies so `AuthResponse` is empty-representable and captures `data` raw
/// only when a build happens to include it.
struct AuthResponse: Decodable, EmptyRepresentable {
let raw: JSONValue
init(from decoder: Decoder) throws { raw = try JSONValue(from: decoder) }
private init(raw: JSONValue) { self.raw = raw }
static var emptyValue: AuthResponse { AuthResponse(raw: .null) }
}
/// `GET /v{n}/ponmgr/version/` attribute set describing the install.
/// Exact keys vary; surface a best-effort display string and keep raw.
struct VersionInfo: Decodable {
let raw: JSONValue
init(from decoder: Decoder) throws { raw = try JSONValue(from: decoder) }
var displayVersion: String? {
raw["version"]?.stringValue
?? raw["Version"]?.stringValue
?? raw["ponmgr"]?["version"]?.stringValue
}
}
// `PUT /v{n}/databases/selection/` takes the database id as a bare string under
// the data envelope `{ "data": "<db id>" }` (dev guide §Request Format). It is
// sent by passing the id String straight to `client.send(wrapInData: true)`, so
// no wrapper struct is needed here.