Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import { mkdtemp, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import { join } from 'node:path'import { describe, expect, it } from 'vitest'import { DEFAULT_BLOCKLIST, applyBlocklist, loadBlocklist,} from './blocklist.mjs'
const CLUSTER = [ 'did:plc:xwobeub6xxjz4xbuivit5jef', 'did:plc:redprhlfvosnp7wbfm3ko5th', 'did:plc:mf723pfwt53bueehasjkisoa', 'did:plc:fxsvokaipyin76axjcuswz6q', 'did:plc:bdlsxzbjlpjfqmhqyvykdyds', 'did:plc:sbmohhw5snspgfntx2e6q2ki', 'did:plc:qzwxjwybclb45kn2nwi6nzxp', 'did:plc:cyduqtoy6ercpxmb7adqhwsa',]
describe('operator blocklist', () => { it('loads the confirmed cluster from the repository blocklist', async () => { const { blocked, reason } = await loadBlocklist(DEFAULT_BLOCKLIST) expect(reason).toMatch(/coordinated/) expect(blocked.size).toBe(8) expect([...blocked.keys()].sort()).toEqual([...CLUSTER].sort()) })
it('excludes a blocked publication and leaves its other reasons intact', () => { const rows = [ { did: CLUSTER[0], spam: { excluded: false, reasons: ['duplicate-text'] }, }, { did: 'did:plc:notblocked', spam: { excluded: false, reasons: [] } }, ] const blocked = new Map([[CLUSTER[0], { did: CLUSTER[0] }]])
expect(applyBlocklist(rows, blocked)).toBe(1) expect(rows[0].spam).toEqual({ excluded: true, reasons: ['blocklist', 'duplicate-text'], }) expect(rows[1].spam).toEqual({ excluded: false, reasons: [] }) })
it('rejects a malformed blocklist path', async () => { const directory = await mkdtemp(join(tmpdir(), 'blocklist-')) try { await expect(loadBlocklist(join(directory, 'missing.json'))).rejects.toThrow( /cannot read blocklist/, ) const invalid = join(directory, 'invalid.json') await writeFile(invalid, '{"accounts":[{"did":"nope"}]}') expect((await loadBlocklist(invalid)).blocked.size).toBe(0) } finally { await rm(directory, { recursive: true, force: true }) } })})