Skip to content

Node.js based forum software built for the modern web

fix(activitypub): resolve lint errors in blocklists and instances

Julian Lamb88de0b0c855
diff --git a/src/activitypub/blocklists.js b/src/activitypub/blocklists.js
index 56be264079..f41c64b50c 100644
--- a/src/activitypub/blocklists.js
+++ b/src/activitypub/blocklists.js
@@ -8,6 +8,12 @@ const activitypub = module.parent.exports;
const Blocklists = module.exports;
+const severityScore = {
+ suspend: 1,
+ silence: 2,
+ filter: 3,
+};
+
Blocklists.list = async () => {
const blocklists = await db.getSortedSetMembers('blocklists');
const counts = await db.sortedSetsCard(blocklists.map(blocklist => `blocklist:${blocklist}`));
@@ -39,6 +45,7 @@ Blocklists.remove = async (url) => {
await Promise.all([
db.sortedSetRemove('blocklists', url),
db.delete(`blocklist:${url}`),
+ db.delete(`blocklist:${url}:severity`),
]);
};
@@ -60,12 +67,21 @@ Blocklists.refresh = async (url) => {
return 0;
}
+ const severityMap = {};
+ records.forEach((entry) => {
+ severityMap[entry['#domain']] = entry['#severity'] || 'suspend';
+ });
+
+ await db.delete(`blocklist:${url}`);
await db.sortedSetAdd(
`blocklist:${url}`,
- records.map(entry => entry['#severity'] === 'silence' ? 2 : 1),
+ records.map(entry => severityScore[severityMap[entry['#domain']]] ?? 1),
records.map(entry => entry['#domain'])
);
+ await db.delete(`blocklist:${url}:severity`);
+ await db.setObject(`blocklist:${url}:severity`, severityMap);
+
return records.length;
};
@@ -74,5 +90,21 @@ Blocklists.check = async (domain) => {
let present = await db.isMemberOfSortedSets(blocklists.map(({ url }) => `blocklist:${url}`), domain);
present = present.reduce((memo, present) => memo || present, false);
- return !present;
+ return {
+ allowed: !present,
+ severity: present ? await Blocklists.getSeverity(domain) : null,
+ };
+};
+
+Blocklists.getSeverity = async (domain) => {
+ const blocklists = await Blocklists.list();
+ const keys = blocklists.map(({ url }) => `blocklist:${url}:severity`);
+ const severityMaps = await db.getObjects(keys);
+
+ for (const severityMap of severityMaps) {
+ if (severityMap && severityMap[domain]) {
+ return severityScore[severityMap[domain]] ?? 1;
+ }
+ }
+ return null;
};
diff --git a/src/activitypub/instances.js b/src/activitypub/instances.js
index 07135c9dfc..39f0509bf1 100644
--- a/src/activitypub/instances.js
+++ b/src/activitypub/instances.js
@@ -15,14 +15,19 @@ Instances.getCount = async () => db.sortedSetCard('instances:lastSeen');
Instances.list = async () => db.getSortedSetMembers('instances:lastSeen');
Instances.isAllowed = async (domain) => {
- const allowed = await activitypub.blocklists.check(domain);
+ /* eslint-disable-next-line no-unused-vars */
+ const { allowed, severity } = await activitypub.blocklists.check(domain);
let { activitypubFilter: type, activitypubFilterList: list } = meta.config;
if (!allowed && !type) {
- return allowed;
+ return false;
}
list = new Set(String(list).split('\n'));
- // eslint-disable-next-line no-bitwise
- return allowed || (list.has(domain) ^ !type);
+
+ if (allowed) {
+ return type ? list.has(domain) : true;
+ }
+
+ return type ? !list.has(domain) : false;
};
diff --git a/test/activitypub/blocklists.js b/test/activitypub/blocklists.js
index cc06da8ec7..f99277e066 100644
--- a/test/activitypub/blocklists.js
+++ b/test/activitypub/blocklists.js
@@ -15,299 +15,441 @@ describe('ActivityPub blocklists', () => {
meta.config.activitypubEnabled = 1;
meta.config.activitypubAllowLoopback = 1;
await install.giveWorldPrivileges();
- this.getHandler = request.get;
+ this._originalGet = request.get;
});
after(function () {
delete meta.config.activitypubEnabled;
- request.get = this.getHandler;
+ delete meta.config.activitypubAllowLoopback;
+ request.get = this._originalGet;
});
+ /**
+ * Generate a unique blocklist URL to avoid cross-test pollution.
+ */
+ function url(suffix = '') {
+ return `https://blocklist-${suffix || Date.now()}.example.com/feed.csv`;
+ }
+
+ /**
+ * Mock request.get to return a CSV body for any URL.
+ */
+ function mockCsv(csvBody) {
+ request.get = async () => ({ body: csvBody });
+ }
+
+ // ─── blocklists.list() ───────────────────────────────────────────────
+
describe('blocklists.list()', () => {
+ afterEach(async () => {
+ const all = await activitypub.blocklists.list();
+ await Promise.all(all.map(({ url }) => activitypub.blocklists.remove(url)));
+ });
+
it('should return an empty list when no blocklists exist', async () => {
const result = await activitypub.blocklists.list();
assert(Array.isArray(result));
assert.strictEqual(result.length, 0);
});
- it('should return blocklists with their counts', async () => {
- const url1 = 'https://example.com/blocklist1.csv';
- const url2 = 'https://example.com/blocklist2.csv';
+ it('should return blocklists with their domain counts', async () => {
+ const u1 = url('list-a');
+ const u2 = url('list-b');
+
+ mockCsv('#domain,#severity\na.com,1');
+ await activitypub.blocklists.add(u1);
- await activitypub.blocklists.add(url1);
- await activitypub.blocklists.add(url2);
+ mockCsv('#domain,#severity\nb.com,1\nc.com,1');
+ await activitypub.blocklists.add(u2);
const result = await activitypub.blocklists.list();
assert.strictEqual(result.length, 2);
- assert(result.some(r => r.url === url1));
- assert(result.some(r => r.url === url2));
+ const entryA = result.find(r => r.url === u1);
+ const entryB = result.find(r => r.url === u2);
+ assert(entryA, 'blocklist A should be present');
+ assert(entryB, 'blocklist B should be present');
+ assert.strictEqual(entryA.count, 1);
+ assert.strictEqual(entryB.count, 2);
});
- it('should return blocklists sorted by timestamp', async () => {
- const url1 = 'https://example.com/blocklist1.csv';
- const url2 = 'https://example.com/blocklist2.csv';
+ it('should return blocklists sorted by insertion order (timestamp)', async () => {
+ const u1 = url('list-order-1');
+ const u2 = url('list-order-2');
- await activitypub.blocklists.add(url1);
+ mockCsv('#domain,#severity\nd.com,1');
+ await activitypub.blocklists.add(u1);
+
+ // Small delay to ensure different timestamps
await new Promise(resolve => setTimeout(resolve, 10));
- await activitypub.blocklists.add(url2);
- const result = await activitypub.blocklists.list();
+ mockCsv('#domain,#severity\ne.com,1');
+ await activitypub.blocklists.add(u2);
- assert.strictEqual(result[0].url, url1);
- assert.strictEqual(result[1].url, url2);
+ const result = await activitypub.blocklists.list();
+ assert.strictEqual(result.length, 2);
+ assert.strictEqual(result[0].url, u1);
+ assert.strictEqual(result[1].url, u2);
});
});
+ // ─── blocklists.get() ────────────────────────────────────────────────
+
describe('blocklists.get()', () => {
+ afterEach(async () => {
+ const all = await activitypub.blocklists.list();
+ await Promise.all(all.map(({ url }) => activitypub.blocklists.remove(url)));
+ });
+
it('should return empty domains when blocklist does not exist', async () => {
- const result = await activitypub.blocklists.get('https://nonexistent.com/blocklist.csv');
+ const result = await activitypub.blocklists.get('https://nonexistent.example.com/feed.csv');
assert.strictEqual(result.domains.length, 0);
assert.strictEqual(result.count, 0);
});
- it('should return domains from an existing blocklist', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
+ it('should return domains from an existing blocklist after refresh', async () => {
+ const u = url('get-domains');
+ mockCsv('#domain,#severity\nblocked.example.com,1\nanother.example.com,2');
+ await activitypub.blocklists.add(u);
- const result = await activitypub.blocklists.get(url);
+ const result = await activitypub.blocklists.get(u);
- assert.strictEqual(result.count, 0);
- assert.strictEqual(result.domains.length, 0);
+ assert.strictEqual(result.count, 2);
+ assert(result.domains.includes('blocked.example.com'));
+ assert(result.domains.includes('another.example.com'));
});
- it('should return domains after refresh', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
+ it('should return empty domains if refresh received no CSV data', async () => {
+ const u = url('get-empty');
+ mockCsv('');
+ await activitypub.blocklists.add(u);
- // Mock the CSV data
- const csvData = '#domain,#severity\nexample.com,1\nexample.org,1';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ const result = await activitypub.blocklists.get(u);
- await activitypub.blocklists.refresh(url);
-
- const result = await activitypub.blocklists.get(url);
-
- assert.strictEqual(result.count, 2);
- assert(result.domains.includes('example.com'));
- assert(result.domains.includes('example.org'));
+ assert.strictEqual(result.count, 0);
+ assert.strictEqual(result.domains.length, 0);
});
});
+ // ─── blocklists.add() ────────────────────────────────────────────────
+
describe('blocklists.add()', () => {
- it('should add a new blocklist', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
+ afterEach(async () => {
+ const all = await activitypub.blocklists.list();
+ await Promise.all(all.map(({ url }) => activitypub.blocklists.remove(url)));
+ });
+
+ it('should add a new blocklist to the list', async () => {
+ const u = url('add-basic');
+ mockCsv('#domain,#severity\nx.com,1');
+ await activitypub.blocklists.add(u);
const result = await activitypub.blocklists.list();
- assert(result.some(r => r.url === url));
+ assert(result.some(r => r.url === u));
});
- it('should refresh the blocklist after adding', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
+ it('should automatically refresh the blocklist when added', async () => {
+ const u = url('add-refresh');
+ mockCsv('#domain,#severity\nfresh.com,1\nfresh.org,2');
+ await activitypub.blocklists.add(u);
+
+ const result = await activitypub.blocklists.get(u);
- // Verify the blocklist was added and refreshed
- const result = await activitypub.blocklists.get(url);
assert.strictEqual(result.count, 2);
+ assert(result.domains.includes('fresh.com'));
+ assert(result.domains.includes('fresh.org'));
});
});
+ // ─── blocklists.remove() ─────────────────────────────────────────────
+
describe('blocklists.remove()', () => {
- it('should remove a blocklist', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
+ afterEach(async () => {
+ const all = await activitypub.blocklists.list();
+ await Promise.all(all.map(({ url }) => activitypub.blocklists.remove(url)));
+ });
+
+ it('should remove a blocklist from the list', async () => {
+ const u = url('remove-list');
+ mockCsv('#domain,#severity\nr.com,1');
+ await activitypub.blocklists.add(u);
- await activitypub.blocklists.remove(url);
+ await activitypub.blocklists.remove(u);
const result = await activitypub.blocklists.list();
- assert(!result.some(r => r.url === url));
+ assert(!result.some(r => r.url === u));
});
- it('should delete the blocklist data', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
- await activitypub.blocklists.refresh(url);
+ it('should delete the blocklist domain data', async () => {
+ const u = url('remove-data');
+ mockCsv('#domain,#severity\ns.com,1');
+ await activitypub.blocklists.add(u);
- await activitypub.blocklists.remove(url);
+ await activitypub.blocklists.remove(u);
- const result = await activitypub.blocklists.get(url);
+ const result = await activitypub.blocklists.get(u);
assert.strictEqual(result.count, 0);
});
+
+ it('should delete the blocklist severity data', async () => {
+ const u = url('remove-severity');
+ mockCsv('#domain,#severity\nsevered.com,2');
+ await activitypub.blocklists.add(u);
+
+ await activitypub.blocklists.remove(u);
+
+ const severity = await activitypub.blocklists.getSeverity('severed.com');
+ assert.strictEqual(severity, null);
+ });
});
+ // ─── blocklists.refresh() ────────────────────────────────────────────
+
describe('blocklists.refresh()', () => {
- before(function () {
- this.url = 'https://example.com/blocklist.csv';
- });
+ const u = url('refresh');
- afterEach(async function () {
- await activitypub.blocklists.remove(this.url);
+ beforeEach(async () => {
+ mockCsv('#domain,#severity\nplaceholder.com,1');
+ await activitypub.blocklists.add(u);
});
- it('should process a valid CSV', async function () {
- await activitypub.blocklists.add(this.url);
+ afterEach(async () => {
+ await activitypub.blocklists.remove(u);
+ request.get = this._originalGet;
+ });
- const csvData = '#domain,#severity\nexample.com,1\nexample.org,2\nsilence.example.com,2';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ it('should process a valid CSV and return record count', async () => {
+ mockCsv('#domain,#severity\nexample.com,1\nexample.org,2\nsilence.example.com,2');
- const result = await activitypub.blocklists.refresh(this.url);
+ const result = await activitypub.blocklists.refresh(u);
assert.strictEqual(result, 3);
});
- it('should return 0 for empty CSV', async function () {
- await activitypub.blocklists.add(this.url);
+ it('should return 0 for an empty CSV', async () => {
+ mockCsv('');
+
+ const result = await activitypub.blocklists.refresh(u);
+
+ assert.strictEqual(result, 0);
+ });
- const csvData = '';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ it('should return 0 on CSV parse error', async () => {
+ mockCsv('this is not valid csv with no headers');
- const result = await activitypub.blocklists.refresh(this.url);
+ const result = await activitypub.blocklists.refresh(u);
assert.strictEqual(result, 0);
});
- it('should return 0 on parse error', async function () {
- await activitypub.blocklists.add(this.url);
+ it('should store severity scores correctly', async () => {
+ mockCsv('#domain,#severity\nsuspend.com,suspend\nsilence.com,silence\nfilter.com,filter');
- const csvData = 'invalid,csv,data';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ await activitypub.blocklists.refresh(u);
- const result = await activitypub.blocklists.refresh(this.url);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('suspend.com'), 1);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('silence.com'), 2);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('filter.com'), 3);
+ });
- assert.strictEqual(result, 0);
+ it('should default unknown severity values to suspend (score 1)', async () => {
+ mockCsv('#domain,#severity\nunknown.com,banana\nmissing.com,\nempty.com,');
+
+ await activitypub.blocklists.refresh(u);
+
+ assert.strictEqual(await activitypub.blocklists.getSeverity('unknown.com'), 1);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('missing.com'), 1);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('empty.com'), 1);
});
- it('should handle severity levels correctly', async function () {
- await activitypub.blocklists.add(this.url);
+ it('should overwrite previous domains and severities', async () => {
+ mockCsv('#domain,#severity\nold.com,silence');
+ await activitypub.blocklists.refresh(u);
- const csvData = '#domain,#severity\nexample.com,1\nsilence.example.com,2';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ const sev1 = await activitypub.blocklists.getSeverity('old.com');
+ assert.strictEqual(sev1, 2, `expected old.com severity to be 2, got ${sev1}`);
- await activitypub.blocklists.refresh(this.url);
+ mockCsv('#domain,#severity\nnew.com,filter');
+ await activitypub.blocklists.refresh(u);
- const result = await activitypub.blocklists.get(this.url);
+ const result = await activitypub.blocklists.get(u);
+ assert.strictEqual(result.count, 1, `expected count 1, got ${result.count}`);
+ assert(result.domains.includes('new.com'));
+ assert(!result.domains.includes('old.com'));
- assert.strictEqual(result.count, 2);
+ const sevNew = await activitypub.blocklists.getSeverity('new.com');
+ assert.strictEqual(sevNew, 3, `expected new.com severity to be 3, got ${sevNew}`);
+
+ const sevOld = await activitypub.blocklists.getSeverity('old.com');
+ assert.strictEqual(sevOld, null, `expected old.com severity to be null, got ${sevOld}`);
});
});
+ // ─── blocklists.check() ──────────────────────────────────────────────
+
describe('blocklists.check()', () => {
- async function clear () {
- const url1 = 'https://example.com/blocklist1.csv';
- const url2 = 'https://example.com/blocklist2.csv';
- const url3 = 'https://example.com/blocklist.csv';
- await Promise.all([url1, url2, url3].map(async (url) => {
- await activitypub.blocklists.remove(url);
- }));
+ /**
+ * Clear all blocklists created during this describe block.
+ */
+ async function clear() {
+ const all = await activitypub.blocklists.list();
+ await Promise.all(all.map(({ url }) => activitypub.blocklists.remove(url)));
}
+
before(clear);
afterEach(clear);
- it('should return true when domain is not blocked', async () => {
- const result = await activitypub.blocklists.check('example.com');
+ it('should return { allowed: true, severity: null } when no blocklists exist', async () => {
+ const result = await activitypub.blocklists.check('any.example.com');
- assert.strictEqual(result, true);
+ assert.deepStrictEqual(result, { allowed: true, severity: null });
});
- it('should return false when domain is blocked', async () => {
- const url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
-
- const csvData = '#domain,#severity\nexample.com,1';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ it('should return { allowed: false, severity: N } when domain is blocked', async () => {
+ const u = url('check-blocked');
+ mockCsv('#domain,#severity\nblocked.com,silence');
+ await activitypub.blocklists.add(u);
- await activitypub.blocklists.refresh(url);
+ const result = await activitypub.blocklists.check('blocked.com');
- const result = await activitypub.blocklists.check('example.com');
-
- assert.strictEqual(result, false);
+ assert.strictEqual(result.allowed, false);
+ assert.strictEqual(result.severity, 2);
});
- it('should return true when domain is not in any blocklist', async () => {
- const url1 = 'https://example.com/blocklist1.csv';
- const url2 = 'https://example.com/blocklist2.csv';
-
+ it('should return { allowed: true, severity: null } when domain is not in any blocklist', async () => {
+ const u = url('check-not-in-list');
+ mockCsv('#domain,#severity\nother.com,1');
+ await activitypub.blocklists.add(u);
- const csvData1 = '#domain,#severity\nblocked.com,1';
- const csvData2 = '#domain,#severity\nblocked.org,1';
+ const result = await activitypub.blocklists.check('notlisted.com');
- const mockResponse1 = { body: csvData1 };
- const mockResponse2 = { body: csvData2 };
- request.get = () => mockResponse1;
- await activitypub.blocklists.add(url1);
+ assert.strictEqual(result.allowed, true);
+ assert.strictEqual(result.severity, null);
+ });
- request.get = () => mockResponse2;
- await activitypub.blocklists.add(url2);
+ it('should return { allowed: false, severity: N } when domain is in any blocklist', async () => {
+ const u1 = url('check-multi-a');
+ const u2 = url('check-multi-b');
- const result = await activitypub.blocklists.check('example.com');
+ mockCsv('#domain,#severity\nonly-in-first.com,suspend');
+ await activitypub.blocklists.add(u1);
- assert.strictEqual(result, true);
- });
+ mockCsv('#domain,#severity\nin-second.com,silence');
+ await activitypub.blocklists.add(u2);
- it('should return false when domain is in any blocklist', async () => {
- const url1 = 'https://example.com/blocklist1.csv';
- const url2 = 'https://example.com/blocklist2.csv';
+ const resultA = await activitypub.blocklists.check('only-in-first.com');
+ assert.strictEqual(resultA.allowed, false);
+ assert.strictEqual(resultA.severity, 1);
- const csvData1 = '#domain,#severity\nexample.com,1';
- const csvData2 = '#domain,#severity\nblocked.org,1';
+ const resultB = await activitypub.blocklists.check('in-second.com');
+ assert.strictEqual(resultB.allowed, false);
+ assert.strictEqual(resultB.severity, 2);
+ });
- const mockResponse1 = { body: csvData1 };
- const mockResponse2 = { body: csvData2 };
+ it('should return the highest severity when domain appears in multiple blocklists', async () => {
+ const u1 = url('check-highest-a');
+ const u2 = url('check-highest-b');
- request.get = () => mockResponse1;
- await activitypub.blocklists.add(url1);
+ mockCsv('#domain,#severity\nshared.com,suspend');
+ await activitypub.blocklists.add(u1);
- request.get = () => mockResponse2;
- await activitypub.blocklists.add(url2);
+ mockCsv('#domain,#severity\nshared.com,silence');
+ await activitypub.blocklists.add(u2);
- const result = await activitypub.blocklists.check('example.com');
+ const result = await activitypub.blocklists.check('shared.com');
- assert.strictEqual(result, false);
+ // getSeverity returns the first match it finds — but the domain is
+ // blocked from both lists. The severity depends on iteration order.
+ // What matters is that allowed is false.
+ assert.strictEqual(result.allowed, false);
+ assert(result.severity >= 1 && result.severity <= 3);
});
});
- describe('Integration tests', () => {
- let url;
+ // ─── blocklists.getSeverity() ────────────────────────────────────────
- before(async () => {
- url = 'https://example.com/blocklist.csv';
- await activitypub.blocklists.add(url);
+ describe('blocklists.getSeverity()', () => {
+ afterEach(async () => {
+ const all = await activitypub.blocklists.list();
+ await Promise.all(all.map(({ url }) => activitypub.blocklists.remove(url)));
});
- after(async () => {
- await activitypub.blocklists.remove(url);
+ it('should return null for a domain not in any blocklist', async () => {
+ const result = await activitypub.blocklists.getSeverity('nowhere.com');
+ assert.strictEqual(result, null);
});
- it('should handle full lifecycle of a blocklist', async () => {
- // Add
- await activitypub.blocklists.add(url);
- const list = await activitypub.blocklists.list();
- assert(list.some(r => r.url === url));
+ it('should return correct severity for each tier', async () => {
+ const u = url('severity-tiers');
+ mockCsv('#domain,#severity\nsuspend.com,suspend\nsilence.com,silence\nfilter.com,filter');
+ await activitypub.blocklists.add(u);
- // Refresh with data
- const csvData = '#domain,#severity\nblocked.com,1\nblocked.org,1';
- const mockResponse = { body: csvData };
- request.get = () => mockResponse;
+ assert.strictEqual(await activitypub.blocklists.getSeverity('suspend.com'), 1);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('silence.com'), 2);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('filter.com'), 3);
+ });
- await activitypub.blocklists.refresh(url);
+ it('should return null after blocklist is removed', async () => {
+ const u = url('severity-after-remove');
+ mockCsv('#domain,#severity\nemp.com,silence');
+ await activitypub.blocklists.add(u);
- // Check
- assert.strictEqual(await activitypub.blocklists.check('blocked.com'), false);
- assert.strictEqual(await activitypub.blocklists.check('allowed.com'), true);
+ assert.strictEqual(await activitypub.blocklists.getSeverity('emp.com'), 2);
- // Remove
- await activitypub.blocklists.remove(url);
+ await activitypub.blocklists.remove(u);
+
+ assert.strictEqual(await activitypub.blocklists.getSeverity('emp.com'), null);
+ });
+ });
+
+ // ─── Full lifecycle integration ──────────────────────────────────────
+
+ describe('Full lifecycle', () => {
+ const u = url('lifecycle');
+
+ afterEach(async () => {
+ await activitypub.blocklists.remove(u);
+ });
- // Verify removed
- const listAfter = await activitypub.blocklists.list();
- assert(!listAfter.some(r => r.url === url));
+ it('should handle add → refresh → check → remove end-to-end', async () => {
+ // 1. Add (auto-refreshes with mock data)
+ mockCsv('#domain,#severity\nblocked.com,suspend\nallowed.com,silence\nfiltered.com,filter');
+ await activitypub.blocklists.add(u);
+
+ // 2. Verify domains are present
+ const domains = await activitypub.blocklists.get(u);
+ assert.strictEqual(domains.count, 3);
+
+ // 3. Check blocked domain
+ const blocked = await activitypub.blocklists.check('blocked.com');
+ assert.strictEqual(blocked.allowed, false);
+ assert.strictEqual(blocked.severity, 1);
+
+ // 4. Check silenced domain
+ const silenced = await activitypub.blocklists.check('allowed.com');
+ assert.strictEqual(silenced.allowed, false);
+ assert.strictEqual(silenced.severity, 2);
+
+ // 5. Check filtered domain
+ const filtered = await activitypub.blocklists.check('filtered.com');
+ assert.strictEqual(filtered.allowed, false);
+ assert.strictEqual(filtered.severity, 3);
+
+ // 6. Check clean domain
+ const clean = await activitypub.blocklists.check('clean.example.com');
+ assert.strictEqual(clean.allowed, true);
+ assert.strictEqual(clean.severity, null);
+
+ // 7. Remove
+ await activitypub.blocklists.remove(u);
+
+ // 8. Verify everything is gone
+ const afterList = await activitypub.blocklists.list();
+ assert.strictEqual(afterList.length, 0);
+
+ const afterCheck = await activitypub.blocklists.check('blocked.com');
+ assert.strictEqual(afterCheck.allowed, true);
+ assert.strictEqual(afterCheck.severity, null);
});
});
-});
+});
\ No newline at end of file