daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR
git clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
Log | Files | Refs | README | LICENSE

homepage-mirrors.test.mjs (1653B)


      1 import assert from 'node:assert/strict';
      2 import { readFile } from 'node:fs/promises';
      3 import test from 'node:test';
      4 import { Window } from 'happy-dom';
      5 
      6 const readJson = async (name) =>
      7   JSON.parse(await readFile(new URL(`../${name}`, import.meta.url), 'utf8'));
      8 
      9 test('the homepage mirror panel reports both trees at their synced size', async () => {
     10   const html = await readFile(new URL('../dist/index.html', import.meta.url), 'utf8');
     11   const window = new Window();
     12   window.document.write(html);
     13 
     14   const mirrors = window.document.querySelector('#mirrors');
     15   assert.ok(mirrors, 'the mirrors band is missing from the homepage');
     16   assert.match(mirrors.textContent, /PayloadsAllTheThings/);
     17   assert.match(mirrors.textContent, /InternalAllTheThings/);
     18 
     19   // The panel counts real collection entries, so it is where a sync becomes
     20   // visible. Assert it against the manifests the sync scripts write rather
     21   // than against hard-coded totals, which go stale on every sync.
     22   const rows = [...mirrors.querySelectorAll('.mirror-row')].map((row) => ({
     23     path: row.querySelector('.path')?.textContent?.trim(),
     24     count: row.querySelector('.count')?.textContent?.trim(),
     25   }));
     26 
     27   const payloads = await readJson('payloads-manifest.json');
     28   const internal = await readJson('internal-manifest.json');
     29 
     30   assert.equal(
     31     rows.find((row) => row.path === 'payloads/')?.count,
     32     `${payloads.pages} files`,
     33     'the payloads/ row disagrees with payloads-manifest.json',
     34   );
     35   assert.equal(
     36     rows.find((row) => row.path === 'internal/')?.count,
     37     `${internal.pages} files`,
     38     'the internal/ row disagrees with internal-manifest.json',
     39   );
     40 });