Commit Graph

38 Commits

Author SHA1 Message Date
Simon Backx
b6519e0f1f
Removed usage of unquoted ids in filter strings (#19070)
fixes GRO-34
fixes GRO-33

This is a revision of a previous commit, that broke the browser tests
because changes in the data generator (requiring bookshelf had side
effects).

This adds a new way to run all tests with enforced numeric ObjectIDs.
These numeric ids cause issues if they are used withing NQL filters. So
they surface tiny bugs in our codebase.

You can run tests using this option via:
NUMERIC_IDS=1 yarn test:e2e

Removed some defensive logic that could be explained by this discovered
issue.
2023-11-21 09:45:36 +01:00
Simon Backx
d5492bd63c
Revert "Removed usage of unquoted ids in filter strings" (#19052)
Reverts TryGhost/Ghost#19031

Browser tests are failing with an unknown cause
2023-11-20 13:50:07 +00:00
Simon Backx
320eaac4c4
Removed usage of unquoted ids in filter strings (#19031)
fixes GRO-34
fixes GRO-33

This also adds a new way to run all tests with enforced numeric ObjectIDs.
These numeric ids cause issues if they are used withing NQL filters. So they
surface tiny bugs in our codebase.

You can run tests using this option via:
NUMERIC_IDS=1 yarn test:e2e

Also removed some defensive logic that could be explained by unquoted ids.
2023-11-20 14:00:31 +01:00
Simon Backx
b51e12d90f
Added emails for recommendations (#18361)
fixes https://github.com/TryGhost/Product/issues/3938
2023-09-26 15:29:17 +00:00
Simon Backx
098f4353a7
Disabled network retries for webmentions in tests (#18269)
refs https://ghost.slack.com/archives/C02G9E68C/p1695296293667689

- We block all outgoing networking by default in tests. When editing a
post/page, Ghost tries to send a webmention. Because of my earlier
changes
(1e3232cf82)
it tries 3 times - all network requests fail instantly when networking
is disabled - but it adds a delay in between those retries. So my change
disables retries during tests.
- Adds a warning when afterEach hook tooks longer than 2s due to
awaiting jobs/events
- We reduce the amount of webmentions that are send, by only sending
webmentions for added or removed urls, no longer when a post html is
changed (unless post is published/removed).
2023-09-21 16:17:05 +02:00
Simon Backx
1e3232cf82
Improved webmention stability in case of slow external servers (#18242)
refs https://github.com/TryGhost/Product/issues/3850

- Added a recheck for recommendation related webmentions after boot (to
check missed webmentions during down time)
- Increased general timeouts to 15s for all webmention related HTTP
requests. Instead, increased retries to 3.
- Increased timeout for fetching webmention metadata from 2s to 15s
- Added more logging about verification and deletion status of
webmentions
2023-09-20 13:09:47 +02:00
Simon Backx
96fefaea69
Added well known recommendations service (#17895)
fixes https://github.com/TryGhost/Product/issues/3797 
fixes https://github.com/TryGhost/Product/issues/3776 
fixes https://github.com/TryGhost/Product/issues/3798

- Added support for storing json webmentions
- Improved handling deleted webmentions (set deleted to true instead of verified to false)
2023-08-31 14:57:18 +00:00
Hannah Wolfe
6161f94910
Updated to use assert/strict everywhere (#17047)
refs: https://github.com/TryGhost/Toolbox/issues/595

We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default.

This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results:
- Url matching needs to be done on `url.href` see aa58b354a4
- Null and undefined are not the same thing,  there were a few cases of this being confused
- Particularly questionable changes in [PostExporter tests](c1a468744b) tracked [here](https://github.com/TryGhost/Team/issues/3505).
- A typo see eaac9c293a

Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
2023-06-21 09:56:59 +01:00
Chris Raible
71aca468b3
Fixed flaky test: Can generate a mentions report (#16592)
refs TryGhost/Team#2844

- assertion was comparing a constant `now` with a `new Date()` that was
made on the next line — by passing now in as the end date to
`getMentionReport`, the end date should always equal the constant
- intent of the test is just to make sure a mentions report can
generate, so we can just use the variable now instead of creating new
Date() objects
2023-04-07 19:03:22 -07:00
Chris Raible
563793c7ed
Added retries for all known flaky tests (#16582)
refs TryGhost/Team#2833

- for mocha tests, we can add `this.retries(1)` to any flaky tests
- for playwright tests, we can add `test.describe.configure({ retries:
1})` to any `describe` block
- not a long-term solution, but it should help mitigate issues with flaky
tests in short term
2023-04-07 00:37:01 -07:00
Fabien "egg" O'Carroll
0262083bb0 Added getMentionReport method to MentionsAPI
This will be used by the mentions-report-email package to generate the
data used for the report emails
2023-03-15 21:22:13 +05:30
Steve Larson
6b29e51c67
🐛 enabled mentions for pages (#16388)
no refs
-mentions were not being sent for pages
-added listeners for page events (published, unpublished, edited)
2023-03-09 17:31:29 -06:00
Steve Larson
9e58181398
combined fetch for metadata and verification (#16330)
refs TryGhost/Team#2582
-removed duplicative fetch request
-added mention as type in oembed service
2023-02-28 08:39:28 -06:00
Simon Backx
603e0909c9 Fixed webmentions unit test coverage
no issue

Try catch was not covered
2023-02-22 16:36:11 +01:00
Simon Backx
f45d1810a6 Improved webmention receiving E2E test reliability
refs https://github.com/TryGhost/Team/issues/2596
2023-02-22 16:19:56 +01:00
Ronald Langeveld
ba0c99d6fb
Added page resource type to Mentions (#16302)
closes https://github.com/TryGhost/Team/issues/2572

The mentions browse output previously only showed resource info if the
mentioned resource type was a `post`.
Additionally, the `resource_type` column basically defaulted to `post`
regardless whether it was a page or in fact a post.

With this change we now have `resource_type` wired in to correctly
determine if the mentioned url was a page or a post.
2023-02-21 13:02:47 +08:00
Steve Larson
2d84b7d990
Upgraded got package from v9.6.0 to v11.8.6 (#16261)
Refs TryGhost/Team#2459
-upgraded got from v9.6.0 to v11.8.6 to support following redirects (and
other fixes)
-got v12+ requires ESM, so we do not want to upgrade further at this
time
-required changes to a few libraries that use externalRequests
-mention discovery service tests updated to test for follow redirects
2023-02-20 09:33:11 -06:00
Fabien "egg" O'Carroll
8908a51547 Improved verification logic for Mentions
refs https://github.com/TryGhost/Team/issues/2550

By using cheerio to parse the HTML we can correctly look for elements
which use the target URL as the href attribute, rather than doing a
plaintext search. This closer to what the spec says.
2023-02-17 19:07:11 +07:00
Fabien "egg" O'Carroll
e14d2e662b Wired up verification to MentionsAPI
refs https://github.com/TryGhost/Team/issues/2550

Whilst this isn't ideal making multiple requests for the same site
it's a first step towards verification properties, and can be
refactored to improve performance later. With the current volume of
incoming Webmentions we've seen so far this shouldn't be a problem.
2023-02-17 19:07:11 +07:00
Steve Larson
1e00bd2af9 Handled empty content when sending webmentions
refs https://ghost.slack.com/archives/C02G9E68C/p1676564978732119

- `cheerio` errors when trying to parse `null`
2023-02-17 10:46:48 +01:00
Fabien "egg" O'Carroll
a310ec2e3e Fixed Mention unit test
refs https://github.com/TryGhost/Ghost/commit/c6b90b6ac
2023-02-16 14:37:22 +07:00
Fabien "egg" O'Carroll
90b7a3f4d0 Added verified member and verify method to Mention entity
closes https://github.com/TryGhost/Team/issues/2548

Rather than use a setter here we've used a verify method which takes the HTML
string and naively validates that the target URL is present. This is so that the
logic of verification is encapsulated in the Mention, and should mean that
erroneous verification doesn't happen.

We could consider down the line that the verify method fetches the content
itself, but if we're to do that we should pass in `got` as a param, so that it's
possible to stub in tests.

One thing to think about when it comes time to making this as performant as
possible is doing a single fetch of the source document and using that for
verification and metadata extraction. At that point we should probably
consolidate both of those operations, either moving the metadata extraction into
the Mention entity (passing in any necessary deps) OR we move the verification
out to the same layer as metadata extraction.
2023-02-13 19:23:34 +07:00
Fabien 'egg' O'Carroll
4e8af72305
Added support for deleting mentions (#16238)
refs https://github.com/TryGhost/Team/issues/2534

As we're using soft deletes for mentions we need to store the `deleted` column
as well as enforce a `'deleted:false'` filter on the bookshelf model. 

We've also implemented the handling for deleting mentions. Where we remove a
mention anytime we receive and update from or to a page which no longer exists.

Co-authored-by: Steve Larson <9larsons@gmail.com>
2023-02-09 17:29:13 +07:00
Steve Larson
6c97edec25
moved sending mentions to job (#16234)
refs TryGhost/Team#2523
-implemented jobsService within mention sending service
-updated tests so we don't need to sleep
2023-02-08 16:29:12 -06:00
Ronald Langeveld
e02c67dd3a
Mentions ordering (#16215)
closes https://github.com/TryGhost/Team/issues/2498

- can now order mentions via the API via params eg `api/admin/mentions/?order=created_at%20desc`.
2023-02-02 13:25:09 +08:00
Steve Larson
855bcb8613 added tests to cover internal data checks
no ref
-tests didn't cover imported data escape
-tests didn't cover internal data escape
2023-02-01 17:40:29 -06:00
Steve Larson
3186323663 updated listeners in test to be fully inclusive
no ref
-test wasn't previously updated to include all event listeners
2023-02-01 17:20:24 -06:00
Steve Larson
ae92d1425d
updated events that send mentions (#16219)
refs TryGhost/Team#2477
-removed post.edited as it was too inclusive
-changed to post.published, post.published.edited, post.unpublished
-blocked import and internal data from triggering mentions
2023-02-01 16:49:58 -06:00
Fabien "egg" O'Carroll
72d7580461 Added source_is_ghost flag to outgoing Webmentions
This is a pretty simple way for us to track which webmentions are sent
by Ghost. Although it's easily spoofed, so are other approaches like
using a header (e.g. User-Agent). If we find that this data is being
spoofed we can look at different approach.

Becuase our receiving implementation stores the payload of the
Webmention, we'll be able to know inside Ghost which Mentions
originated from another Ghost installation, which is useful for stats
and gives us the possibility to display that information in the feed.

Longer term we might want to consider storing this data in a separate
column for Mentions, rather than the `payload` column - but that is
outside the scope of this change.
2023-02-01 13:44:55 +07:00
Steve Larson
a3064d95cb
completely blocked external requests in Webmentions tests (#16186)
no issue
-had timeout issues in test suite
-tests were still doing dns lookup via external request
2023-01-25 10:43:57 -06:00
Fabien 'egg' O'Carroll
33ebe971f8
Added BookshelfMentionRepository implementation (#16156)
fixes https://github.com/TryGhost/Team/issues/2418

This stores the received webmentions in the database.

Co-authored-by: Simon Backx <simon@ghost.org>
2023-01-20 14:32:50 +01:00
Steve Larson
8895d22602
Added mention discovery service (#16154)
fixes https://github.com/TryGhost/Team/issues/2407

The MentionDiscoveryService fetches mentioned sites to return the webmention endpoint.
2023-01-20 11:45:48 +01:00
Simon Backx
a596acf7d2
Added MentionSendingService (#16151)
fixes https://github.com/TryGhost/Team/issues/2409

The MentionSendingService listens for post changes and sends webmentions
for outbound links in the post.
2023-01-19 17:35:10 +01:00
Fabien "egg" O'Carroll
3a0e0831ec Updated Mention entity validation of properties
Based on a discussion in slack we want to make all metadata properties optional,
with the exception of the title, which will default to the host of the source
URL if it's missing.

This is so that we can accept as many webmentions as possible and convert them
into Mentions. If we were to have strictly validation, we'd end up having to
drop webmentions that didn't match our criteria, and lose important data.

Giving the title a default allows us to provide a consistent UI experience too.
2023-01-19 19:24:07 +07:00
Fabien "egg" O'Carroll
743da542d0 Wired up the Webmention receive endpoint to the Mentions service
refs https://github.com/TryGhost/Team/issues/2419

This is the initial stab at having everything wired up, we're not
using a queue but we are handling the processing of the Webmention
asyncrounsly so that the HTTP response can be end immediately.

We've also laid the groundwork for extending and implementing the
correct processing of Webmentions, for example checking if the target
URL exists in the system, pulling out the metadata from the Webmention
source and fetching any internal resources.
2023-01-19 18:41:49 +07:00
Fabien "egg" O'Carroll
560d168169 Added site title and author to Mention entity
refs https://github.com/TryGhost/Team/issues/2435

We've made these fields optional, and we may need to extend this to other fields
too as we discover more about the data we're able to get access to.
2023-01-19 18:41:49 +07:00
Fabien "egg" O'Carroll
1babf6126a Added initial basic Mentions implementation
refs https://github.com/TryGhost/Team/issues/2416

This extends the mock API to use a more formal pattern of moving our
entity code into a separate package, and use the service/repository
patterns we've been work toward.

The repository is currently in memory, this allows us to start using
the API without having to make commitments to the database structure.

We've also injected a single fake webmention for testing. I'd expect
the Mention object to change a lot from this initial definition as we
gain more information about the type of data we expect to see.
2023-01-17 17:01:20 +07:00
Ronald Langeveld
e55405691a
Added webmentions package (#16133)
refs https://github.com/TryGhost/Team/issues/2408

- Added webmentions package 
- Setup basic folder structure, controllers, repositories & services to
get started.
- note package haven't been published yet
2023-01-17 13:18:16 +08:00