From 18eeb9e523f557596552e9c3d21a5c1d542ad1a5 Mon Sep 17 00:00:00 2001 From: Steve Larson <9larsons@gmail.com> Date: Wed, 22 Feb 2023 09:52:23 -0600 Subject: [PATCH] moved spam prevention test no refs -spam prevention test was causing subsequent tests to fail randomly -moving to the end ensures (for now) we don't interrupt other tests -seems to be an issue with awaiting the jobservice which do concurrent --- .../e2e-api/webmentions/webmentions.test.js | 91 ++++++++++--------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/ghost/core/test/e2e-api/webmentions/webmentions.test.js b/ghost/core/test/e2e-api/webmentions/webmentions.test.js index 0fb7e4eac2..ad168b6eb7 100644 --- a/ghost/core/test/e2e-api/webmentions/webmentions.test.js +++ b/ghost/core/test/e2e-api/webmentions/webmentions.test.js @@ -39,49 +39,6 @@ describe('Webmentions (receiving)', function () { await dbUtils.truncate('brute'); }); - it('is rate limited against spamming mention requests', async function () { - await dbUtils.truncate('brute'); - const webmentionBlock = configUtils.config.get('spam').webmentions_block; - const targetUrl = new URL(urlUtils.getSiteUrl()); - const sourceUrl = new URL('http://testpage.com/external-article-brute-test/'); - const html = ` - Test Page - `; - nock(targetUrl.origin) - .persist() - .head(targetUrl.pathname) - .reply(200); - - nock(sourceUrl.origin) - .persist() - .get(sourceUrl.pathname) - .reply(200, html, {'Content-Type': 'text/html'}); - - const requests = []; - for (let i = 0; i < webmentionBlock.freeRetries + 1; i++) { - const req = await agent.post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href, - payload: {} - }) - .expectStatus(202); - - requests.push(req); - } - await Promise.all(requests); - - await agent - .post('/receive/') - .body({ - source: sourceUrl.href, - target: targetUrl.href, - payload: {} - }) - .expectStatus(429); - await allSettled(); - }); - it('can receive a webmention', async function () { const targetUrl = new URL('integrations/', urlUtils.getSiteUrl()); const sourceUrl = new URL('http://testpage.com/external-article/'); @@ -533,7 +490,7 @@ describe('Webmentions (receiving)', function () { assert.equal(mention.get('verified'), false); }); - it('can verifiy a webmention link', async function () { + it('can verify a webmention link', async function () { const targetUrl = new URL(urlUtils.getSiteUrl()); const sourceUrl = new URL('http://testpage.com/external-article-2/'); const html = ` @@ -592,4 +549,50 @@ describe('Webmentions (receiving)', function () { assert(mention); assert.equal(mention.get('verified'), true); }); + + // NOTE: this test needs to be last; it will disrupt other tests based on the fact we can't + // await the jobService completion for multiple concurrent requests + it('is rate limited against spamming mention requests', async function () { + await dbUtils.truncate('brute'); + const webmentionBlock = configUtils.config.get('spam').webmentions_block; + const targetUrl = new URL(urlUtils.getSiteUrl()); + const sourceUrl = new URL('http://testpage.com/external-article-brute-test/'); + const html = ` + Test Page + `; + nock(targetUrl.origin) + .persist() + .head(targetUrl.pathname) + .reply(200); + + nock(sourceUrl.origin) + .persist() + .get(sourceUrl.pathname) + .reply(200, html, {'Content-Type': 'text/html'}); + + const requests = []; + for (let i = 0; i < webmentionBlock.freeRetries + 1; i++) { + const req = await agent.post('/receive/') + .body({ + source: sourceUrl.href, + target: targetUrl.href, + payload: {} + }) + .expectStatus(202); + + requests.push(req); + } + await Promise.all(requests); + + await agent + .post('/receive/') + .body({ + source: sourceUrl.href, + target: targetUrl.href, + payload: {} + }) + .expectStatus(429); + await allSettled(); + }); + // NOTE: do not list other tests after the spam prevention test });