2023-02-09 09:57:48 +03:00
|
|
|
const {
|
2023-02-13 19:14:16 +03:00
|
|
|
agentProvider,
|
|
|
|
fixtureManager,
|
2023-02-09 09:57:48 +03:00
|
|
|
mockManager,
|
|
|
|
dbUtils,
|
|
|
|
configUtils
|
|
|
|
} = require('../../utils/e2e-framework');
|
2023-01-20 16:32:50 +03:00
|
|
|
const models = require('../../../core/server/models');
|
|
|
|
const assert = require('assert');
|
|
|
|
const urlUtils = require('../../../core/shared/url-utils');
|
|
|
|
const nock = require('nock');
|
2023-02-17 15:05:36 +03:00
|
|
|
const jobsService = require('../../../core/server/services/mentions-jobs');
|
2023-01-30 17:46:31 +03:00
|
|
|
const DomainEvents = require('@tryghost/domain-events');
|
2023-01-20 16:32:50 +03:00
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
async function allSettled() {
|
|
|
|
await jobsService.allSettled();
|
|
|
|
await DomainEvents.allSettled();
|
|
|
|
}
|
|
|
|
|
2023-01-20 16:32:50 +03:00
|
|
|
describe('Webmentions (receiving)', function () {
|
|
|
|
let agent;
|
2023-02-22 18:19:09 +03:00
|
|
|
|
2023-01-20 16:32:50 +03:00
|
|
|
before(async function () {
|
|
|
|
agent = await agentProvider.getWebmentionsAPIAgent();
|
|
|
|
await fixtureManager.init('posts');
|
|
|
|
});
|
2023-01-30 14:11:30 +03:00
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
beforeEach(async function () {
|
|
|
|
await allSettled();
|
|
|
|
mockManager.disableNetwork();
|
|
|
|
mockManager.mockLabsEnabled('webmentions');
|
2023-02-23 13:42:14 +03:00
|
|
|
mockManager.mockLabsEnabled('webmentionEmails');
|
2023-01-25 16:10:29 +03:00
|
|
|
});
|
|
|
|
|
2023-01-30 17:45:16 +03:00
|
|
|
afterEach(async function () {
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-01-25 16:10:29 +03:00
|
|
|
mockManager.restore();
|
2023-02-13 10:16:56 +03:00
|
|
|
await dbUtils.truncate('brute');
|
2023-01-25 16:10:29 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can receive a webmention', async function () {
|
2023-01-30 14:11:30 +03:00
|
|
|
const targetUrl = new URL('integrations/', urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article/');
|
2023-01-25 16:10:29 +03:00
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body></body></html>
|
|
|
|
`;
|
|
|
|
|
2023-01-30 14:11:30 +03:00
|
|
|
nock(targetUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-01-30 14:11:30 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-01-30 14:11:30 +03:00
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
2023-01-25 16:10:29 +03:00
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
2023-01-30 14:11:30 +03:00
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href,
|
2023-01-25 16:10:29 +03:00
|
|
|
withExtension: true // test payload recorded
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-01-25 16:10:29 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/external-article/'});
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('target'), urlUtils.getSiteUrl() + 'integrations/');
|
|
|
|
assert.ok(mention.get('resource_id'));
|
|
|
|
assert.equal(mention.get('resource_type'), 'post');
|
|
|
|
assert.equal(mention.get('source_title'), 'Test Page');
|
|
|
|
assert.equal(mention.get('source_excerpt'), 'Test description');
|
|
|
|
assert.equal(mention.get('source_author'), 'John Doe');
|
|
|
|
assert.equal(mention.get('payload'), JSON.stringify({
|
|
|
|
withExtension: true
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2023-02-13 10:47:02 +03:00
|
|
|
it('will update a mentions source metadata', async function () {
|
|
|
|
const targetUrl = new URL(urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/update-mention-test-1/');
|
|
|
|
|
|
|
|
testCreatingTheMention: {
|
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body></body></html>
|
|
|
|
`;
|
|
|
|
|
|
|
|
nock(targetUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-13 10:47:02 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-13 10:47:02 +03:00
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-13 10:47:02 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/update-mention-test-1/'});
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('source_title'), 'Test Page');
|
|
|
|
assert.equal(mention.get('source_excerpt'), 'Test description');
|
|
|
|
assert.equal(mention.get('source_author'), 'John Doe');
|
|
|
|
|
|
|
|
break testCreatingTheMention;
|
|
|
|
}
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
nock.cleanAll();
|
|
|
|
|
2023-02-13 10:47:02 +03:00
|
|
|
testUpdatingTheMention: {
|
|
|
|
const html = `
|
|
|
|
<html><head><title>New Title</title><meta name="description" content="New Description"><meta name="author" content="big man with a beard"></head><body></body></html>
|
|
|
|
`;
|
|
|
|
|
|
|
|
nock(targetUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-13 10:47:02 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-13 10:47:02 +03:00
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-13 10:47:02 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/update-mention-test-1/'});
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('source_title'), 'New Title');
|
|
|
|
assert.equal(mention.get('source_excerpt'), 'New Description');
|
|
|
|
assert.equal(mention.get('source_author'), 'big man with a beard');
|
|
|
|
|
|
|
|
break testUpdatingTheMention;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-13 19:14:16 +03:00
|
|
|
it('will delete a mention when the target in Ghost was deleted', async function () {
|
|
|
|
const post = await models.Post.findOne({id: fixtureManager.get('posts', 0).id});
|
|
|
|
const targetUrl = new URL(urlUtils.getSiteUrl() + post.get('slug') + '/');
|
|
|
|
const sourceUrl = new URL('http://testpage.com/update-mention-test-2/');
|
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body></body></html>
|
|
|
|
`;
|
2023-02-22 18:19:09 +03:00
|
|
|
|
2023-02-13 19:14:16 +03:00
|
|
|
nock(sourceUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-13 19:14:16 +03:00
|
|
|
.get(sourceUrl.pathname)
|
2023-02-17 14:56:44 +03:00
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
2023-02-13 19:14:16 +03:00
|
|
|
|
|
|
|
testCreatingTheMention: {
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-13 19:14:16 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/update-mention-test-2/'});
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('resource_id'), post.id);
|
|
|
|
assert.equal(mention.get('source_title'), 'Test Page');
|
|
|
|
assert.equal(mention.get('source_excerpt'), 'Test description');
|
|
|
|
assert.equal(mention.get('source_author'), 'John Doe');
|
|
|
|
|
|
|
|
break testCreatingTheMention;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move post to draft and mark page as 404
|
|
|
|
await models.Post.edit({status: 'draft'}, {id: post.id});
|
|
|
|
|
|
|
|
nock(targetUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-13 19:14:16 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(404);
|
|
|
|
|
|
|
|
testUpdatingTheMention: {
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-13 19:14:16 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/update-mention-test-2/'});
|
|
|
|
assert(mention);
|
|
|
|
|
|
|
|
// Check resource id was not cleared
|
|
|
|
assert.equal(mention.get('resource_id'), post.id);
|
|
|
|
|
|
|
|
// Check deleted
|
|
|
|
assert.equal(mention.get('deleted'), true);
|
|
|
|
|
|
|
|
break testUpdatingTheMention;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-01-30 14:11:30 +03:00
|
|
|
it('can receive a webmention to homepage', async function () {
|
|
|
|
const targetUrl = new URL(urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-2/');
|
2023-01-25 16:10:29 +03:00
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body></body></html>
|
|
|
|
`;
|
2023-01-30 14:11:30 +03:00
|
|
|
|
|
|
|
nock(targetUrl.origin)
|
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-01-30 14:11:30 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/external-article-2/'});
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('target'), urlUtils.getSiteUrl());
|
|
|
|
assert.ok(!mention.get('resource_id'));
|
|
|
|
assert.equal(mention.get('resource_type'), null);
|
|
|
|
assert.equal(mention.get('source_title'), 'Test Page');
|
|
|
|
assert.equal(mention.get('source_excerpt'), 'Test description');
|
|
|
|
assert.equal(mention.get('source_author'), 'John Doe');
|
|
|
|
assert.equal(mention.get('payload'), JSON.stringify({}));
|
|
|
|
});
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
it('can verify a webmention <a> link', async function () {
|
2023-02-13 10:16:56 +03:00
|
|
|
const targetUrl = new URL(urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-2/');
|
|
|
|
const html = `
|
2023-02-22 18:19:09 +03:00
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body><a href="${urlUtils.getSiteUrl()}">your cool website mentioned</a></body></html>
|
2023-02-13 10:16:56 +03:00
|
|
|
`;
|
|
|
|
nock(targetUrl.origin)
|
2023-02-13 19:14:16 +03:00
|
|
|
.persist()
|
2023-02-13 10:16:56 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
2023-02-13 19:14:16 +03:00
|
|
|
.persist()
|
2023-02-13 10:16:56 +03:00
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
2023-02-13 10:16:56 +03:00
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-13 10:16:56 +03:00
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/external-article-2/'});
|
|
|
|
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('verified'), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can verify a webmention <a> link to post', async function () {
|
|
|
|
const targetUrl = new URL('integrations/', urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-3/');
|
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body><a href="${targetUrl.toString()}">your cool website mentioned</a></body></html>
|
|
|
|
`;
|
|
|
|
nock(targetUrl.origin)
|
|
|
|
.persist()
|
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
|
|
|
.persist()
|
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
2023-02-13 10:16:56 +03:00
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
2023-02-22 18:19:09 +03:00
|
|
|
target: targetUrl.href
|
2023-02-13 10:16:56 +03:00
|
|
|
})
|
2023-02-22 18:19:09 +03:00
|
|
|
.expectStatus(202);
|
|
|
|
|
|
|
|
await allSettled();
|
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: sourceUrl.href});
|
|
|
|
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('verified'), true);
|
2023-02-13 10:16:56 +03:00
|
|
|
});
|
2023-02-17 14:56:44 +03:00
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
it('can verify a webmention <a> link to post with tracking parameters', async function () {
|
|
|
|
const targetUrl = new URL('integrations/', urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-4/');
|
2023-02-17 14:56:44 +03:00
|
|
|
const html = `
|
2023-02-22 18:19:09 +03:00
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body><a href="${targetUrl.toString()}?ref=1234-working">your cool website mentioned</a></body></html>
|
2023-02-17 14:56:44 +03:00
|
|
|
`;
|
|
|
|
nock(targetUrl.origin)
|
2023-02-22 18:19:09 +03:00
|
|
|
.persist()
|
2023-02-17 14:56:44 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
|
|
|
.persist()
|
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-17 14:56:44 +03:00
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
const mention = await models.Mention.findOne({source: sourceUrl.href});
|
2023-02-17 14:56:44 +03:00
|
|
|
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('verified'), true);
|
|
|
|
});
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
it('marks as unverified if url not present on source', async function () {
|
|
|
|
const targetUrl = new URL('html-ipsum', urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-not-present/');
|
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body><a href="${urlUtils.getSiteUrl()}">your cool website mentioned</a></body></html>
|
|
|
|
`;
|
|
|
|
nock(targetUrl.origin).persist()
|
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
|
|
|
.persist()
|
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
|
|
|
await allSettled();
|
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: sourceUrl.toString()});
|
|
|
|
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('verified'), false);
|
|
|
|
});
|
|
|
|
|
2023-02-22 18:52:23 +03:00
|
|
|
it('can verify a webmention <img> link', async function () {
|
2023-02-17 14:56:44 +03:00
|
|
|
const targetUrl = new URL(urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-2/');
|
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body><img src="${urlUtils.getSiteUrl()}"></body></html>
|
|
|
|
`;
|
2023-02-22 18:19:09 +03:00
|
|
|
nock(targetUrl.origin).persist()
|
2023-02-17 14:56:44 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
|
|
|
.persist()
|
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-17 14:56:44 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/external-article-2/'});
|
|
|
|
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('verified'), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can verify a webmention <video> link', async function () {
|
|
|
|
const targetUrl = new URL(urlUtils.getSiteUrl());
|
|
|
|
const sourceUrl = new URL('http://testpage.com/external-article-2/');
|
|
|
|
const html = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body><video src="${urlUtils.getSiteUrl()}"></body></html>
|
|
|
|
`;
|
2023-02-22 18:19:09 +03:00
|
|
|
nock(targetUrl.origin).persist()
|
2023-02-17 14:56:44 +03:00
|
|
|
.head(targetUrl.pathname)
|
|
|
|
.reply(200);
|
|
|
|
|
|
|
|
nock(sourceUrl.origin)
|
|
|
|
.persist()
|
|
|
|
.get(sourceUrl.pathname)
|
|
|
|
.reply(200, html, {'Content-Type': 'text/html'});
|
|
|
|
|
|
|
|
await agent.post('/receive')
|
|
|
|
.body({
|
|
|
|
source: sourceUrl.href,
|
|
|
|
target: targetUrl.href
|
|
|
|
})
|
|
|
|
.expectStatus(202);
|
|
|
|
|
2023-02-22 18:19:09 +03:00
|
|
|
await allSettled();
|
2023-02-17 14:56:44 +03:00
|
|
|
|
|
|
|
const mention = await models.Mention.findOne({source: 'http://testpage.com/external-article-2/'});
|
|
|
|
|
|
|
|
assert(mention);
|
|
|
|
assert.equal(mention.get('verified'), true);
|
|
|
|
});
|
2023-02-22 18:52:23 +03:00
|
|
|
|
|
|
|
// 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 = `
|
|
|
|
<html><head><title>Test Page</title><meta name="description" content="Test description"><meta name="author" content="John Doe"></head><body></body></html>
|
|
|
|
`;
|
|
|
|
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
|
2023-01-20 16:32:50 +03:00
|
|
|
});
|