Merge pull request #969 from kmycode/upstream-20240123

Upstream 20240123
This commit is contained in:
KMY(雪あすか) 2025-01-23 19:16:23 +09:00 committed by GitHub
commit 22bf14e9f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
320 changed files with 2589 additions and 2817 deletions

View file

@ -9,45 +9,6 @@ RSpec.describe StatusesController do
let(:account) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: account) }
context 'when account is permanently suspended' do
before do
account.suspend!
account.deletion_request.destroy
get :show, params: { account_username: account.username, id: status.id }
end
it 'returns http gone' do
expect(response).to have_http_status(410)
end
end
context 'when account is temporarily suspended' do
before do
account.suspend!
get :show, params: { account_username: account.username, id: status.id }
end
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
context 'when status is a reblog' do
let(:original_account) { Fabricate(:account, domain: 'example.com') }
let(:original_status) { Fabricate(:status, account: original_account, url: 'https://example.com/123') }
let(:status) { Fabricate(:status, account: account, reblog: original_status) }
before do
get :show, params: { account_username: status.account.username, id: status.id }
end
it 'redirects to the original status' do
expect(response).to redirect_to(original_status.url)
end
end
context 'when status is public' do
before do
get :show, params: { account_username: status.account.username, id: status.id, format: format }
@ -142,17 +103,6 @@ RSpec.describe StatusesController do
sign_in(user)
end
context 'when account blocks user' do
before do
account.block!(user.account)
get :show, params: { account_username: status.account.username, id: status.id }
end
it 'returns http not found' do
expect(response).to have_http_status(404)
end
end
context 'when status is public' do
before do
get :show, params: { account_username: status.account.username, id: status.id, format: format }

View file

@ -249,6 +249,44 @@ RSpec.describe LinkDetailsExtractor do
expect(subject.author_name).to eq 'Author 1, Author 2'
end
end
context 'with embedded arrays' do
let(:ld_json) do
{
'@context' => 'https://schema.org',
'@type' => 'NewsArticle',
'headline' => 'A lot of authors',
'description' => 'But we decided to cram them into one',
'author' => [[{
'@type' => 'Person',
'name' => ['Author 1'],
}]],
'publisher' => [[{
'@type' => 'NewsMediaOrganization',
'name' => 'Pet News',
'url' => 'https://example.com',
}]],
}.to_json
end
let(:html) { <<~HTML }
<!doctype html>
<html>
<body>
<script type="application/ld+json">
#{ld_json}
</script>
</body>
</html>
HTML
it 'gives correct author_name' do
expect(subject.author_name).to eq 'Author 1'
end
it 'gives provider_name' do
expect(subject.provider_name).to eq 'Pet News'
end
end
end
context 'when Open Graph protocol data is present' do

View file

@ -712,38 +712,16 @@ RSpec.describe Account do
end
end
describe '#attribution_domains_as_text=' do
subject { Fabricate(:account) }
it 'sets attribution_domains accordingly' do
subject.attribution_domains_as_text = "hoge.com\nexample.com"
expect(subject.attribution_domains).to contain_exactly('hoge.com', 'example.com')
end
it 'strips leading "*."' do
subject.attribution_domains_as_text = "hoge.com\n*.example.com"
expect(subject.attribution_domains).to contain_exactly('hoge.com', 'example.com')
end
it 'strips the protocol if present' do
subject.attribution_domains_as_text = "http://hoge.com\nhttps://example.com"
expect(subject.attribution_domains).to contain_exactly('hoge.com', 'example.com')
end
it 'strips a combination of leading "*." and protocol' do
subject.attribution_domains_as_text = "http://*.hoge.com\nhttps://*.example.com"
expect(subject.attribution_domains).to contain_exactly('hoge.com', 'example.com')
end
end
describe 'Normalizations' do
describe 'username' do
it { is_expected.to normalize(:username).from(" \u3000bob \t \u00a0 \n ").to('bob') }
end
describe 'attribution_domains' do
it { is_expected.to normalize(:attribution_domains).from(['example.com', ' example.com ', ' example.net ']).to(['example.com', 'example.net']) }
it { is_expected.to normalize(:attribution_domains).from(['https://example.com', 'http://example.net', '*.example.org']).to(['example.com', 'example.net', 'example.org']) }
it { is_expected.to normalize(:attribution_domains).from(['', ' ', nil]).to([]) }
end
end
describe 'Validations' do
@ -794,6 +772,9 @@ RSpec.describe Account do
it { is_expected.to validate_absence_of(:inbox_url).on(:create) }
it { is_expected.to validate_absence_of(:shared_inbox_url).on(:create) }
it { is_expected.to validate_absence_of(:uri).on(:create) }
it { is_expected.to allow_values([], ['example.com'], (1..100).to_a).for(:attribution_domains) }
it { is_expected.to_not allow_values(['example com'], ['@'], (1..101).to_a).for(:attribution_domains) }
end
context 'when account is remote' do

View file

@ -64,6 +64,7 @@ RSpec.describe 'credentials API' do
indexable: true,
locked: false,
note: 'Hello!',
attribution_domains: ['example.com'],
source: {
privacy: 'unlisted',
sensitive: true,
@ -121,7 +122,8 @@ RSpec.describe 'credentials API' do
display_name: eq("Alice Isn't Dead"),
note: 'Hello!',
avatar: exist,
header: exist
header: exist,
attribution_domains: ['example.com']
)
end

View file

@ -107,6 +107,13 @@ RSpec.describe 'API V1 Push Subscriptions' do
it_behaves_like 'validation error'
end
it 'gracefully handles invalid nested params' do
post api_v1_push_subscription_path, params: { subscription: 'invalid' }, headers: headers
expect(response)
.to have_http_status(400)
end
end
describe 'PUT /api/v1/push/subscription' do
@ -133,6 +140,13 @@ RSpec.describe 'API V1 Push Subscriptions' do
policy: alerts_payload[:data][:policy]
)
end
it 'gracefully handles invalid nested params' do
put api_v1_push_subscription_path(endpoint_push_subscription), params: { data: 'invalid' }, headers: headers
expect(response)
.to have_http_status(400)
end
end
describe 'GET /api/v1/push/subscription' do

View file

@ -52,4 +52,28 @@ RSpec.describe 'API Web Push Subscriptions' do
end
end
end
describe 'POST /api/web/push_subscriptions' do
before { sign_in Fabricate :user }
it 'gracefully handles invalid nested params' do
post api_web_push_subscriptions_path, params: { subscription: 'invalid' }
expect(response)
.to have_http_status(400)
end
end
describe 'PUT /api/web/push_subscriptions' do
before { sign_in Fabricate :user }
let(:subscription) { Fabricate :web_push_subscription }
it 'gracefully handles invalid nested params' do
put api_web_push_subscription_path(subscription), params: { data: 'invalid' }
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -24,4 +24,15 @@ RSpec.describe 'Auth Setup' do
end
end
end
describe 'PUT /auth/setup' do
before { sign_in Fabricate(:user, confirmed_at: nil) }
it 'gracefully handles invalid nested params' do
put '/auth/setup?user=invalid'
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Disputes Appeals' do
describe 'POST /disputes/appeals' do
before { sign_in strike.target_account.user }
let(:strike) { Fabricate :account_warning }
it 'gracefully handles invalid nested params' do
post disputes_strike_appeal_path(strike, appeal: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -13,4 +13,28 @@ RSpec.describe 'Filters' do
end
end
end
describe 'POST /filters' do
before { sign_in Fabricate :user }
it 'gracefully handles invalid nested params' do
post filters_path(custom_filter: 'invalid')
expect(response)
.to have_http_status(400)
end
end
describe 'PUT /filters/:id' do
before { sign_in(filter.account.user) }
let(:filter) { Fabricate :custom_filter }
it 'gracefully handles invalid nested params' do
put filter_path(filter, custom_filter: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -28,4 +28,15 @@ RSpec.describe 'Invites' do
end
end
end
describe 'POST /invites' do
before { UserRole.everyone.update(permissions: UserRole.everyone.permissions | UserRole::FLAGS[:invite_users]) }
it 'gracefully handles invalid nested params' do
post invites_path(invite: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Aliases' do
describe 'POST /settings/aliases' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
post settings_aliases_path(account_alias: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Deletes' do
describe 'DELETE /settings/delete' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
delete settings_delete_path(form_delete_confirmation: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Aliases' do
describe 'POST /settings/featured_tags' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
post settings_featured_tags_path(featured_tag: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Imports' do
describe 'POST /settings/imports' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
post settings_imports_path(form_import: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Migration Redirects' do
describe 'POST /settings/migration/redirect' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
post settings_migration_redirect_path(form_redirect: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -18,4 +18,15 @@ RSpec.describe 'Settings Migrations' do
it { is_expected.to redirect_to new_user_session_path }
end
end
context 'when user is signed in' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
post settings_migration_path(account_migration: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Privacy' do
describe 'PUT /settings/privacy' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
put settings_privacy_path(account: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Profiles' do
describe 'PUT /settings/profile' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
put settings_profile_path(account: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Statuses Cleanup' do
describe 'PUT /statuses_cleanup' do
before { sign_in Fabricate(:user) }
it 'gracefully handles invalid nested params' do
put statuses_cleanup_path(account_statuses_cleanup_policy: 'invalid')
expect(response)
.to have_http_status(400)
end
end
end

View file

@ -0,0 +1,67 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Statuses' do
describe 'GET /@:account_username/:id' do
let(:account) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: account) }
context 'when signed out' do
context 'when account is permanently suspended' do
before do
account.suspend!
account.deletion_request.destroy
end
it 'returns http gone' do
get "/@#{account.username}/#{status.id}"
expect(response)
.to have_http_status(410)
end
end
context 'when account is temporarily suspended' do
before { account.suspend! }
it 'returns http forbidden' do
get "/@#{account.username}/#{status.id}"
expect(response)
.to have_http_status(403)
end
end
context 'when status is a reblog' do
let(:original_account) { Fabricate(:account, domain: 'example.com') }
let(:original_status) { Fabricate(:status, account: original_account, url: 'https://example.com/123') }
let(:status) { Fabricate(:status, account: account, reblog: original_status) }
it 'redirects to the original status' do
get "/@#{status.account.username}/#{status.id}"
expect(response)
.to redirect_to(original_status.url)
end
end
end
context 'when signed in' do
let(:user) { Fabricate(:user) }
before { sign_in(user) }
context 'when account blocks user' do
before { account.block!(user.account) }
it 'returns http not found' do
get "/@#{status.account.username}/#{status.id}"
expect(response)
.to have_http_status(404)
end
end
end
end
end

View file

@ -319,6 +319,16 @@ RSpec.describe NotifyService do
end
end
context 'when sender is a moderator' do
let(:sender_role) { Fabricate(:user_role, highlighted: true, permissions: UserRole::FLAGS[:manage_users]) }
let(:sender) { Fabricate(:user, role: sender_role).account }
let(:activity) { Fabricate(:mention, status: Fabricate(:status, account: sender)) }
it 'returns false' do
expect(subject.filter?).to be false
end
end
context 'when sender is followed by recipient' do
before do
notification.account.follow!(notification.from_account)

View file

@ -26,8 +26,8 @@ RSpec.describe 'OCR', :attachment_processing, :inline_jobs, :js, :streaming do
end
end
click_on('Detect text from picture')
click_on('Add text from image')
expect(page).to have_css('#upload-modal__description', text: /Hello Mastodon\s*/, wait: 10)
expect(page).to have_css('#description', text: /Hello Mastodon\s*/, wait: 10)
end
end

View file

@ -5,8 +5,6 @@ require 'rails_helper'
RSpec.describe 'Profile' do
include ProfileStories
subject { page }
let(:local_domain) { Rails.configuration.x.local_domain }
before do
@ -17,7 +15,8 @@ RSpec.describe 'Profile' do
it 'I can view public account page for Alice' do
visit account_path('alice')
expect(subject).to have_title("alice (@alice@#{local_domain})")
expect(page)
.to have_title("alice (@alice@#{local_domain})")
end
it 'I can change my account' do
@ -26,8 +25,31 @@ RSpec.describe 'Profile' do
fill_in 'Display name', with: 'Bob'
fill_in 'Bio', with: 'Bob is silent'
first('button[type=submit]').click
fill_in 'account_fields_attributes_0_name', with: 'Personal Website'
fill_in 'account_fields_attributes_0_value', with: 'https://host.example/personal'
expect(subject).to have_content 'Changes successfully saved!'
fill_in 'account_fields_attributes_1_name', with: 'Professional Biography'
fill_in 'account_fields_attributes_1_value', with: 'https://host.example/pro'
expect { submit_form }
.to change { bob.account.reload.display_name }.to('Bob')
.and(change_account_fields)
expect(page)
.to have_content 'Changes successfully saved!'
end
def submit_form
first('button[type=submit]').click
end
def change_account_fields
change { bob.account.reload.fields }
.from([])
.to(
contain_exactly(
be_a(Account::Field),
be_a(Account::Field)
)
)
end
end

View file

@ -15,12 +15,27 @@ RSpec.describe 'Settings verification page' do
.to have_content(verification_summary)
.and have_private_cache_control
fill_in attribution_field, with: 'host.example'
fill_in attribution_field, with: " example.com\n\n https://example.net"
expect { click_on submit_button }
.to(change { user.account.reload.attribution_domains_as_text })
.to(change { user.account.reload.attribution_domains }.to(['example.com', 'example.net']))
expect(page)
.to have_content(success_message)
expect(find_field(attribution_field).value)
.to have_content("example.com\nexample.net")
end
it 'rejects invalid attribution domains' do
visit settings_verification_path
fill_in attribution_field, with: "example.com \n invalid_com"
expect { click_on submit_button }
.to_not(change { user.account.reload.attribution_domains })
expect(page)
.to have_content(I18n.t('activerecord.errors.messages.invalid_domain_on_line', value: 'invalid_com'))
expect(find_field(attribution_field).value)
.to have_content("example.com\ninvalid_com")
end
end
@ -29,6 +44,6 @@ RSpec.describe 'Settings verification page' do
end
def attribution_field
I18n.t('simple_form.labels.account.attribution_domains_as_text')
I18n.t('simple_form.labels.account.attribution_domains')
end
end

View file

@ -1,46 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe LinesValidator do
let(:record_class) do
Class.new do
include ActiveModel::Validations
attr_accessor :text
validates :text, lines: { maximum: 5 }
end
end
let(:record) { record_class.new }
describe '#validate_each' do
context 'with a nil value' do
it 'does not add errors' do
record.text = nil
expect(record).to be_valid
expect(record.errors).to be_empty
end
end
context 'with lines below the limit' do
it 'does not add errors' do
record.text = "hoge\n" * 5
expect(record).to be_valid
expect(record.errors).to be_empty
end
end
context 'with more lines than limit' do
it 'adds an error' do
record.text = "hoge\n" * 6
expect(record).to_not be_valid
expect(record.errors.where(:text)).to_not be_empty
end
end
end
end