Most "obfuscated" subjects of older and smaller groups name their file
without quotes ("DVDFab 8.2.0.5.rar (006/332)", fta's "q3B9…part023.rar
(104/137)", "New_Super_Mario_Bros._[Keygen].exe (1/2)") or with one
quote ("[keira_s04_0037_l.jpg\" yEnc] (2/2)"): 100% of ath 2013's and
fta's, 94% of models' (LOG.md 2026-10-11 (5)). With a segment counter and
no quoted name, unquotedName takes the name before a lone quote (after a
"[", else after the last space), else the text when it ends in a file
name (after "] " or " - "), else its first word that is one; a file
counter stuck in a bracket is dropped. The release identity takes such a
name out of the subject as it would quotes (else every image of a set
was a release: 9,130 instead of 267 on the models fixture).
Both implementations; a fourth fixture (fta, 25k lines) and tests; check
identical on all four. Truly random subjects (ngPost hex = message-id,
random tokens) stay obfuscated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.8 KiB
TypeScript
86 lines
3.8 KiB
TypeScript
import { test } from '@japa/runner'
|
|
import { fileKey, parseSubject } from '#lib/headers/index'
|
|
import { parseXrefGroups } from '#lib/nntp/index'
|
|
|
|
test.group('subject / parseSubject', () => {
|
|
test('parses file counter, filename and segment counter', ({ assert }) => {
|
|
assert.deepEqual(parseSubject('. - [09/51] - "obrMkrDeLmbhaouwYO34.part08.rar" yEnc (56/274)'), {
|
|
name: 'obrMkrDeLmbhaouwYO34.part08.rar',
|
|
segment: 56,
|
|
totalSegments: 274,
|
|
fileIndex: 9,
|
|
fileTotal: 51,
|
|
base: '. - [09/51] - "obrMkrDeLmbhaouwYO34.part08.rar" yEnc',
|
|
})
|
|
})
|
|
|
|
test('handles a file size after the segment counter', ({ assert }) => {
|
|
const subject = '[8/9] - "x.tar.zst.vol063+064.par2" yEnc (37/72) 51315352'
|
|
const parsed = parseSubject(subject)!
|
|
assert.equal(parsed.segment, 37)
|
|
assert.equal(parsed.totalSegments, 72)
|
|
assert.equal(parsed.base, '[8/9] - "x.tar.zst.vol063+064.par2" yEnc 51315352')
|
|
})
|
|
|
|
test('ignores counters inside the filename', ({ assert }) => {
|
|
const parsed = parseSubject('"Show (1/2) Special.mkv" yEnc (3/10)')!
|
|
assert.equal(parsed.name, 'Show (1/2) Special.mkv')
|
|
assert.equal(parsed.segment, 3)
|
|
assert.equal(parsed.totalSegments, 10)
|
|
})
|
|
|
|
test('the base is equal for all segments of one file', ({ assert }) => {
|
|
const a = parseSubject('[1/9] - "a.tar.zst" yEnc (253/1000) 716554110')!
|
|
const b = parseSubject('[1/9] - "a.tar.zst" yEnc (254/1000) 716554110')!
|
|
assert.equal(a.base, b.base)
|
|
})
|
|
|
|
test('returns null for obfuscated or invalid subjects', ({ assert }) => {
|
|
assert.isNull(parseSubject('GZFDJc0hB3Y0FwwAznkk'))
|
|
assert.isNull(parseSubject('"name.rar" yEnc'))
|
|
assert.isNull(parseSubject('"name.rar" yEnc (0/5)'))
|
|
assert.isNull(parseSubject('"name.rar" yEnc (6/5)'))
|
|
assert.isNull(parseSubject('"" yEnc (1/5)'))
|
|
// A counter but no file name: still obfuscated.
|
|
assert.isNull(parseSubject('[7w] - 9BbEV2MrTi59GBTEFlVrssBrXNwXf2SK9cQEeDjg yEnc (1/12432)'))
|
|
assert.isNull(parseSubject('Re: Will somebody answer the question? (1/2)'))
|
|
})
|
|
|
|
test('finds the file name of subjects without a quoted one (unquotedName)', ({ assert }) => {
|
|
const cases: [string, string, number, number, number?][] = [
|
|
['DVDFab 8.2.0.5.rar (006/332)', 'DVDFab 8.2.0.5.rar', 6, 332],
|
|
['q3B9OrpKiCxUnzgtUGnp.part023.rar (104/137)', 'q3B9OrpKiCxUnzgtUGnp.part023.rar', 104, 137],
|
|
['New_Super_Mario_Bros._[Keygen].exe (1/2)', 'New_Super_Mario_Bros._[Keygen].exe', 1, 2],
|
|
['Emily_18_-_Bed.part01.rar Emily 18 bed video FULL NUDE (01/24)', 'Emily_18_-_Bed.part01.rar', 1, 24],
|
|
['[33/117] 674a37548b09.dat (1/1)', '674a37548b09.dat', 1, 1, 33],
|
|
["pal! [Mivina high(1).wmv\" yEnc] (323/349)", 'Mivina high(1).wmv', 323, 349],
|
|
['[03/21 Geroellheimer - S03E16.part01.rar" yEnc (1/50)', 'Geroellheimer - S03E16.part01.rar', 1, 50],
|
|
]
|
|
for (const [subject, name, segment, total, fileIndex] of cases) {
|
|
const parsed = parseSubject(subject)
|
|
assert.include(parsed, { name, segment, totalSegments: total }, subject)
|
|
if (fileIndex) assert.equal(parsed!.fileIndex, fileIndex)
|
|
}
|
|
})
|
|
})
|
|
|
|
test.group('subject / fileKey', () => {
|
|
test('differs per poster and per segment count, is stable otherwise', ({ assert }) => {
|
|
const key = fileKey('poster@a', '"x.rar" yEnc', 10)
|
|
assert.lengthOf(key, 40)
|
|
assert.equal(key, fileKey('poster@a', '"x.rar" yEnc', 10))
|
|
assert.notEqual(key, fileKey('poster@b', '"x.rar" yEnc', 10))
|
|
assert.notEqual(key, fileKey('poster@a', '"x.rar" yEnc', 11))
|
|
})
|
|
})
|
|
|
|
test.group('nntp / parseXrefGroups', () => {
|
|
test('extracts crossposted groups', ({ assert }) => {
|
|
assert.deepEqual(
|
|
parseXrefGroups('news.eweka.nl alt.binaries.nl:35801424104 alt.binaries.test:27275430913'),
|
|
['alt.binaries.nl', 'alt.binaries.test']
|
|
)
|
|
assert.deepEqual(parseXrefGroups(undefined), [])
|
|
})
|
|
})
|