Merge commit '2f932cb2bb' into kb_migration

This commit is contained in:
KMY 2023-08-03 15:48:07 +09:00
commit 82d61dad96
65 changed files with 909 additions and 162 deletions

BIN
spec/fixtures/files/600x400.avif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
spec/fixtures/files/600x400.heic vendored Normal file

Binary file not shown.

BIN
spec/fixtures/files/600x400.jpeg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
spec/fixtures/files/600x400.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
spec/fixtures/files/600x400.webp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View file

@ -95,6 +95,33 @@ describe Request do
end
end
context 'with bare domain URL' do
let(:url) { 'http://example.com' }
before do
stub_request(:get, 'http://example.com')
end
it 'normalizes path' do
subject.perform do |response|
expect(response.request.uri.path).to eq '/'
end
end
it 'normalizes path used for request signing' do
subject.perform
headers = subject.instance_variable_get(:@headers)
expect(headers[Request::REQUEST_TARGET]).to eq 'get /'
end
it 'normalizes path used in request line' do
subject.perform do |response|
expect(response.request.headline).to eq 'GET / HTTP/1.1'
end
end
end
context 'with unnormalized URL' do
let(:url) { 'HTTP://EXAMPLE.com:80/foo%41%3A?bar=%41%3A#baz' }
@ -114,18 +141,31 @@ describe Request do
end
end
it 'does modify path' do
it 'does not modify path' do
subject.perform do |response|
expect(response.request.uri.path).to eq '/foo%41%3A'
end
end
it 'does modify query string' do
it 'does not modify query string' do
subject.perform do |response|
expect(response.request.uri.query).to eq 'bar=%41%3A'
end
end
it 'does not modify path used for request signing' do
subject.perform
headers = subject.instance_variable_get(:@headers)
expect(headers[Request::REQUEST_TARGET]).to eq 'get /foo%41%3A'
end
it 'does not modify path used in request line' do
subject.perform do |response|
expect(response.request.headline).to eq 'GET /foo%41%3A?bar=%41%3A HTTP/1.1'
end
end
it 'strips fragment' do
subject.perform do |response|
expect(response.request.uri.fragment).to be_nil
@ -134,22 +174,35 @@ describe Request do
end
context 'with non-ASCII URL' do
let(:url) { 'http://éxample.com/föo?bär=1' }
let(:url) { 'http://éxample.com:81/föo?bär=1' }
before do
stub_request(:get, 'http://xn--xample-9ua.com/f%C3%B6o?b%C3%A4r=1')
stub_request(:get, 'http://xn--xample-9ua.com:81/f%C3%B6o?b%C3%A4r=1')
end
it 'IDN-encodes host' do
subject.perform do |response|
expect(response.request.uri.authority).to eq 'xn--xample-9ua.com'
expect(response.request.uri.authority).to eq 'xn--xample-9ua.com:81'
end
end
it 'percent-escapes path and query string' do
it 'IDN-encodes host in Host header' do
subject.perform do |response|
expect(response.request.headers['Host']).to eq 'xn--xample-9ua.com'
end
end
it 'percent-escapes path used for request signing' do
subject.perform
expect(a_request(:get, 'http://xn--xample-9ua.com/f%C3%B6o?b%C3%A4r=1')).to have_been_made
headers = subject.instance_variable_get(:@headers)
expect(headers[Request::REQUEST_TARGET]).to eq 'get /f%C3%B6o'
end
it 'normalizes path used in request line' do
subject.perform do |response|
expect(response.request.headline).to eq 'GET /f%C3%B6o?b%C3%A4r=1 HTTP/1.1'
end
end
end

View file

@ -3,21 +3,42 @@
require 'rails_helper'
RSpec.describe NotificationMailer do
let(:receiver) { Fabricate(:user) }
let(:receiver) { Fabricate(:user, account_attributes: { username: 'alice' }) }
let(:sender) { Fabricate(:account, username: 'bob') }
let(:foreign_status) { Fabricate(:status, account: sender, text: 'The body of the foreign status') }
let(:own_status) { Fabricate(:status, account: receiver.account, text: 'The body of the own status') }
shared_examples 'headers' do |type, thread|
it 'renders the to and from headers' do
expect(mail[:to].value).to eq "#{receiver.account.username} <#{receiver.email}>"
expect(mail.from).to eq ['notifications@localhost']
end
it 'renders the list headers' do
expect(mail['List-ID'].value).to eq "<#{type}.alice.cb6e6126.ngrok.io>"
expect(mail['List-Unsubscribe'].value).to match(%r{<https://cb6e6126.ngrok.io/unsubscribe\?token=.+>})
expect(mail['List-Unsubscribe'].value).to match("&type=#{type}")
expect(mail['List-Unsubscribe-Post'].value).to eq 'List-Unsubscribe=One-Click'
end
if thread
it 'renders the thread headers' do
expect(mail['In-Reply-To'].value).to match(/<conversation-\d+.\d\d\d\d-\d\d-\d\d@cb6e6126.ngrok.io>/)
expect(mail['References'].value).to match(/<conversation-\d+.\d\d\d\d-\d\d-\d\d@cb6e6126.ngrok.io>/)
end
end
end
describe 'mention' do
let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) }
let(:notification) { Notification.create!(account: receiver.account, activity: mention) }
let(:mail) { prepared_mailer_for(receiver.account).mention }
include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob'
include_examples 'headers', 'mention', true
it 'renders the headers' do
it 'renders the subject' do
expect(mail.subject).to eq('You were mentioned by bob')
expect(mail[:to].value).to eq("#{receiver.account.username} <#{receiver.email}>")
end
it 'renders the body' do
@ -32,10 +53,10 @@ RSpec.describe NotificationMailer do
let(:mail) { prepared_mailer_for(receiver.account).follow }
include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob'
include_examples 'headers', 'follow', false
it 'renders the headers' do
it 'renders the subject' do
expect(mail.subject).to eq('bob is now following you')
expect(mail[:to].value).to eq("#{receiver.account.username} <#{receiver.email}>")
end
it 'renders the body' do
@ -49,10 +70,10 @@ RSpec.describe NotificationMailer do
let(:mail) { prepared_mailer_for(own_status.account).favourite }
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
include_examples 'headers', 'favourite', true
it 'renders the headers' do
it 'renders the subject' do
expect(mail.subject).to eq('bob favorited your post')
expect(mail[:to].value).to eq("#{receiver.account.username} <#{receiver.email}>")
end
it 'renders the body' do
@ -67,10 +88,10 @@ RSpec.describe NotificationMailer do
let(:mail) { prepared_mailer_for(own_status.account).reblog }
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
include_examples 'headers', 'reblog', true
it 'renders the headers' do
it 'renders the subject' do
expect(mail.subject).to eq('bob boosted your post')
expect(mail[:to].value).to eq("#{receiver.account.username} <#{receiver.email}>")
end
it 'renders the body' do
@ -85,10 +106,10 @@ RSpec.describe NotificationMailer do
let(:mail) { prepared_mailer_for(receiver.account).follow_request }
include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob'
include_examples 'headers', 'follow_request', false
it 'renders the headers' do
it 'renders the subject' do
expect(mail.subject).to eq('Pending follower: bob')
expect(mail[:to].value).to eq("#{receiver.account.username} <#{receiver.email}>")
end
it 'renders the body' do

View file

@ -84,7 +84,87 @@ RSpec.describe MediaAttachment, paperclip_processing: true do
end
end
describe 'animated gif conversion' do
shared_examples 'static 600x400 image' do |content_type, extension|
after do
media.destroy
end
it 'saves media attachment' do
expect(media.persisted?).to be true
expect(media.file).to_not be_nil
end
it 'completes processing' do
expect(media.processing_complete?).to be true
end
it 'sets type' do
expect(media.type).to eq 'image'
end
it 'sets content type' do
expect(media.file_content_type).to eq content_type
end
it 'sets file extension' do
expect(media.file_file_name).to end_with extension
end
it 'strips original file name' do
expect(media.file_file_name).to_not start_with '600x400'
end
it 'sets meta for original' do
expect(media.file.meta['original']['width']).to eq 600
expect(media.file.meta['original']['height']).to eq 400
expect(media.file.meta['original']['aspect']).to eq 1.5
end
it 'sets meta for thumbnail' do
expect(media.file.meta['small']['width']).to eq 588
expect(media.file.meta['small']['height']).to eq 392
expect(media.file.meta['small']['aspect']).to eq 1.5
end
end
describe 'jpeg' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('600x400.jpeg')) }
it_behaves_like 'static 600x400 image', 'image/jpeg', '.jpeg'
end
describe 'png' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('600x400.png')) }
it_behaves_like 'static 600x400 image', 'image/png', '.png'
end
describe 'webp' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('600x400.webp')) }
it_behaves_like 'static 600x400 image', 'image/webp', '.webp'
end
describe 'avif' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('600x400.avif')) }
it_behaves_like 'static 600x400 image', 'image/jpeg', '.jpeg'
end
describe 'heic' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('600x400.heic')) }
it_behaves_like 'static 600x400 image', 'image/jpeg', '.jpeg'
end
describe 'base64-encoded image' do
let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('600x400.jpeg').read)}" }
let(:media) { described_class.create(account: Fabricate(:account), file: base64_attachment) }
it_behaves_like 'static 600x400 image', 'image/jpeg', '.jpeg'
end
describe 'animated gif' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) }
it 'sets type to gifv' do
@ -101,7 +181,7 @@ RSpec.describe MediaAttachment, paperclip_processing: true do
end
end
describe 'non-animated gif non-conversion' do
describe 'static gif' do
fixtures = [
{ filename: 'attachment.gif', width: 600, height: 400, aspect: 1.5 },
{ filename: 'mini-static.gif', width: 32, height: 32, aspect: 1.0 },
@ -172,37 +252,6 @@ RSpec.describe MediaAttachment, paperclip_processing: true do
end
end
describe 'jpeg' do
let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }
it 'sets meta for different style' do
expect(media.file.meta['original']['width']).to eq 600
expect(media.file.meta['original']['height']).to eq 400
expect(media.file.meta['original']['aspect']).to eq 1.5
expect(media.file.meta['small']['width']).to eq 588
expect(media.file.meta['small']['height']).to eq 392
expect(media.file.meta['small']['aspect']).to eq 1.5
end
it 'gives the file a random name' do
expect(media.file_file_name).to_not eq 'attachment.jpg'
end
end
describe 'base64-encoded jpeg' do
let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('attachment.jpg').read)}" }
let(:media) { described_class.create(account: Fabricate(:account), file: base64_attachment) }
it 'saves media attachment' do
expect(media.persisted?).to be true
expect(media.file).to_not be_nil
end
it 'gives the file a file name' do
expect(media.file_file_name).to_not be_blank
end
end
it 'is invalid without file' do
media = described_class.new(account: Fabricate(:account))
expect(media.valid?).to be false

View file

@ -508,12 +508,12 @@ describe 'Caching behavior' do
context 'when enabling LIMITED_FEDERATION_MODE mode' do
around do |example|
ClimateControl.modify LIMITED_FEDERATION_MODE: 'true' do
old_whitelist_mode = Rails.configuration.x.whitelist_mode
Rails.configuration.x.whitelist_mode = true
old_limited_federation_mode = Rails.configuration.x.limited_federation_mode
Rails.configuration.x.limited_federation_mode = true
example.run
Rails.configuration.x.whitelist_mode = old_whitelist_mode
Rails.configuration.x.limited_federation_mode = old_limited_federation_mode
end
end

View file

@ -0,0 +1,103 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'MailSubscriptionsController' do
let(:user) { Fabricate(:user) }
let(:token) { user.to_sgid(for: 'unsubscribe').to_s }
let(:type) { 'follow' }
shared_examples 'not found with invalid token' do
context 'with invalid token' do
let(:token) { 'invalid-token' }
it 'returns http not found' do
expect(response).to have_http_status(404)
end
end
end
shared_examples 'not found with invalid type' do
context 'with invalid type' do
let(:type) { 'invalid_type' }
it 'returns http not found' do
expect(response).to have_http_status(404)
end
end
end
describe 'on the unsubscribe confirmation page' do
before do
get unsubscribe_url(token: token, type: type)
end
it_behaves_like 'not found with invalid token'
it_behaves_like 'not found with invalid type'
it 'shows unsubscribe form' do
expect(response).to have_http_status(200)
expect(response.body).to include(
I18n.t('mail_subscriptions.unsubscribe.action')
)
expect(response.body).to include(user.email)
end
end
describe 'submitting the unsubscribe confirmation page' do
before do
user.settings.update('notification_emails.follow': true)
user.save!
post unsubscribe_url, params: { token: token, type: type }
end
it_behaves_like 'not found with invalid token'
it_behaves_like 'not found with invalid type'
it 'shows confirmation page' do
expect(response).to have_http_status(200)
expect(response.body).to include(
I18n.t('mail_subscriptions.unsubscribe.complete')
)
expect(response.body).to include(user.email)
end
it 'updates notification settings' do
user.reload
expect(user.settings['notification_emails.follow']).to be false
end
end
describe 'unsubscribing with List-Unsubscribe-Post' do
around do |example|
old = ActionController::Base.allow_forgery_protection
ActionController::Base.allow_forgery_protection = true
example.run
ActionController::Base.allow_forgery_protection = old
end
before do
user.settings.update('notification_emails.follow': true)
user.save!
post unsubscribe_url(token: token, type: type), params: { 'List-Unsubscribe' => 'One-Click' }
end
it_behaves_like 'not found with invalid token'
it_behaves_like 'not found with invalid type'
it 'return http success' do
expect(response).to have_http_status(200)
end
it 'updates notification settings' do
user.reload
expect(user.settings['notification_emails.follow']).to be false
end
end
end

View file

@ -14,7 +14,7 @@ RSpec.describe UnallowDomainService, type: :service do
context 'with limited federation mode' do
before do
allow(Rails.configuration.x).to receive(:whitelist_mode).and_return(true)
allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(true)
end
describe '#call' do
@ -40,7 +40,7 @@ RSpec.describe UnallowDomainService, type: :service do
context 'without limited federation mode' do
before do
allow(Rails.configuration.x).to receive(:whitelist_mode).and_return(false)
allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(false)
end
describe '#call' do