Skip to content

Fix/backup webauthn ml export bugs - #4

Merged
lukislp merged 2 commits into
mainfrom
fix/backup-webauthn-ml-export-bugs
Aug 6, 2026
Merged

Fix/backup webauthn ml export bugs#4
lukislp merged 2 commits into
mainfrom
fix/backup-webauthn-ml-export-bugs

Conversation

@lukislp

@lukislp lukislp commented Aug 6, 2026

Copy link
Copy Markdown
Owner

fix backup webauthn ml export and minor bugs

lukislp added 2 commits August 6, 2026 18:05
Several real bugs surfaced by the batch-1/2 coverage agents, all now
fixed:

- WebAuthnService: registration origin mismatch and authentication
  signature-counter regression (cloned-authenticator signal) were only
  logged, never rejected. Both are now hard failures.
- DatabaseRestoreService: encrypted-backup restore was broken two ways
  - ValidateBackupAsync's ZIP-structure gate rejected genuinely
  AES-encrypted backups outright (they are IV-prefixed ciphertext, not
  a ZIP), and DecryptAndExtractAsync never actually decrypted, just
  copied the stream verbatim. Both fixed: a non-ZIP stream long enough
  to hold an IV is now treated as an encrypted-backup candidate, and
  decryption genuinely happens (same AES key derivation as
  BackupManagementService.EncryptBackupAsync). Also fixed
  IsBackupEncryptedAsync's metadata-entry filename check (was looking
  for "backup_metadata.json", JsonBackupHelper writes "metadata.json"),
  and removed ~55 lines of dead restore code superseded by the JSON
  restore path.
- BackupManagementService: Weekly/Monthly retention cutoffs had an
  inverted sign (AddDays(+28)/(+365) instead of negative), making
  Weekly retention tighter than Daily's and Monthly backups deleted
  unconditionally regardless of age.
  CleanupBackupsByProviderSettingsAsync's doc comment claimed
  "Weekly and monthly handled analogously" but only ever processed
  Daily rows; now processes all three. A failed remote delete no
  longer purges the DB row (the backup may still exist at the
  provider - it's retried on the next cleanup run instead).
- CategoryPredictionService: the ML training pipeline's first step
  (MapValueToKey("Label")) made building a PredictionEngine always
  throw "Could not find input column 'Label'", both right after
  training and after every reload - so the ML model never actually
  worked, silently falling back to keyword-only suggestions forever.
  CategoryPredictionInput now carries the (unused-at-prediction-time)
  Label column the schema requires. The reload guard that caught this
  exception and deleted the just-trained model file (without
  resetting _trainedModel, so IsMlModelTrained lied about it) is
  removed - reload now succeeds outright.
  FindSimilarProductsAsync also matched case-sensitively against
  already-lowercased keywords, so it silently missed most real
  product names.
- ExportService: storage-location Excel export called
  .Include(sl => sl.Room) on a plain string column, not a navigation
  property, throwing on every call.
- ApplicationInsightsService: MemoryTotalMB was hardcoded to
  long.MinValue instead of a real reading.
- DatabaseHealthService: GetHealthReportAsync never called the
  existing GetLastBackupDateAsync helper, so LastBackup stayed null
  regardless of actual backup history.

Also fixes an unrelated pre-existing test bug in
SecurityRiskServiceTests (asserted UserId descending order when the
test's own scenario makes the lower-UserId user score higher - the
correct invariant is RiskScore descending).
Every test that previously documented one of the bugs fixed in the
prior commit now asserts the corrected behavior instead, plus new
tests where the fix needed a real relational provider (SQLite) that
EF Core InMemory can't translate the query against.

Also fixes SecurityRiskServiceTests' own pre-existing assertion bug
(unrelated to the production fixes): it asserted UserId descending
order, but the test's own scenario gives the lower-UserId user the
higher risk score - the correct invariant is RiskScore descending.
@lukislp
lukislp merged commit 8d2087c into main Aug 6, 2026
0 of 6 checks passed
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant