Files
softharbor/scripts/validate-data.test.ts
poli0981andClaude Opus 5.5 981e625ca1
CI / build (push) Successful in 3m19s
CI / gates (push) Successful in 1m5s
CI / record (push) Skipped
Reusable / Qodana / Qodana (push) Successful in 3m7s
Qodana / qodana (push) Successful in 3m7s
Reusable / Security / Secrets (gitleaks) (push) Successful in 10s
Reusable / Security / Rust (cargo-deny) (push) Skipped
Reusable / Security / .NET (NuGetAudit) (push) Skipped
Reusable / Security / SAST (Opengrep) (push) Successful in 24s
Reusable / Security / Dependencies (osv-scanner) (push) Successful in 17s
Security / security (push) Successful in 52s
CI / deploy (push) Successful in 1m9s
chore: move the repository to Gitea (D38) (#1)
- ci: move the workflows to Gitea Actions (D38)
- feat(site): source on Gitea, issues and bug reports on the GitLab mirror
- docs: where the project lives now — Gitea, the GitLab mirror, e-mail
- docs: the suite on Gitea — D38, CI/CD rewritten, every GitHub-era claim synced
- fix(ci): what the first Gitea runs found — Qodana and gitleaks
- fix(ci): .gitleaksignore describes the Sonar key instead of quoting it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 05:29:57 +00:00

129 lines
5.1 KiB
TypeScript

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 (SkullMute)
//
// The L2 rules (docs/03 §2) — the ones the Zod schema cannot express — each
// proven to fire, plus the clean case proven NOT to.
import { describe, expect, it } from 'vitest';
import { project, run } from './fixture';
const day = (offset: number): string =>
new Date(Date.now() + offset * 86_400_000).toISOString().slice(0, 10);
const TODAY = day(0);
const ZWSP = String.fromCharCode(0x200b);
type App = Record<string, unknown>;
const app = (over: App = {}): App => ({
name: 'Firefox',
categories: ['browser'],
links: { homepage: 'https://www.firefox.com/', repo: null },
logo: 'simple-icons:firefox',
addedAt: TODAY,
updatedAt: TODAY,
summary: { en: 'A browser.', vi: 'Trình duyệt.' },
security: {
status: 'clean',
checkedAt: TODAY,
evidence: 'https://www.virustotal.com/gui/url/abc',
},
...over,
});
/** A project with categories.json and the given apps (slug → entry, or raw text). */
function data(apps: Record<string, App | string>, extra: Record<string, string> = {}): string {
const files: Record<string, string> = {
'src/data/categories.json': JSON.stringify([{ id: 'browser' }, { id: 'security-privacy' }]),
...extra,
};
for (const [slug, entry] of Object.entries(apps)) {
files[`src/data/apps/${slug}.json`] = typeof entry === 'string' ? entry : JSON.stringify(entry);
}
return project(files);
}
const validate = (root: string) => run('validate-data.mjs', root);
describe('validate-data', () => {
it('passes a clean dataset', () => {
const r = validate(data({ firefox: app(), 'tor-browser': app({ name: 'Tor Browser' }) }));
expect(r.code).toBe(0);
expect(r.out).toContain('validate:data — OK (2 apps, 2 categories)');
});
it.each([
{ rule: 'slug-format', apps: { Fire_Fox: app() } },
{ rule: 'slug-length', apps: { [`a${'-b'.repeat(20)}`]: app() } },
{ rule: 'parse', apps: { firefox: '{ not json' } },
{ rule: 'duplicate-name', apps: { firefox: app(), 'firefox-2': app({ name: 'FÍREFOX ' }) } },
{ rule: 'unknown-category', apps: { firefox: app({ categories: ['browsers'] }) } },
{ rule: 'bad-url', apps: { firefox: app({ links: { homepage: 'firefox.com' } }) } },
{ rule: 'insecure-link', apps: { firefox: app({ links: { homepage: 'http://x.org/' } }) } },
{
rule: 'punycode-host',
apps: { firefox: app({ links: { homepage: 'https://xn--80ak6aa92e.com/' } }) },
},
{
rule: 'download-portal',
apps: { firefox: app({ links: { download: 'https://en.softonic.com/firefox' } }) },
},
{
rule: 'tracking-param',
apps: { firefox: app({ links: { homepage: 'https://www.firefox.com/?utm_source=x' } }) },
},
{
rule: 'invisible-char',
apps: { firefox: app({ summary: { en: `A${ZWSP}browser.`, vi: 'Trình duyệt.' } }) },
},
{
rule: 'flagged-in-main-tree',
apps: { firefox: app({ security: { status: 'flagged', checkedAt: TODAY } }) },
},
{ rule: 'future-date', apps: { firefox: app({ addedAt: day(3), updatedAt: day(3) }) } },
{ rule: 'date-order', apps: { firefox: app({ addedAt: TODAY, updatedAt: day(-1) }) } },
])('fails $rule', ({ rule, apps }) => {
const r = validate(data(apps));
expect(r.code).toBe(1);
expect(r.out).toContain(rule);
});
it('checks the evidence link like any other', () => {
const security = { status: 'clean', checkedAt: TODAY, evidence: 'http://vt.test/x' };
expect(validate(data({ firefox: app({ security }) })).out).toContain(
'insecure-link security.evidence',
);
});
it('compares local logos case-sensitively, as Linux CI and the deploy job do', () => {
const extra = { 'src/assets/logos/Firefox.svg': '<svg/>' };
const wrongCase = validate(data({ firefox: app({ logo: 'local:firefox.svg' }) }, extra));
expect(wrongCase.code).toBe(1);
expect(wrongCase.out).toContain('missing-logo');
expect(validate(data({ firefox: app({ logo: 'local:Firefox.svg' }) }, extra)).code).toBe(0);
});
it('warns, without failing, when a security check is due', () => {
const security = { status: 'clean', checkedAt: day(-200), evidence: 'https://vt.test/x' };
const r = validate(data({ firefox: app({ addedAt: day(-300), security }) }));
expect(r.code).toBe(0);
expect(r.out).toMatch(
/stale-check: 1 entry — e\.g\. firefox\.json: security checked 20\d days ago/,
);
});
it('keeps quarantine honest: flagged only, and never live at the same time', () => {
const flagged = JSON.stringify(app({ security: { status: 'flagged', checkedAt: TODAY } }));
const ok = validate(
data({ other: app({ name: 'Other' }) }, { 'data/quarantine/firefox.json': flagged }),
);
expect(ok.code).toBe(0);
const restored = JSON.stringify(app());
const unflagged = validate(data({}, { 'data/quarantine/firefox.json': restored }));
expect(unflagged.out).toContain('unflagged-in-quarantine');
const both = validate(data({ firefox: app() }, { 'data/quarantine/firefox.json': flagged }));
expect(both.code).toBe(1);
expect(both.out).toContain('slug-in-both-trees');
});
});