فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A04): verify real encrypted company backups across native WebView2 and UI navigation

Preserve native financial, WebView2-origin and ten-route checks. Verify .fbackup AES-GCM recovery including intentional wrong-password toast and modal dismissal, followed by audited restore and successful dashboard navigation. Validated on PR head ab89ec6: 185 Node tests, Vite build, npm audit, Windows NSIS preview, native installer v2.0.3→2.0.4 upgrade and ten-route WebView2 lab (Actions 38939141399, 38939141475).

davoodmehraban89 committed Oct 16, 2026 at 20:59 UTC 58f4d1bc1a0446fec5811e23ca70a6ec6de41286
5 files changed +267
.github/workflows/a04-fast-native-backup-regression.yml new
+66
@@ -0,0 +1,66 @@
1 +name: A04 Windows fast native backup regression (prebuilt installer)
2 +
3 +on:
4 + workflow_dispatch:
5 + inputs:
6 + artifact_run_id:
7 + description: 'Successful PR-quality run containing factor-easypro-windows-pr-preview; verify it matches the tested product source'
8 + required: true
9 + type: string
10 + expected_version:
11 + description: 'Version displayed by the NSIS preview installer'
12 + required: true
13 + type: string
14 + default: '2.0.3'
15 +
16 +permissions:
17 + contents: read
18 + actions: read
19 +
20 +jobs:
21 + fast-native-smoke:
22 + runs-on: windows-latest
23 + timeout-minutes: 20
24 + steps:
25 + - uses: actions/checkout@v4
26 + with:
27 + persist-credentials: false
28 + - uses: actions/setup-node@v4
29 + with:
30 + node-version: '22'
31 + - name: Validate run ID, version and completed preview source
32 + shell: pwsh
33 + env:
34 + GH_TOKEN: ${{ github.token }}
35 + SOURCE_RUN: ${{ inputs.artifact_run_id }}
36 + EXPECTED_VERSION: ${{ inputs.expected_version }}
37 + run: |
38 + if ($env:SOURCE_RUN -notmatch '^[0-9]+$') { throw 'Run ID must be numeric' }
39 + if ($env:EXPECTED_VERSION -notmatch '^\d+\.\d+\.\d+$') { throw 'Version must be semantic' }
40 + $info = gh api "repos/$env:GITHUB_REPOSITORY/actions/runs/$env:SOURCE_RUN" | ConvertFrom-Json
41 + if ($info.conclusion -ne 'success') { throw 'Prebuilt installer source workflow has not passed' }
42 + if ($info.head_sha -ne $env:GITHUB_SHA) { throw 'Prebuilt NSIS source SHA differs from the checked-out test source' }
43 + Write-Host ("Source run: " + $info.html_url + " commit: " + $info.head_sha)
44 + - name: Fetch a checksum-verified previous Windows NSIS preview
45 + uses: actions/download-artifact@v4
46 + with:
47 + run-id: ${{ inputs.artifact_run_id }}
48 + github-token: ${{ github.token }}
49 + name: factor-easypro-windows-pr-preview
50 + path: test-installer
51 + - name: Execute the installed native application and encrypted backup UI
52 + shell: pwsh
53 + env:
54 + EXPECTED_VERSION: ${{ inputs.expected_version }}
55 + run: |
56 + $files = @(Get-ChildItem test-installer -Recurse -Filter '*x64-setup.exe')
57 + if ($files.Count -ne 1) { throw 'Expected exactly one x64 NSIS preview' }
58 + ./scripts/windows-vm-fast-native-backup-smoke.ps1 -Installer $files[0].FullName -ExpectedVersion $env:EXPECTED_VERSION
59 + - name: Upload synthetic evidence including failures
60 + if: always()
61 + uses: actions/upload-artifact@v4
62 + with:
63 + name: a04-fast-native-company-backup-evidence
64 + path: ${{ runner.temp }}/factor-fast-native-backup-lab/reports/*.json
65 + retention-days: 14
66 + if-no-files-found: warn
.github/workflows/windows-vm-native-lab.yml
+1
@@ -13,6 +13,7 @@ on:
13 - 'tests/windows-vm-native-origin.cjs'
14 - 'tests/windows-vm-native-origin.test.mjs'
15 - 'tests/windows-vm-native-functional-matrix.cjs'
16 + - 'tests/windows-vm-encrypted-company-backup-browser.js'
17 - 'scripts/windows-vm-native-lab.ps1'
18 - 'scripts/windows-vm-set-candidate.cjs'
19 - '.github/workflows/windows-vm-native-lab.yml'
scripts/windows-vm-fast-native-backup-smoke.ps1 new
+33
@@ -0,0 +1,33 @@
1 +[CmdletBinding()]
2 +param(
3 + [Parameter(Mandatory=$true)][string]$Installer,
4 + [string]$ExpectedVersion = '2.0.3'
5 +)
6 +$ErrorActionPreference = 'Stop'
7 +if ($env:RUNNER_OS -ne 'Windows' -or !$env:GITHUB_ACTIONS) {
8 + throw 'This test only runs inside a disposable Windows GitHub Actions VM'
9 +}
10 +$root = Join-Path $env:RUNNER_TEMP 'factor-fast-native-backup-lab'
11 +$install = Join-Path $root 'installed'
12 +$profile = Join-Path $root 'webview2-profile'
13 +$reportDir = Join-Path $root 'reports'
14 +New-Item -ItemType Directory -Force -Path $install,$profile,$reportDir | Out-Null
15 +if (!(Test-Path -LiteralPath $Installer)) { throw 'Preview installer missing' }
16 +$hash = (Get-FileHash -Path $Installer -Algorithm SHA256).Hash
17 +Write-Host ("Using prebuilt NSIS artifact checksum SHA256: " + $hash)
18 +$installerProcess = Start-Process -FilePath $Installer -ArgumentList @('/S',("/D="+$install)) -PassThru
19 +try {
20 + if (!$installerProcess.WaitForExit(120000)) { $installerProcess.Kill(); throw 'NSIS timeout' }
21 + if ($installerProcess.ExitCode -ne 0) { throw "NSIS exited $($installerProcess.ExitCode)" }
22 +} finally { $installerProcess.Dispose() }
23 +$exe = @(Get-ChildItem -LiteralPath $install -File -Recurse |
24 + Where-Object { $_.Name -in @('app.exe','Factor-easyPro.exe') })[0]
25 +if (!$exe) { throw 'Installed native app EXE missing' }
26 +$report = Join-Path $reportDir 'fast-native-company-backup.json'
27 +& node tests/windows-vm-installed-tauri-cdp.cjs $exe.FullName $profile fresh $ExpectedVersion $report | Out-Host
28 +if ($LASTEXITCODE -ne 0) { throw "Fast native company-backup smoke failed (exit $LASTEXITCODE)" }
29 +$result = Get-Content $report -Raw | ConvertFrom-Json
30 +if ($result.status -ne 'PASSED' -or !$result.encryptedCompanyBackup) {
31 + throw 'Encrypted company backup did not pass native WebView2 smoke'
32 +}
33 +Write-Host 'Prebuilt NSIS native encrypted backup smoke succeeded.'
tests/windows-vm-encrypted-company-backup-browser.js new
+147
@@ -0,0 +1,147 @@
1 +(async () => {
2 + // Executes inside an installed Tauri WebView2 window, authenticated as a
3 + // synthetic administrator. Exercises the actual Settings UI backup methods.
4 + const store = FINORA.Storage;
5 + const company = await FINORA.Company.current();
6 + const actor = FINORA.Auth.current();
7 + if (!company?.id || !actor?.id || !FINORA.Auth.isAdmin()) {
8 + throw Error('Native company backup test requires an authenticated administrator');
9 + }
10 + const contactId = 'vm-only-encrypted-backup-contact';
11 + const synthetic = 'VM-ONLY encrypted backup test contact';
12 + await store.put('contacts', {
13 + id: contactId, companyId: company.id, ownerUserId: actor.id, name: synthetic
14 + });
15 +
16 + const password = 'VM-ONLY-PASSPHRASE-18-characters';
17 + const original = {
18 + prompt: window.prompt, create: URL.createObjectURL,
19 + revoke: URL.revokeObjectURL,
20 + anchorClick: HTMLAnchorElement.prototype.click,
21 + timeout: window.setTimeout,
22 + toastError: FINORA.Toast.error
23 + };
24 + const capturedErrors = [];
25 + FINORA.Toast.error = function (message, ...args) {
26 + capturedErrors.push(String(message).slice(0, 280));
27 + return original.toastError.call(this, message, ...args);
28 + };
29 + let exportedBlob = null;
30 + let downloadedName = null;
31 + const restoreFile = ciphertext => {
32 + window.SettingsView.openRestoreModal();
33 + const input = document.getElementById('restoreFile');
34 + const selector = document.getElementById('restoreMode');
35 + if (!input || !selector) throw Error('Company restore form not displayed');
36 + const file = new File([ciphertext], 'synthetic-company.fbackup', {
37 + type: 'application/octet-stream'
38 + });
39 + Object.defineProperty(input, 'files', {
40 + configurable: true, value: [file]
41 + });
42 + selector.value = 'merge';
43 + };
44 + try {
45 + window.prompt = () => password;
46 + URL.createObjectURL = blob => {
47 + exportedBlob = blob; return 'blob:vm-only-native-backup';
48 + };
49 + URL.revokeObjectURL = () => {};
50 + HTMLAnchorElement.prototype.click = function () {
51 + downloadedName = this.download;
52 + };
53 + // Suppress only the UI's delayed page reload after a successful recovery.
54 + // This keeps the evaluation context alive for the required assertions.
55 + window.setTimeout = (fn, delay, ...args) => {
56 + if (delay === 1500 && String(fn).includes('location.reload')) return 0;
57 + return original.timeout.call(window, fn, delay, ...args);
58 + };
59 +
60 + await window.SettingsView.downloadBackup();
61 + if (!(exportedBlob instanceof Blob)) {
62 + throw Error('Actual SettingsView.downloadBackup did not create a Blob: ' +
63 + capturedErrors.join(' | '));
64 + }
65 + const encryptedText = await exportedBlob.text();
66 + const envelope = JSON.parse(encryptedText);
67 + if (envelope.format !== 'finora-encrypted-backup-v1' ||
68 + !envelope.salt || !envelope.iv || !envelope.ciphertext ||
69 + encryptedText.includes(synthetic)) {
70 + throw Error('Downloaded company backup is not a confidential encrypted envelope');
71 + }
72 + if (!String(downloadedName).endsWith('.fbackup')) {
73 + throw Error('Native Settings UI did not produce a .fbackup filename');
74 + }
75 +
76 + await store.delete('contacts', contactId);
77 + if (await store.get('contacts', contactId)) throw Error('Synthetic contact did not get deleted');
78 +
79 + restoreFile(encryptedText);
80 + window.prompt = () => 'an-intentionally-wrong-password';
81 + await window.SettingsView.restoreBackup();
82 + if (await store.get('contacts', contactId)) {
83 + throw Error('Encrypted company backup accepted an incorrect password');
84 + }
85 +
86 + // The incorrect-password result MUST produce the real, visible error toast.
87 + // ToastManager deliberately retains errors until dismissed.
88 + // Dismiss ONLY the expected toast and modal through their real UI actions.
89 + // Any unrelated errors remain visible and will fail the navigation sweep.
90 + const expectedError = 'رمز نادرست است یا فایل پشتیبان آسیب دیده است';
91 + if (capturedErrors.length !== 1 || !capturedErrors[0].includes(expectedError)) {
92 + throw Error('Wrong-password restore did not emit exactly the expected error');
93 + }
94 + const visibleErrors = [...document.querySelectorAll('.toast-error')];
95 + if (visibleErrors.length !== 1 || !visibleErrors[0].textContent.includes(expectedError)) {
96 + throw Error('Expected wrong-password error toast was absent or extra errors were shown');
97 + }
98 + const dismiss = visibleErrors[0].querySelector('.toast-close');
99 + if (!dismiss) throw Error('Expected error toast cannot be dismissed');
100 + dismiss.click();
101 + if (document.querySelector('.toast-error')) {
102 + throw Error('Unexpected error toast survived wrong-password cleanup');
103 + }
104 + // A failed restore deliberately keeps its form open for the user to retry.
105 + // The test must close that form before opening a second restore dialog.
106 + if (!document.getElementById('restoreFile')) {
107 + throw Error('Wrong-password recovery unexpectedly closed its dialog');
108 + }
109 + FINORA.Modal.close();
110 + if (document.getElementById('restoreFile')) {
111 + throw Error('Failed recovery dialog could not be closed');
112 + }
113 +
114 + restoreFile(encryptedText);
115 + window.prompt = () => password;
116 + await window.SettingsView.restoreBackup();
117 + if (capturedErrors.length !== 1 || document.querySelector('.toast-error') ||
118 + document.querySelector('.modal-backdrop')) {
119 + throw Error('Correct-password restore failed or left modal/error state');
120 + }
121 + const recovered = await store.get('contacts', contactId);
122 + if (recovered?.name !== synthetic || recovered.companyId !== company.id) {
123 + throw Error('Encrypted native company backup did not restore the exact contact');
124 + }
125 + const audits = (await store.getAll('audit_events'))
126 + .filter(e => e.eventType === 'backup_restored' && e.companyId === company.id);
127 + if (!audits.length) {
128 + throw Error('Company restore did not create a corresponding audit event');
129 + }
130 + return {
131 + encryptedEnvelope: true,
132 + filenameSuffix: '.fbackup',
133 + wrongPasswordRejected: true,
134 + sameCompanyRestore: true,
135 + restoredContact: true,
136 + restoreAudited: true,
137 + plaintextSensitiveDataAbsent: true
138 + };
139 + } finally {
140 + window.prompt = original.prompt;
141 + URL.createObjectURL = original.create;
142 + URL.revokeObjectURL = original.revoke;
143 + HTMLAnchorElement.prototype.click = original.anchorClick;
144 + window.setTimeout = original.timeout;
145 + FINORA.Toast.error = original.toastError;
146 + }
147 +})()
\ No newline at end of file
tests/windows-vm-installed-tauri-cdp.cjs
+20
@@ -295,6 +295,26 @@ async function connect(url) {
295 // verify accounting activation, financial journal, stock, backup and RTL.
296 report.nativeFunctional = await verifyNativeFunctionalMatrix(cdp);
297 }
298 + if (mode === 'fresh') {
299 + // Verify encrypted .fbackup BEFORE sweeping all 10 native UI routes.
300 + // Intentional wrong-password toast/dialog are dismissed through the UI;
301 + // unexpected errors still fail the following navigation regression.
302 + const script = fs.readFileSync(
303 + path.join(__dirname, 'windows-vm-encrypted-company-backup-browser.js'), 'utf8'
304 + );
305 + const validated = await cdp.evaluate(script);
306 + assert.deepEqual(validated, {
307 + encryptedEnvelope: true,
308 + filenameSuffix: '.fbackup',
309 + wrongPasswordRejected: true,
310 + sameCompanyRestore: true,
311 + restoredContact: true,
312 + restoreAudited: true,
313 + plaintextSensitiveDataAbsent: true
314 + });
315 + report.encryptedCompanyBackup =
316 + 'native-SettingsUI-AES-GCM-PBKDF2-wrong-password-and-audited-restore-passed';
317 + }
318 if (mode === 'fresh') {
319 // Drive synthetic records, complete snapshot replay and every SPA route
320 // inside the actually installed Tauri WebView2, not Vite preview.