Merge remote-tracking branch 'parent/main' into upstream-20240126

This commit is contained in:
KMY 2024-01-26 11:14:21 +09:00
commit 3dd9591a4b
163 changed files with 3000 additions and 2777 deletions

View file

@ -0,0 +1,32 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'redirection confirmations' do
let(:account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/foo', url: 'https://example.com/@foo') }
let(:status) { Fabricate(:status, account: account, uri: 'https://example.com/users/foo/statuses/1', url: 'https://example.com/@foo/1') }
context 'when a logged out user visits a local page for a remote account' do
it 'shows a confirmation page' do
visit "/@#{account.pretty_acct}"
# It explains about the redirect
expect(page).to have_content(I18n.t('redirects.title', instance: 'cb6e6126.ngrok.io'))
# It features an appropriate link
expect(page).to have_link(account.url, href: account.url)
end
end
context 'when a logged out user visits a local page for a remote status' do
it 'shows a confirmation page' do
visit "/@#{account.pretty_acct}/#{status.id}"
# It explains about the redirect
expect(page).to have_content(I18n.t('redirects.title', instance: 'cb6e6126.ngrok.io'))
# It features an appropriate link
expect(page).to have_link(status.url, href: status.url)
end
end
end

View file

@ -1933,6 +1933,49 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'when object URI uses bearcaps' do
subject { described_class.new(json, sender) }
let(:token) { 'foo' }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
type: 'Create',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: Addressable::URI.new(scheme: 'bear', query_values: { t: token, u: object_json[:id] }).to_s,
}.with_indifferent_access
end
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
to: 'https://www.w3.org/ns/activitystreams#Public',
}
end
before do
stub_request(:get, object_json[:id])
.with(headers: { Authorization: "Bearer #{token}" })
.to_return(body: Oj.dump(object_json), headers: { 'Content-Type': 'application/activity+json' })
subject.perform
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status).to have_attributes(
visibility: 'public',
text: 'Lorem ipsum'
)
end
end
context 'with an encrypted message' do
subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
@ -2182,54 +2225,5 @@ RSpec.describe ActivityPub::Activity::Create do
expect(sender.statuses.count).to eq 0
end
end
context 'when bearcaps' do
subject { described_class.new(json, sender) }
before do
stub_request(:get, 'https://example.com/statuses/1234567890')
.with(headers: { 'Authorization' => 'Bearer test_ohagi_token' })
.to_return(status: 200, body: Oj.dump(object_json), headers: {})
subject.perform
end
let!(:recipient) { Fabricate(:account) }
let(:object_json) do
{
id: 'https://example.com/statuses/1234567890',
type: 'Note',
content: 'Lorem ipsum',
to: ActivityPub::TagManager.instance.uri_for(recipient),
attachment: [
{
type: 'Document',
mediaType: 'image/png',
url: 'http://example.com/attachment.png',
},
],
}
end
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Create',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: "bear:?#{{ u: 'https://example.com/statuses/1234567890', t: 'test_ohagi_token' }.to_query}",
}.with_indifferent_access
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'
expect(status.mentions.map(&:account)).to include(recipient)
expect(status.mentions.count).to eq 1
expect(status.visibility).to eq 'limited'
expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
end
end
end
end

View file

@ -296,16 +296,11 @@ RSpec.describe AccountStatusesCleanupPolicy do
let!(:old_status) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:slightly_less_old_status) { Fabricate(:status, created_at: 6.months.ago, account: account) }
it 'returns statuses including max_id' do
expect(subject).to include(old_status.id)
end
it 'returns statuses including older than max_id' do
expect(subject).to include(very_old_status.id)
end
it 'does not return statuses newer than max_id' do
expect(subject).to_not include(slightly_less_old_status.id)
it 'returns statuses included the max_id and older than the max_id but not newer than max_id' do
expect(subject)
.to include(old_status.id)
.and include(very_old_status.id)
.and not_include(slightly_less_old_status.id)
end
end
@ -315,16 +310,11 @@ RSpec.describe AccountStatusesCleanupPolicy do
let!(:old_status) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:slightly_less_old_status) { Fabricate(:status, created_at: 6.months.ago, account: account) }
it 'returns statuses including min_id' do
expect(subject).to include(old_status.id)
end
it 'returns statuses including newer than max_id' do
expect(subject).to include(slightly_less_old_status.id)
end
it 'does not return statuses older than min_id' do
expect(subject).to_not include(very_old_status.id)
it 'returns statuses including min_id and newer than min_id, but not older than min_id' do
expect(subject)
.to include(old_status.id)
.and include(slightly_less_old_status.id)
.and not_include(very_old_status.id)
end
end
@ -339,12 +329,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.min_status_age = 2.years.seconds
end
it 'does not return unrelated old status' do
expect(subject.pluck(:id)).to_not include(unrelated_status.id)
end
it 'returns only oldest status for deletion' do
expect(subject.pluck(:id)).to eq [very_old_status.id]
it 'does not return unrelated old status and does return oldest status' do
expect(subject.pluck(:id))
.to not_include(unrelated_status.id)
.and eq [very_old_status.id]
end
end
@ -358,12 +346,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'does not return the old direct message for deletion' do
expect(subject.pluck(:id)).to_not include(direct_message.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status except does not return the old direct message for deletion' do
expect(subject.pluck(:id))
.to not_include(direct_message.id)
.and include(very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -377,12 +363,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = true
end
it 'does not return the old self-bookmarked message for deletion' do
expect(subject.pluck(:id)).to_not include(self_bookmarked.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status but does not return the old self-bookmarked message for deletion' do
expect(subject.pluck(:id))
.to not_include(self_bookmarked.id)
.and include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -396,12 +380,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'does not return the old self-bookmarked message for deletion' do
expect(subject.pluck(:id)).to_not include(self_faved.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status but does not return the old self-faved message for deletion' do
expect(subject.pluck(:id))
.to not_include(self_faved.id)
.and include(direct_message.id, very_old_status.id, pinned_status.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -415,12 +397,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'does not return the old message with media for deletion' do
expect(subject.pluck(:id)).to_not include(status_with_media.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status but does not return the old message with media for deletion' do
expect(subject.pluck(:id))
.to not_include(status_with_media.id)
.and include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -434,12 +414,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'does not return the old poll message for deletion' do
expect(subject.pluck(:id)).to_not include(status_with_poll.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status but does not return the old poll message for deletion' do
expect(subject.pluck(:id))
.to not_include(status_with_poll.id)
.and include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -453,12 +431,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'does not return the old pinned message for deletion' do
expect(subject.pluck(:id)).to_not include(pinned_status.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status but does not return the old pinned message for deletion' do
expect(subject.pluck(:id))
.to not_include(pinned_status.id)
.and include(direct_message.id, very_old_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -472,16 +448,11 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = false
end
it 'does not return the recent toot' do
expect(subject.pluck(:id)).to_not include(recent_status.id)
end
it 'does not return the unrelated toot' do
expect(subject.pluck(:id)).to_not include(unrelated_status.id)
end
it 'returns every other old status for deletion' do
expect(subject.pluck(:id)).to include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns every old status but does not return the recent or unrelated statuses' do
expect(subject.pluck(:id))
.to not_include(recent_status.id)
.and not_include(unrelated_status.id)
.and include(direct_message.id, very_old_status.id, pinned_status.id, self_faved.id, self_bookmarked.id, status_with_poll.id, status_with_media.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -495,12 +466,10 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.keep_self_bookmark = true
end
it 'does not return unrelated old status' do
expect(subject.pluck(:id)).to_not include(unrelated_status.id)
end
it 'returns only normal statuses for deletion' do
expect(subject.pluck(:id)).to contain_exactly(very_old_status.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns normal statuses and does not return unrelated old status' do
expect(subject.pluck(:id))
.to not_include(unrelated_status.id)
.and contain_exactly(very_old_status.id, faved_primary.id, faved_secondary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
@ -509,20 +478,12 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.min_reblogs = 5
end
it 'does not return the recent toot' do
expect(subject.pluck(:id)).to_not include(recent_status.id)
end
it 'does not return the toot reblogged 5 times' do
expect(subject.pluck(:id)).to_not include(reblogged_secondary.id)
end
it 'does not return the unrelated toot' do
expect(subject.pluck(:id)).to_not include(unrelated_status.id)
end
it 'returns old statuses not reblogged as much' do
expect(subject.pluck(:id)).to include(very_old_status.id, faved_primary.id, faved_secondary.id, reblogged_primary.id)
it 'returns old not-reblogged statuses but does not return the recent, 5-times reblogged, or unrelated statuses' do
expect(subject.pluck(:id))
.to not_include(recent_status.id)
.and not_include(reblogged_secondary.id)
.and not_include(unrelated_status.id)
.and include(very_old_status.id, faved_primary.id, faved_secondary.id, reblogged_primary.id)
end
end
@ -531,20 +492,12 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.min_favs = 5
end
it 'does not return the recent toot' do
expect(subject.pluck(:id)).to_not include(recent_status.id)
end
it 'does not return the toot faved 5 times' do
expect(subject.pluck(:id)).to_not include(faved_secondary.id)
end
it 'does not return the unrelated toot' do
expect(subject.pluck(:id)).to_not include(unrelated_status.id)
end
it 'returns old statuses not faved as much' do
expect(subject.pluck(:id)).to include(very_old_status.id, faved_primary.id, reblogged_primary.id, reblogged_secondary.id)
it 'returns old not-faved statuses but does not return the recent, 5-times faved, or unrelated statuses' do
expect(subject.pluck(:id))
.to not_include(recent_status.id)
.and not_include(faved_secondary.id)
.and not_include(unrelated_status.id)
.and include(very_old_status.id, faved_primary.id, reblogged_primary.id, reblogged_secondary.id)
end
end
end

View file

@ -0,0 +1,35 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CustomFilterKeyword do
describe '#to_regex' do
context 'when whole_word is true' do
it 'builds a regex with boundaries and the keyword' do
keyword = described_class.new(whole_word: true, keyword: 'test')
expect(keyword.to_regex).to eq(/(?mix:\b#{Regexp.escape(keyword.keyword)}\b)/)
end
it 'builds a regex with starting boundary and the keyword when end with non-word' do
keyword = described_class.new(whole_word: true, keyword: 'test#')
expect(keyword.to_regex).to eq(/(?mix:\btest\#)/)
end
it 'builds a regex with end boundary and the keyword when start with non-word' do
keyword = described_class.new(whole_word: true, keyword: '#test')
expect(keyword.to_regex).to eq(/(?mix:\#test\b)/)
end
end
context 'when whole_word is false' do
it 'builds a regex with the keyword' do
keyword = described_class.new(whole_word: false, keyword: 'test')
expect(keyword.to_regex).to eq(/test/i)
end
end
end
end

View file

@ -0,0 +1,104 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Instance do
describe 'Scopes' do
before { described_class.refresh }
describe '#searchable' do
let(:expected_domain) { 'host.example' }
let(:blocked_domain) { 'other.example' }
before do
Fabricate :account, domain: expected_domain
Fabricate :account, domain: blocked_domain
Fabricate :domain_block, domain: blocked_domain
end
it 'returns records not domain blocked' do
results = described_class.searchable.pluck(:domain)
expect(results)
.to include(expected_domain)
.and not_include(blocked_domain)
end
end
describe '#matches_domain' do
let(:host_domain) { 'host.example.com' }
let(:host_under_domain) { 'host_under.example.com' }
let(:other_domain) { 'other.example' }
before do
Fabricate :account, domain: host_domain
Fabricate :account, domain: host_under_domain
Fabricate :account, domain: other_domain
end
it 'returns matching records' do
expect(described_class.matches_domain('host.exa').pluck(:domain))
.to include(host_domain)
.and not_include(other_domain)
expect(described_class.matches_domain('ple.com').pluck(:domain))
.to include(host_domain)
.and not_include(other_domain)
expect(described_class.matches_domain('example').pluck(:domain))
.to include(host_domain)
.and include(other_domain)
expect(described_class.matches_domain('host_').pluck(:domain)) # Preserve SQL wildcards
.to include(host_domain)
.and include(host_under_domain)
.and not_include(other_domain)
end
end
describe '#by_domain_and_subdomains' do
let(:exact_match_domain) { 'example.com' }
let(:subdomain_domain) { 'foo.example.com' }
let(:partial_domain) { 'grexample.com' }
before do
Fabricate(:account, domain: exact_match_domain)
Fabricate(:account, domain: subdomain_domain)
Fabricate(:account, domain: partial_domain)
end
it 'returns matching instances' do
results = described_class.by_domain_and_subdomains('example.com').pluck(:domain)
expect(results)
.to include(exact_match_domain)
.and include(subdomain_domain)
.and not_include(partial_domain)
end
end
describe '#with_domain_follows' do
let(:example_domain) { 'example.host' }
let(:other_domain) { 'other.host' }
let(:none_domain) { 'none.host' }
before do
example_account = Fabricate(:account, domain: example_domain)
other_account = Fabricate(:account, domain: other_domain)
Fabricate(:account, domain: none_domain)
Fabricate :follow, account: example_account
Fabricate :follow, target_account: other_account
end
it 'returns instances with domain accounts that have follows' do
results = described_class.with_domain_follows(['example.host', 'other.host', 'none.host']).pluck(:domain)
expect(results)
.to include(example_domain)
.and include(other_domain)
.and not_include(none_domain)
end
end
end
end

View file

@ -265,7 +265,7 @@ RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
anything
)
expect(Status.where(uri: 'https://example.com/users/bob/fake-status').exists?).to be false
expect(Status.exists?(uri: 'https://example.com/users/bob/fake-status')).to be false
end
end
end

View file

@ -24,7 +24,7 @@ describe 'NewStatuses', :sidekiq_inline do
within('.compose-form') do
fill_in "What's on your mind?", with: status_text
click_on 'Publish!'
click_on 'Post'
end
expect(subject).to have_css('.status__content__text', text: status_text)
@ -37,7 +37,7 @@ describe 'NewStatuses', :sidekiq_inline do
within('.compose-form') do
fill_in "What's on your mind?", with: status_text
click_on 'Publish!'
click_on 'Post'
end
expect(subject).to have_css('.status__content__text', text: status_text)

View file

@ -19,13 +19,13 @@ describe 'ShareEntrypoint' do
it 'can be used to post a new status' do
expect(subject).to have_css('div#mastodon-compose')
expect(subject).to have_css('.compose-form__publish-button-wrapper > button')
expect(subject).to have_css('.compose-form__submit')
status_text = 'This is a new status!'
within('.compose-form') do
fill_in "What's on your mind?", with: status_text
click_on 'Publish!'
click_on 'Post'
end
expect(subject).to have_css('.notification-bar-message', text: 'Post published.')