import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import test from 'node:test';
import { Window } from 'happy-dom';
async function documentAt(route) {
const window = new Window();
window.document.write(await readFile(new URL(`../dist/${route}index.html`, import.meta.url), 'utf8'));
return window.document;
}
test('section banners stand on the contour field, and it never reaches the reading area', async () => {
for (const route of ['osint/']) {
const document = await documentAt(route);
// The dot cloud is gone from every banner; the contour field took its place.
assert.equal(document.querySelectorAll('[data-signal]').length, 0, route);
const fields = [...document.querySelectorAll('[data-contour]')];
assert.equal(fields.length, 1, route);
assert.ok(fields[0].parentElement.classList.contains('signal-hero'), route);
assert.equal(document.querySelector('body > [data-contour], article [data-contour]'), null, route);
assert.equal(fields[0].hasAttribute('data-astro-transition-persist'), false, route);
// The banner's type is marked, so the lines keep out from under it.
assert.ok(fields[0].parentElement.querySelectorAll('[data-contour-clear]').length >= 1, route);
}
});
test('the home hero stands on the contour field, with no ambient dot cloud', async () => {
const document = await documentAt('');
// The cloud is gone from the hero; the dots that gather into the shelf
// icons live on the plate, which the hero's script mounts at runtime.
assert.equal(document.querySelectorAll('[data-signal]').length, 0);
const contours = [...document.querySelectorAll('[data-contour]')];
assert.equal(contours.length, 1);
assert.ok(contours[0].parentElement.hasAttribute('data-hero-loop'));
assert.ok(contours[0].parentElement.classList.contains('signal-hero'));
assert.equal(contours[0].hasAttribute('data-astro-transition-persist'), false);
});
// One page of each document type. All four headers are `.sheet-head.plate`
// bands and stand on the same field as the hero and the banners.
const DOCUMENTS = [
'sheets/enumeration/2-4-cheatsheet-gitleaks/',
'payloads/sql-injection/',
'internal/active-directory/ad-adcs-esc01/',
'hacktricks/mobile-pentesting/cordova-apps/',
];
test('document headers stand on the contour field, and it never reaches the article', async () => {
for (const route of DOCUMENTS) {
const document = await documentAt(route);
const fields = [...document.querySelectorAll('[data-contour]')];
assert.equal(fields.length, 1, route);
const head = fields[0].parentElement;
assert.ok(head.matches('header.sheet-head.plate.signal-hero'), route);
assert.equal(document.querySelector('article [data-contour], body > [data-contour]'), null, route);
assert.equal(fields[0].hasAttribute('data-astro-transition-persist'), false, route);
// The head's type is marked so the lines keep out from under it. The
// shader reads six boxes and silently ignores the rest, so a seventh
// would be type with lines through it.
const clear = [...head.querySelectorAll('[data-contour-clear]')];
assert.ok(clear.length >= 1 && clear.length <= 6, `${route}: ${clear.length} clearings`);
assert.ok(head.querySelector('[data-contour-clear] .sheet-title, .sheet-title[data-contour-clear]'), `${route}: title`);
for (const small of head.querySelectorAll('.sheet-desc, .sheet-meta, .tags-row, .report-sequence-note')) {
assert.ok(small.closest('[data-contour-clear]'), `${route}: .${small.className} is outside every clearing`);
}
// Every word of the eyebrow, whichever of the two eyebrow shapes it is.
const eyebrow = head.querySelector('.eyebrow');
assert.ok(eyebrow.closest('[data-contour-clear]') || eyebrow.querySelector('[data-contour-clear]'), `${route}: eyebrow`);
}
});
test('the streak texture is gone from every kind of page', async () => {
for (const route of ['', 'osint/', 'sheets/', 'tags/', 'credits/', 'hacktricks/section/mobile-pentesting/', ...DOCUMENTS]) {
const document = await documentAt(route);
assert.equal(document.querySelectorAll('[data-fuzz], .fuzz-field, [data-signal]').length, 0, route);
}
});
test('the credits page is a plain document with no field', async () => {
const document = await documentAt('credits/');
assert.equal(document.querySelectorAll('[data-contour]').length, 0);
});
test('home has one h1 and a skip link to main', async () => {
const document = await documentAt('');
assert.equal(document.querySelectorAll('h1').length, 1);
assert.equal(document.querySelector('a.skip-link')?.getAttribute('href'), '#main');
assert.ok(document.querySelector('main#main'));
});
test('home carries the shared open emblem and six-colour hero rail', async () => {
const document = await documentAt('');
const brand = document.querySelector('[data-hero-brand-template]')?.content;
assert.ok(brand);
assert.equal(brand.querySelectorAll('.hero-brand__arm').length, 6);
assert.equal(brand.querySelectorAll('.hero-brand__arm--outline').length, 3);
assert.equal(brand.querySelectorAll('.hero-brand__rail i').length, 6);
assert.equal(brand.querySelector('.hero-brand__emblem').getAttribute('aria-hidden'), 'true');
});
test('OSINT and Enumeration both link to the original secret-scanner sheets', async () => {
for (const route of ['osint/', 'enumeration/']) {
const document = await documentAt(route);
for (const slug of ['2-4-cheatsheet-gitleaks', '2-5-cheatsheet-trufflehog']) {
assert.equal(document.querySelectorAll(`a.rec[href="/sheets/enumeration/${slug}"]`).length, 1, `${route}: ${slug}`);
}
}
});
test('secret-scanner instructions render as prose after the installation block', async () => {
for (const slug of ['2-4-cheatsheet-gitleaks', '2-5-cheatsheet-trufflehog']) {
const document = await documentAt(`sheets/enumeration/${slug}/`);
const headings = [...document.querySelectorAll('article h2')].map((h) => h.textContent);
assert.ok(headings.includes('Subcommands at a Glance'), slug);
assert.ok(document.querySelector('article table'), slug);
}
});