@davoodmehraban89 / Factor-easy / commits / 77af796
Fork 0

سامانه صدور فاکتور و حسابداری

fix: make manual QA fail closed and origin safe

davoodmehraban89 committed Oct 1, 2026 at 23:58 UTC 77af796de74c2d3c8bb3ca35785c6b48e5a12d3f
1 file changed +74 -16
.github/workflows/qa.yml
+74 -16
@@ -15,6 +15,9 @@ on:
15 - live
16 - all
17
18 +permissions:
19 + contents: read
20 +
21 jobs:
22 qa:
23 runs-on: ubuntu-latest
@@ -24,6 +27,36 @@ jobs:
27 with:
28 node-version: 20
29
30 + - name: Validate requested QA target before credentials
31 + env:
32 + BASE_URL: ${{ inputs.base_url }}
33 + SUITE: ${{ inputs.suite }}
34 + run: |
35 + node <<'NODE'
36 + const allowedLiveOrigins = new Set([
37 + 'https://factoreasy.ir',
38 + 'https://www.factoreasy.ir',
39 + ]);
40 + const suite = process.env.SUITE || 'public';
41 + let target;
42 + try { target = new URL(process.env.BASE_URL || ''); }
43 + catch { throw new Error('BASE_URL must be a valid absolute URL'); }
44 + if (target.protocol !== 'https:') throw new Error('QA target must use HTTPS');
45 + if ((suite === 'live' || suite === 'all') && !allowedLiveOrigins.has(target.origin)) {
46 + throw new Error(`Refusing to expose live-test credentials to non-allowlisted origin: ${target.origin}`);
47 + }
48 + console.log(`Validated ${suite} QA target: ${target.origin}`);
49 + NODE
50 +
51 + - name: Require live QA credentials
52 + if: ${{ inputs.suite == 'live' || inputs.suite == 'all' }}
53 + env:
54 + TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
55 + TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
56 + run: |
57 + test -n "$TEST_EMAIL" || { echo '::error::TEST_EMAIL is required for live/all QA'; exit 1; }
58 + test -n "$TEST_PASSWORD" || { echo '::error::TEST_PASSWORD is required for live/all QA'; exit 1; }
59 +
60 - name: Write test project
61 run: |
62 mkdir -p qa/tests
@@ -48,7 +81,7 @@ jobs:
81 use: {
82 baseURL: process.env.BASE_URL || 'https://factoreasy.ir',
83 locale: 'fa-IR',
51 - screenshot: 'on',
84 + screenshot: 'only-on-failure',
85 trace: 'retain-on-failure',
86 },
87 });
@@ -112,16 +145,34 @@ jobs:
145 const { test, expect } = require('@playwright/test');
146 const EMAIL = process.env.TEST_EMAIL;
147 const PASS = process.env.TEST_PASSWORD;
115 - const NAV_SELECTOR = process.env.NAV_SELECTOR || 'nav a, nav button, aside a, aside button, [data-view], [onclick*="show"]';
148 + const NAV_SELECTOR = process.env.NAV_SELECTOR || '.module-tab, .context-menu a, .context-menu button, .sidebar-menu a, .mobile-dock a, [data-view]';
149 const SKIP = /حذف|پاک|خروج|delete|remove|logout|sign out/i;
117 - test.skip(!EMAIL || !PASS, 'TEST_EMAIL / TEST_PASSWORD secrets are not set');
150 + const ALLOWED_ORIGINS = new Set(['https://factoreasy.ir', 'https://www.factoreasy.ir']);
151 +
152 + if (!EMAIL || !PASS) throw new Error('TEST_EMAIL / TEST_PASSWORD are required for authenticated QA');
153 +
154 + function assertAllowedOrigin(url) {
155 + const origin = new URL(url).origin;
156 + expect(ALLOWED_ORIGINS.has(origin), `credential-bearing browser escaped allowlisted origin: ${origin}`).toBeTruthy();
157 + }
158
159 async function login(page) {
160 await page.goto('/');
161 + assertAllowedOrigin(page.url());
162 await page.locator('input[type="email"], input[name="email"]').first().fill(EMAIL);
163 await page.locator('input[type="password"]').first().fill(PASS);
164 await page.getByRole('button', { name: /ورود|login|sign in/i }).first().click();
165 await page.waitForLoadState('networkidle');
166 + assertAllowedOrigin(page.url());
167 + }
168 +
169 + async function uiState(page) {
170 + return page.evaluate(() => ({
171 + href: location.href,
172 + activeViews: [...document.querySelectorAll('.view-pane.active')].filter((x) => x.offsetParent !== null).map((x) => x.id).sort(),
173 + activeNav: [...document.querySelectorAll('.module-tab.active,.context-menu .active,.sidebar-menu .active,.mobile-dock .active')].filter((x) => x.offsetParent !== null).map((x) => (x.id || x.getAttribute('data-view') || x.textContent || '').trim()).sort(),
174 + openPanels: [...document.querySelectorAll('.open,.expanded,[aria-expanded="true"]')].filter((x) => x.offsetParent !== null).map((x) => (x.id || x.getAttribute('data-module') || x.textContent || '').trim().slice(0, 80)).sort(),
175 + }));
176 }
177
178 test('read-only crawl of every visible menu item', async ({ page }) => {
@@ -138,18 +189,24 @@ jobs:
189 const results = [];
190 for (let i = 0; i < count; i++) {
191 const el = items.nth(i);
141 - if (!(await el.isVisible().catch(() => false))) continue;
142 - const label = ((await el.innerText().catch(() => '')) || '').trim().slice(0, 60);
192 + if (!(await el.isVisible())) continue;
193 + const label = ((await el.innerText()) || '').trim().slice(0, 60);
194 if (!label || SKIP.test(label)) continue;
144 - const before = errors.length;
145 - await el.click({ timeout: 5000 }).catch(() => {});
146 - await page.waitForTimeout(800);
147 - await page.screenshot({ path: 'evidence/menu-' + String(i).padStart(3, '0') + '.png' });
148 - results.push({ index: i, label, newErrors: errors.slice(before) });
149 - await page.keyboard.press('Escape').catch(() => {});
195 + if (await el.evaluate((node) => node.classList.contains('active'))) continue;
196 + const beforeErrors = errors.length;
197 + const beforeState = await uiState(page);
198 + await el.click({ timeout: 5000 });
199 + await page.waitForTimeout(500);
200 + assertAllowedOrigin(page.url());
201 + const afterState = await uiState(page);
202 + expect(afterState, `menu item did not change navigation/view state: ${label}`).not.toEqual(beforeState);
203 + const newErrors = errors.slice(beforeErrors);
204 + expect(newErrors, `menu item produced runtime errors: ${label}`).toEqual([]);
205 + results.push({ index: i, label, beforeState, afterState });
206 + await page.keyboard.press('Escape');
207 }
208 + expect(results.length, 'authenticated menu crawl found no navigable items').toBeGreaterThan(0);
209 fs.writeFileSync('evidence/crawl.json', JSON.stringify(results, null, 2));
152 - expect.soft(results.filter((r) => r.newErrors.length), 'menu items that produced errors').toEqual([]);
210 });
211 EOF
212
@@ -179,7 +236,6 @@ jobs:
236
237 - name: Run tests
238 working-directory: qa
182 - continue-on-error: true
239 env:
240 BASE_URL: ${{ inputs.base_url }}
241 TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
@@ -188,7 +244,8 @@ jobs:
244 case "${{ inputs.suite }}" in
245 public) npx playwright test public-smoke ;;
246 live) npx playwright test logged-in ;;
191 - *) npx playwright test ;;
247 + all) npx playwright test ;;
248 + *) echo '::error::Unknown QA suite'; exit 2 ;;
249 esac
250
251 - name: Summary
@@ -200,10 +257,11 @@ jobs:
257 if: always()
258 uses: actions/upload-artifact@v4
259 with:
203 - name: qa-results
260 + name: qa-results-${{ github.run_id }}
261 + retention-days: 3
262 path: |
263 qa/playwright-report
264 qa/evidence
265 qa/test-results
266 qa/results.json
209 - if-no-files-found: ignore
267 + if-no-files-found: warn