const test = require('node:test'); const assert = require('node:assert/strict'); const block = require('../lib/downloadBlock'); const makerworld = require('../lib/importers/makerworld'); test('a blocked site stays blocked until it’s cleared', () => { assert.equal(block.isBlocked('makerworld'), false); block.block('makerworld', 'Prove you’re not a robot.'); assert.equal(block.isBlocked('makerworld'), true); const state = block.state('makerworld'); assert.equal(state.blocked, true); assert.equal(state.message, 'Prove you’re not a robot.'); assert.ok(state.since instanceof Date); // Blocking again keeps the original message and time. const again = block.block('makerworld', 'something else'); assert.equal(again.message, 'Prove you’re not a robot.'); block.clear('makerworld'); assert.deepEqual(block.state('makerworld'), { blocked: false }); }); test('MakerWorld’s anti-bot answers are recognised, ordinary refusals aren’t', () => { for (const text of ['Please verify you are not a robot', 'Just a moment…', 'Select in this order', 'Security check required', 'Verification required']) { assert.equal(makerworld.isChallengeText(text), true, text); } for (const text of ['Please log in to download models.', 'Model not found', '']) { assert.equal(makerworld.isChallengeText(text), false, text); } // An answer carrying a link is never a challenge. assert.equal(makerworld.isChallenge({ url: 'https://cdn/x.3mf', message: 'captcha' }), false); const problem = makerworld.downloadProblem({ error: 'Please verify you are not a robot' }); assert.equal(problem.challenged, true); assert.equal(makerworld.downloadProblem({ error: 'Please log in to download models.' }).tokenRejected, true); });