Merge tag 'v3.4.0' into hometown-dev
This commit is contained in:
@ -370,7 +370,7 @@ RSpec.describe AccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it_behaves_like 'cachable response'
|
||||
@ -402,7 +402,7 @@ RSpec.describe AccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns public Cache-Control header' do
|
||||
@ -428,7 +428,7 @@ RSpec.describe AccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it_behaves_like 'cachable response'
|
||||
@ -446,7 +446,7 @@ RSpec.describe AccountsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns private Cache-Control header' do
|
||||
|
||||
@ -43,7 +43,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it_behaves_like 'cachable response'
|
||||
@ -88,7 +88,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it_behaves_like 'cachable response'
|
||||
@ -116,7 +116,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns private Cache-Control header' do
|
||||
@ -141,7 +141,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns private Cache-Control header' do
|
||||
|
||||
@ -40,7 +40,7 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController, type: :controll
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns orderedItems with followers from example.com' do
|
||||
|
||||
@ -46,7 +46,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns totalItems' do
|
||||
@ -85,7 +85,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns orderedItems with public or unlisted statuses' do
|
||||
@ -133,7 +133,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns orderedItems with public or unlisted statuses' do
|
||||
@ -159,7 +159,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns orderedItems with private statuses' do
|
||||
@ -185,7 +185,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns empty orderedItems' do
|
||||
@ -210,7 +210,7 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'returns empty orderedItems' do
|
||||
|
||||
@ -73,7 +73,7 @@ RSpec.describe ActivityPub::RepliesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it_behaves_like 'cachable response'
|
||||
@ -120,7 +120,7 @@ RSpec.describe ActivityPub::RepliesController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.content_type).to eq 'application/activity+json'
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it_behaves_like 'cachable response'
|
||||
|
||||
@ -3,9 +3,19 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::DashboardController, type: :controller do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns 200' do
|
||||
before do
|
||||
allow(Admin::SystemCheck).to receive(:perform).and_return([
|
||||
Admin::SystemCheck::Message.new(:database_schema_check),
|
||||
Admin::SystemCheck::Message.new(:rules_check, nil, admin_rules_path),
|
||||
Admin::SystemCheck::Message.new(:sidekiq_process_check, 'foo, bar'),
|
||||
])
|
||||
sign_in Fabricate(:user, admin: true)
|
||||
end
|
||||
|
||||
it 'returns 200' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
@ -20,4 +20,16 @@ RSpec.describe Admin::TagsController, type: :controller do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let!(:tag) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
get :show, params: { id: tag.id }
|
||||
end
|
||||
|
||||
it 'returns status 200' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,8 +30,8 @@ describe Api::V1::Accounts::CredentialsController do
|
||||
patch :update, params: {
|
||||
display_name: "Alice Isn't Dead",
|
||||
note: "Hi!\n\nToot toot!",
|
||||
avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
|
||||
header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
|
||||
avatar: fixture_file_upload('avatar.gif', 'image/gif'),
|
||||
header: fixture_file_upload('attachment.jpg', 'image/jpeg'),
|
||||
source: {
|
||||
privacy: 'unlisted',
|
||||
sensitive: true,
|
||||
|
||||
@ -268,6 +268,34 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #mute with nonzero duration set' do
|
||||
let(:scopes) { 'write:mutes' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
user.account.follow!(other_account)
|
||||
post :mute, params: { id: other_account.id, duration: 300 }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'does not remove the following relation between user and target user' do
|
||||
expect(user.account.following?(other_account)).to be true
|
||||
end
|
||||
|
||||
it 'creates a muting relation' do
|
||||
expect(user.account.muting?(other_account)).to be true
|
||||
end
|
||||
|
||||
it 'mutes notifications' do
|
||||
expect(user.account.muting_notifications?(other_account)).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
||||
end
|
||||
|
||||
describe 'POST #unmute' do
|
||||
let(:scopes) { 'write:mutes' }
|
||||
let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
@ -4,23 +4,83 @@ RSpec.describe Api::V1::AppsController, type: :controller do
|
||||
render_views
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:client_name) { 'Test app' }
|
||||
let(:scopes) { nil }
|
||||
let(:redirect_uris) { 'urn:ietf:wg:oauth:2.0:oob' }
|
||||
let(:website) { nil }
|
||||
|
||||
let(:app_params) do
|
||||
{
|
||||
client_name: client_name,
|
||||
redirect_uris: redirect_uris,
|
||||
scopes: scopes,
|
||||
website: website,
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
post :create, params: { client_name: 'Test app', redirect_uris: 'urn:ietf:wg:oauth:2.0:oob' }
|
||||
post :create, params: app_params
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
context 'with valid params' do
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'creates an OAuth app' do
|
||||
expect(Doorkeeper::Application.find_by(name: client_name)).to_not be nil
|
||||
end
|
||||
|
||||
it 'returns client ID and client secret' do
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:client_id]).to_not be_blank
|
||||
expect(json[:client_secret]).to_not be_blank
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates an OAuth app' do
|
||||
expect(Doorkeeper::Application.find_by(name: 'Test app')).to_not be nil
|
||||
context 'with an unsupported scope' do
|
||||
let(:scopes) { 'hoge' }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns client ID and client secret' do
|
||||
json = body_as_json
|
||||
context 'with many duplicate scopes' do
|
||||
let(:scopes) { (%w(read) * 40).join(' ') }
|
||||
|
||||
expect(json[:client_id]).to_not be_blank
|
||||
expect(json[:client_secret]).to_not be_blank
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'only saves the scope once' do
|
||||
expect(Doorkeeper::Application.find_by(name: client_name).scopes.to_s).to eq 'read'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a too-long name' do
|
||||
let(:client_name) { 'hoge' * 20 }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a too-long website' do
|
||||
let(:website) { 'https://foo.bar/' + ('hoge' * 2_000) }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a too-long redirect_uris' do
|
||||
let(:redirect_uris) { 'https://foo.bar/' + ('hoge' * 2_000) }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,7 +8,7 @@ RSpec.describe Api::V1::FollowRequestsController, type: :controller do
|
||||
let(:follower) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
FollowService.new.call(follower, user.account.acct)
|
||||
FollowService.new.call(follower, user.account)
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
context 'when imagemagick cant identify the file type' do
|
||||
before do
|
||||
expect_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Errors::NotIdentifiedByImageMagickError)
|
||||
post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') }
|
||||
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
||||
end
|
||||
|
||||
it 'returns http 422' do
|
||||
@ -26,7 +26,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
context 'when there is a generic error' do
|
||||
before do
|
||||
expect_any_instance_of(Account).to receive_message_chain(:media_attachments, :create!).and_raise(Paperclip::Error)
|
||||
post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') }
|
||||
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
||||
end
|
||||
|
||||
it 'returns http 422' do
|
||||
@ -37,7 +37,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
|
||||
context 'image/jpeg' do
|
||||
before do
|
||||
post :create, params: { file: fixture_file_upload('files/attachment.jpg', 'image/jpeg') }
|
||||
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
@ -59,7 +59,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
|
||||
context 'image/gif' do
|
||||
before do
|
||||
post :create, params: { file: fixture_file_upload('files/attachment.gif', 'image/gif') }
|
||||
post :create, params: { file: fixture_file_upload('attachment.gif', 'image/gif') }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
@ -81,7 +81,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
|
||||
context 'video/webm' do
|
||||
before do
|
||||
post :create, params: { file: fixture_file_upload('files/attachment.webm', 'video/webm') }
|
||||
post :create, params: { file: fixture_file_upload('attachment.webm', 'video/webm') }
|
||||
end
|
||||
|
||||
it do
|
||||
|
||||
@ -57,7 +57,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
|
||||
@mention_from_status = mentioning_status.mentions.first
|
||||
@favourite = FavouriteService.new.call(other.account, first_status)
|
||||
@second_favourite = FavouriteService.new.call(third.account, first_status)
|
||||
@follow = FollowService.new.call(other.account, 'alice')
|
||||
@follow = FollowService.new.call(other.account, user.account)
|
||||
end
|
||||
|
||||
describe 'with no options' do
|
||||
|
||||
@ -27,20 +27,27 @@ describe Api::V1::Push::SubscriptionsController do
|
||||
let(:alerts_payload) do
|
||||
{
|
||||
data: {
|
||||
policy: 'all',
|
||||
|
||||
alerts: {
|
||||
follow: true,
|
||||
follow_request: true,
|
||||
favourite: false,
|
||||
reblog: true,
|
||||
mention: false,
|
||||
poll: true,
|
||||
status: false,
|
||||
}
|
||||
}
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'saves push subscriptions' do
|
||||
before do
|
||||
post :create, params: create_payload
|
||||
end
|
||||
|
||||
it 'saves push subscriptions' do
|
||||
push_subscription = Web::PushSubscription.find_by(endpoint: create_payload[:subscription][:endpoint])
|
||||
|
||||
expect(push_subscription.endpoint).to eq(create_payload[:subscription][:endpoint])
|
||||
@ -52,31 +59,34 @@ describe Api::V1::Push::SubscriptionsController do
|
||||
|
||||
it 'replaces old subscription on repeat calls' do
|
||||
post :create, params: create_payload
|
||||
post :create, params: create_payload
|
||||
|
||||
expect(Web::PushSubscription.where(endpoint: create_payload[:subscription][:endpoint]).count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
it 'changes alert settings' do
|
||||
before do
|
||||
post :create, params: create_payload
|
||||
put :update, params: alerts_payload
|
||||
end
|
||||
|
||||
it 'changes alert settings' do
|
||||
push_subscription = Web::PushSubscription.find_by(endpoint: create_payload[:subscription][:endpoint])
|
||||
|
||||
expect(push_subscription.data.dig('alerts', 'follow')).to eq(alerts_payload[:data][:alerts][:follow].to_s)
|
||||
expect(push_subscription.data.dig('alerts', 'favourite')).to eq(alerts_payload[:data][:alerts][:favourite].to_s)
|
||||
expect(push_subscription.data.dig('alerts', 'reblog')).to eq(alerts_payload[:data][:alerts][:reblog].to_s)
|
||||
expect(push_subscription.data.dig('alerts', 'mention')).to eq(alerts_payload[:data][:alerts][:mention].to_s)
|
||||
expect(push_subscription.data['policy']).to eq(alerts_payload[:data][:policy])
|
||||
|
||||
%w(follow follow_request favourite reblog mention poll status).each do |type|
|
||||
expect(push_subscription.data['alerts'][type]).to eq(alerts_payload[:data][:alerts][type.to_sym].to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'removes the subscription' do
|
||||
before do
|
||||
post :create, params: create_payload
|
||||
delete :destroy
|
||||
end
|
||||
|
||||
it 'removes the subscription' do
|
||||
expect(Web::PushSubscription.find_by(endpoint: create_payload[:subscription][:endpoint])).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -22,11 +22,16 @@ describe Api::Web::PushSubscriptionsController do
|
||||
let(:alerts_payload) do
|
||||
{
|
||||
data: {
|
||||
policy: 'all',
|
||||
|
||||
alerts: {
|
||||
follow: true,
|
||||
follow_request: false,
|
||||
favourite: false,
|
||||
reblog: true,
|
||||
mention: false,
|
||||
poll: true,
|
||||
status: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,10 +64,11 @@ describe Api::Web::PushSubscriptionsController do
|
||||
|
||||
push_subscription = Web::PushSubscription.find_by(endpoint: create_payload[:subscription][:endpoint])
|
||||
|
||||
expect(push_subscription.data['alerts']['follow']).to eq(alerts_payload[:data][:alerts][:follow].to_s)
|
||||
expect(push_subscription.data['alerts']['favourite']).to eq(alerts_payload[:data][:alerts][:favourite].to_s)
|
||||
expect(push_subscription.data['alerts']['reblog']).to eq(alerts_payload[:data][:alerts][:reblog].to_s)
|
||||
expect(push_subscription.data['alerts']['mention']).to eq(alerts_payload[:data][:alerts][:mention].to_s)
|
||||
expect(push_subscription.data['policy']).to eq 'all'
|
||||
|
||||
%w(follow follow_request favourite reblog mention poll status).each do |type|
|
||||
expect(push_subscription.data['alerts'][type]).to eq(alerts_payload[:data][:alerts][type.to_sym].to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -81,10 +87,11 @@ describe Api::Web::PushSubscriptionsController do
|
||||
|
||||
push_subscription = Web::PushSubscription.find_by(endpoint: create_payload[:subscription][:endpoint])
|
||||
|
||||
expect(push_subscription.data['alerts']['follow']).to eq(alerts_payload[:data][:alerts][:follow].to_s)
|
||||
expect(push_subscription.data['alerts']['favourite']).to eq(alerts_payload[:data][:alerts][:favourite].to_s)
|
||||
expect(push_subscription.data['alerts']['reblog']).to eq(alerts_payload[:data][:alerts][:reblog].to_s)
|
||||
expect(push_subscription.data['alerts']['mention']).to eq(alerts_payload[:data][:alerts][:mention].to_s)
|
||||
expect(push_subscription.data['policy']).to eq 'all'
|
||||
|
||||
%w(follow follow_request favourite reblog mention poll status).each do |type|
|
||||
expect(push_subscription.data['alerts'][type]).to eq(alerts_payload[:data][:alerts][type.to_sym].to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -42,20 +42,6 @@ describe ApplicationController, type: :controller do
|
||||
include_examples 'respond_with_error', 422
|
||||
end
|
||||
|
||||
it "does not force ssl if Rails.env.production? is not 'true'" do
|
||||
routes.draw { get 'success' => 'anonymous#success' }
|
||||
allow(Rails.env).to receive(:production?).and_return(false)
|
||||
get 'success'
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it "forces ssl if Rails.env.production? is 'true'" do
|
||||
routes.draw { get 'success' => 'anonymous#success' }
|
||||
allow(Rails.env).to receive(:production?).and_return(true)
|
||||
get 'success'
|
||||
expect(response).to redirect_to('https://test.host/success')
|
||||
end
|
||||
|
||||
describe 'helper_method :current_account' do
|
||||
it 'returns nil if not signed in' do
|
||||
expect(controller.view_context.current_account).to be_nil
|
||||
@ -349,10 +335,6 @@ describe ApplicationController, type: :controller do
|
||||
expect(C.new.cache_collection(raw, Object)).to eq raw
|
||||
end
|
||||
|
||||
context 'Notification' do
|
||||
include_examples 'cacheable', :notification, Notification
|
||||
end
|
||||
|
||||
context 'Status' do
|
||||
include_examples 'cacheable', :status, Status
|
||||
end
|
||||
|
||||
@ -32,6 +32,52 @@ describe Auth::ConfirmationsController, type: :controller do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is unconfirmed and unapproved' do
|
||||
let!(:user) { Fabricate(:user, confirmation_token: 'foobar', confirmed_at: nil, approved: false) }
|
||||
|
||||
before do
|
||||
allow(BootstrapTimelineWorker).to receive(:perform_async)
|
||||
@request.env['devise.mapping'] = Devise.mappings[:user]
|
||||
get :show, params: { confirmation_token: 'foobar' }
|
||||
end
|
||||
|
||||
it 'redirects to login' do
|
||||
expect(response).to redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is already confirmed' do
|
||||
let!(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
allow(BootstrapTimelineWorker).to receive(:perform_async)
|
||||
@request.env['devise.mapping'] = Devise.mappings[:user]
|
||||
sign_in(user, scope: :user)
|
||||
get :show, params: { confirmation_token: 'foobar' }
|
||||
end
|
||||
|
||||
it 'redirects to root path' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is already confirmed but unapproved' do
|
||||
let!(:user) { Fabricate(:user, approved: false) }
|
||||
|
||||
before do
|
||||
allow(BootstrapTimelineWorker).to receive(:perform_async)
|
||||
@request.env['devise.mapping'] = Devise.mappings[:user]
|
||||
user.approved = false
|
||||
user.save!
|
||||
sign_in(user, scope: :user)
|
||||
get :show, params: { confirmation_token: 'foobar' }
|
||||
end
|
||||
|
||||
it 'redirects to settings' do
|
||||
expect(response).to redirect_to(edit_user_registration_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is updating email' do
|
||||
let!(:user) { Fabricate(:user, confirmation_token: 'foobar', unconfirmed_email: 'new-email@example.com') }
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'shows a login error' do
|
||||
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email')
|
||||
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email'))
|
||||
end
|
||||
|
||||
it "doesn't log the user in" do
|
||||
@ -136,7 +136,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'shows a login error' do
|
||||
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email')
|
||||
expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: I18n.t('activerecord.attributes.user.email'))
|
||||
end
|
||||
|
||||
it "doesn't log the user in" do
|
||||
|
||||
@ -99,12 +99,10 @@ describe AuthorizeInteractionsController do
|
||||
|
||||
allow(ResolveAccountService).to receive(:new).and_return(service)
|
||||
allow(service).to receive(:call).with('user@hostname').and_return(target_account)
|
||||
allow(service).to receive(:call).with(target_account, skip_webfinger: true).and_return(target_account)
|
||||
|
||||
|
||||
post :create, params: { acct: 'acct:user@hostname' }
|
||||
|
||||
expect(service).to have_received(:call).with(target_account, skip_webfinger: true)
|
||||
expect(account.following?(target_account)).to be true
|
||||
expect(response).to render_template(:success)
|
||||
end
|
||||
|
||||
40
spec/controllers/concerns/cache_concern_spec.rb
Normal file
40
spec/controllers/concerns/cache_concern_spec.rb
Normal file
@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CacheConcern, type: :controller do
|
||||
controller(ApplicationController) do
|
||||
include CacheConcern
|
||||
|
||||
def empty_array
|
||||
render plain: cache_collection([], Status).size
|
||||
end
|
||||
|
||||
def empty_relation
|
||||
render plain: cache_collection(Status.none, Status).size
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
routes.draw do
|
||||
get 'empty_array' => 'anonymous#empty_array'
|
||||
post 'empty_relation' => 'anonymous#empty_relation'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#cache_collection' do
|
||||
context 'given an empty array' do
|
||||
it 'returns an empty array' do
|
||||
get :empty_array
|
||||
expect(response.body).to eq '0'
|
||||
end
|
||||
end
|
||||
|
||||
context 'given an empty relation' do
|
||||
it 'returns an empty array' do
|
||||
get :empty_relation
|
||||
expect(response.body).to eq '0'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -22,8 +22,8 @@ describe ApplicationController, type: :controller do
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'text/csv'
|
||||
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="anonymous.csv"'
|
||||
expect(response.media_type).to eq 'text/csv'
|
||||
expect(response.headers['Content-Disposition']).to start_with 'attachment; filename="anonymous.csv"'
|
||||
expect(response.body).to eq user.account.username
|
||||
end
|
||||
|
||||
|
||||
@ -36,11 +36,7 @@ describe RelationshipsController do
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
let(:poopfeast) { Fabricate(:account, username: 'poopfeast', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
|
||||
|
||||
before do
|
||||
stub_request(:post, 'http://example.com/salmon').to_return(status: 200)
|
||||
end
|
||||
let(:poopfeast) { Fabricate(:account, username: 'poopfeast', domain: 'example.com') }
|
||||
|
||||
shared_examples 'redirects back to followers page' do
|
||||
it 'redirects back to followers page' do
|
||||
|
||||
@ -21,7 +21,7 @@ RSpec.describe Settings::ImportsController, type: :controller do
|
||||
post :create, params: {
|
||||
import: {
|
||||
type: 'following',
|
||||
data: fixture_file_upload('files/imports.txt')
|
||||
data: fixture_file_upload('imports.txt')
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ RSpec.describe Settings::ImportsController, type: :controller do
|
||||
post :create, params: {
|
||||
import: {
|
||||
type: 'blocking',
|
||||
data: fixture_file_upload('files/imports.txt')
|
||||
data: fixture_file_upload('imports.txt')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ describe Settings::MigrationsController do
|
||||
it_behaves_like 'authenticate user'
|
||||
end
|
||||
|
||||
context 'when user is sign in' do
|
||||
context 'when user is signed in' do
|
||||
subject { post :create, params: { account_migration: { acct: acct, current_password: '12345678' } } }
|
||||
|
||||
let(:user) { Fabricate(:user, password: '12345678') }
|
||||
@ -67,12 +67,45 @@ describe Settings::MigrationsController do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when acct is a current account' do
|
||||
context 'when acct is the current account' do
|
||||
let(:acct) { user.account }
|
||||
|
||||
it 'renders show' do
|
||||
is_expected.to render_template :show
|
||||
end
|
||||
|
||||
it 'does not update the moved account' do
|
||||
expect(user.account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when target account does not reference the account being moved from' do
|
||||
let(:acct) { Fabricate(:account, also_known_as: []) }
|
||||
|
||||
it 'renders show' do
|
||||
is_expected.to render_template :show
|
||||
end
|
||||
|
||||
it 'does not update the moved account' do
|
||||
expect(user.account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a recent migration already exists ' do
|
||||
let(:acct) { Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)]) }
|
||||
|
||||
before do
|
||||
moved_to = Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(user.account)])
|
||||
user.account.migrations.create!(acct: moved_to.acct)
|
||||
end
|
||||
|
||||
it 'renders show' do
|
||||
is_expected.to render_template :show
|
||||
end
|
||||
|
||||
it 'does not update the moved account' do
|
||||
expect(user.account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -33,7 +33,7 @@ RSpec.describe Settings::ProfilesController, type: :controller do
|
||||
account = Fabricate(:account, user: @user, display_name: 'AvatarTest')
|
||||
expect(account.avatar.instance.avatar_file_name).to be_nil
|
||||
|
||||
put :update, params: { account: { avatar: fixture_file_upload('files/avatar.gif', 'image/gif') } }
|
||||
put :update, params: { account: { avatar: fixture_file_upload('avatar.gif', 'image/gif') } }
|
||||
expect(response).to redirect_to(settings_profile_path)
|
||||
expect(account.reload.avatar.instance.avatar_file_name).not_to be_nil
|
||||
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
|
||||
@ -44,7 +44,7 @@ RSpec.describe Settings::ProfilesController, type: :controller do
|
||||
it 'gives the user an error message' do
|
||||
allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
|
||||
account = Fabricate(:account, user: @user, display_name: 'AvatarTest')
|
||||
put :update, params: { account: { avatar: fixture_file_upload('files/4096x4097.png', 'image/png') } }
|
||||
put :update, params: { account: { avatar: fixture_file_upload('4096x4097.png', 'image/png') } }
|
||||
expect(response.body).to include('images are not supported')
|
||||
end
|
||||
end
|
||||
|
||||
@ -11,7 +11,7 @@ describe Settings::TwoFactorAuthentication::ConfirmationsController do
|
||||
subject
|
||||
|
||||
expect(assigns(:confirmation)).to be_instance_of Form::TwoFactorConfirmation
|
||||
expect(assigns(:provision_url)).to eq 'otpauth://totp/local-part@domain?secret=thisisasecretforthespecofnewview&issuer=cb6e6126.ngrok.io'
|
||||
expect(assigns(:provision_url)).to eq 'otpauth://totp/cb6e6126.ngrok.io:local-part%40domain?secret=thisisasecretforthespecofnewview&issuer=cb6e6126.ngrok.io'
|
||||
expect(assigns(:qrcode)).to be_instance_of RQRCode::QRCode
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response).to render_template(:new)
|
||||
|
||||
@ -8,7 +8,7 @@ describe WellKnown::HostMetaController, type: :controller do
|
||||
get :show, format: :xml
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/xrd+xml'
|
||||
expect(response.media_type).to eq 'application/xrd+xml'
|
||||
expect(response.body).to eq <<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
|
||||
@ -8,7 +8,7 @@ describe WellKnown::KeybaseProofConfigController, type: :controller do
|
||||
get :show
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/json'
|
||||
expect(response.media_type).to eq 'application/json'
|
||||
expect { JSON.parse(response.body) }.not_to raise_exception
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,7 +8,7 @@ describe WellKnown::NodeInfoController, type: :controller do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/json'
|
||||
expect(response.media_type).to eq 'application/json'
|
||||
|
||||
json = body_as_json
|
||||
|
||||
@ -23,7 +23,7 @@ describe WellKnown::NodeInfoController, type: :controller do
|
||||
get :show
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/json'
|
||||
expect(response.media_type).to eq 'application/json'
|
||||
|
||||
json = body_as_json
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ describe WellKnown::WebfingerController, type: :controller do
|
||||
end
|
||||
|
||||
it 'returns application/jrd+json' do
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
expect(response.media_type).to eq 'application/jrd+json'
|
||||
end
|
||||
|
||||
it 'returns links for the account' do
|
||||
|
||||
4
spec/fabricators/canonical_email_block_fabricator.rb
Normal file
4
spec/fabricators/canonical_email_block_fabricator.rb
Normal file
@ -0,0 +1,4 @@
|
||||
Fabricator(:canonical_email_block) do
|
||||
email "test@example.com"
|
||||
reference_account { Fabricate(:account) }
|
||||
end
|
||||
@ -0,0 +1,3 @@
|
||||
Fabricator(:follow_recommendation_suppression) do
|
||||
account
|
||||
end
|
||||
5
spec/fabricators/rule_fabricator.rb
Normal file
5
spec/fabricators/rule_fabricator.rb
Normal file
@ -0,0 +1,5 @@
|
||||
Fabricator(:rule) do
|
||||
priority ""
|
||||
deleted_at "2021-02-21 05:51:09"
|
||||
text "MyText"
|
||||
end
|
||||
@ -67,7 +67,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||
end
|
||||
end
|
||||
|
||||
context 'public' do
|
||||
context 'public with explicit public address' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
@ -85,7 +85,43 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlisted' do
|
||||
context 'public with as:Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'as:Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'public'
|
||||
end
|
||||
end
|
||||
|
||||
context 'public with Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'public'
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlisted with explicit public address' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
@ -103,6 +139,42 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlisted with as:Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'as:Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'unlisted'
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlisted with Public' do
|
||||
let(:object_json) do
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
cc: 'Public',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.visibility).to eq 'unlisted'
|
||||
end
|
||||
end
|
||||
|
||||
context 'private' do
|
||||
let(:object_json) do
|
||||
{
|
||||
|
||||
@ -49,4 +49,24 @@ RSpec.describe ActivityPub::Activity::Delete do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the status has been reported' do
|
||||
describe '#perform' do
|
||||
subject { described_class.new(json, sender) }
|
||||
let!(:reporter) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
reporter.reports.create!(target_account: status.account, status_ids: [status.id], forwarded: false)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'marks the status as deleted' do
|
||||
expect(Status.find_by(id: status.id)).to be_nil
|
||||
end
|
||||
|
||||
it 'actually keeps a copy for inspection' do
|
||||
expect(Status.with_discarded.find_by(id: status.id)).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -17,62 +17,171 @@ RSpec.describe ActivityPub::Activity::Follow do
|
||||
describe '#perform' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
context 'unlocked account' do
|
||||
before do
|
||||
subject.perform
|
||||
context 'with no prior follow' do
|
||||
context 'unlocked account' do
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
context 'silenced account following an unlocked account' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
context 'unlocked account muting the sender' do
|
||||
before do
|
||||
recipient.mute!(sender)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'silenced account following an unlocked account' do
|
||||
context 'when a follow relationship already exists' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
sender.active_relationships.create!(target_account: recipient, uri: 'bar')
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
context 'unlocked account' do
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
context 'silenced account following an unlocked account' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlocked account muting the sender' do
|
||||
before do
|
||||
recipient.mute!(sender)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.active_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'unlocked account muting the sender' do
|
||||
context 'when a follow request already exists' do
|
||||
before do
|
||||
recipient.mute!(sender)
|
||||
subject.perform
|
||||
sender.follow_requests.create!(target_account: recipient, uri: 'bar')
|
||||
end
|
||||
|
||||
it 'creates a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be true
|
||||
context 'silenced account following an unlocked account' do
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not create a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
end
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
context 'locked account' do
|
||||
before do
|
||||
recipient.update(locked: true)
|
||||
subject.perform
|
||||
end
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
it 'correctly sets the new URI' do
|
||||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,23 +1,11 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::Activity::Move do
|
||||
let(:follower) { Fabricate(:account) }
|
||||
let(:old_account) { Fabricate(:account) }
|
||||
let(:new_account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
follower.follow!(old_account)
|
||||
|
||||
old_account.update!(uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox')
|
||||
new_account.update!(uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: [old_account.uri])
|
||||
|
||||
stub_request(:post, 'https://example.org/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
|
||||
|
||||
service_stub = double
|
||||
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
|
||||
allow(service_stub).to receive(:call).and_return(new_account)
|
||||
end
|
||||
let(:follower) { Fabricate(:account) }
|
||||
let(:old_account) { Fabricate(:account, uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox') }
|
||||
let(:new_account) { Fabricate(:account, uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: also_known_as) }
|
||||
let(:also_known_as) { [old_account.uri] }
|
||||
let(:returned_account) { new_account }
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
@ -30,6 +18,17 @@ RSpec.describe ActivityPub::Activity::Move do
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
follower.follow!(old_account)
|
||||
|
||||
stub_request(:post, old_account.inbox_url).to_return(status: 200)
|
||||
stub_request(:post, new_account.inbox_url).to_return(status: 200)
|
||||
|
||||
service_stub = double
|
||||
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
|
||||
allow(service_stub).to receive(:call).and_return(returned_account)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
subject { described_class.new(json, old_account) }
|
||||
|
||||
@ -37,16 +36,70 @@ RSpec.describe ActivityPub::Activity::Move do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'sets moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to eq new_account.id
|
||||
context 'when all conditions are met' do
|
||||
it 'sets moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to eq new_account.id
|
||||
end
|
||||
|
||||
it 'makes followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be false
|
||||
end
|
||||
|
||||
it 'makes followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'makes followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be false
|
||||
context "when the new account can't be resolved" do
|
||||
let(:returned_account) { nil }
|
||||
|
||||
it 'does not set moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be true
|
||||
end
|
||||
|
||||
it 'does not make followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it 'makes followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be true
|
||||
context 'when the new account does not references the old account' do
|
||||
let(:also_known_as) { [] }
|
||||
|
||||
it 'does not set moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be true
|
||||
end
|
||||
|
||||
it 'does not make followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a Move has been recently processed' do
|
||||
around do |example|
|
||||
Redis.current.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
|
||||
example.run
|
||||
Redis.current.del("move_in_progress:#{old_account.id}")
|
||||
end
|
||||
|
||||
it 'does not set moved account on old account' do
|
||||
expect(old_account.reload.moved_to_account_id).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make followers unfollow old account' do
|
||||
expect(follower.following?(old_account)).to be true
|
||||
end
|
||||
|
||||
it 'does not make followers follow-request the new account' do
|
||||
expect(follower.requested?(new_account)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -13,7 +13,7 @@ RSpec.describe ActivityPub::Activity::Update do
|
||||
end
|
||||
|
||||
let(:modified_sender) do
|
||||
sender.dup.tap do |modified_sender|
|
||||
sender.tap do |modified_sender|
|
||||
modified_sender.display_name = 'Totally modified now'
|
||||
end
|
||||
end
|
||||
|
||||
@ -81,6 +81,6 @@ RSpec.describe ActivityPub::LinkedDataSignature do
|
||||
options_hash = Digest::SHA256.hexdigest(canonicalize(options.merge('@context' => ActivityPub::LinkedDataSignature::CONTEXT)))
|
||||
document_hash = Digest::SHA256.hexdigest(canonicalize(document))
|
||||
to_be_verified = options_hash + document_hash
|
||||
Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest::SHA256.new, to_be_verified))
|
||||
Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_verified))
|
||||
end
|
||||
end
|
||||
|
||||
19
spec/lib/entity_cache_spec.rb
Normal file
19
spec/lib/entity_cache_spec.rb
Normal file
@ -0,0 +1,19 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EntityCache do
|
||||
let(:local_account) { Fabricate(:account, domain: nil, username: 'alice') }
|
||||
let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') }
|
||||
|
||||
describe '#emoji' do
|
||||
subject { EntityCache.instance.emoji(shortcodes, domain) }
|
||||
|
||||
context 'called with an empty list of shortcodes' do
|
||||
let(:shortcodes) { [] }
|
||||
let(:domain) { 'example.org' }
|
||||
|
||||
it 'returns an empty array' do
|
||||
is_expected.to eq []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -21,6 +21,14 @@ RSpec.describe Formatter do
|
||||
end
|
||||
end
|
||||
|
||||
context 'given a stand-alone URL with a newer TLD' do
|
||||
let(:text) { 'http://example.gay' }
|
||||
|
||||
it 'matches the full URL' do
|
||||
is_expected.to include 'href="http://example.gay"'
|
||||
end
|
||||
end
|
||||
|
||||
context 'given a stand-alone IDN URL' do
|
||||
let(:text) { 'https://nic.みんな/' }
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require Rails.root.join('app', 'lib', 'sanitize_config.rb')
|
||||
|
||||
describe Sanitize::Config do
|
||||
describe '::MASTODON_STRICT' do
|
||||
|
||||
@ -1,192 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SpamCheck do
|
||||
let!(:sender) { Fabricate(:account) }
|
||||
let!(:alice) { Fabricate(:account, username: 'alice') }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
def status_with_html(text, options = {})
|
||||
status = PostStatusService.new.call(sender, { text: text }.merge(options))
|
||||
status.update_columns(text: Formatter.instance.format(status), local: false)
|
||||
status
|
||||
end
|
||||
|
||||
describe '#hashable_text' do
|
||||
it 'removes mentions from HTML for remote statuses' do
|
||||
status = status_with_html('@alice Hello')
|
||||
expect(described_class.new(status).hashable_text).to eq 'hello'
|
||||
end
|
||||
|
||||
it 'removes mentions from text for local statuses' do
|
||||
status = PostStatusService.new.call(alice, text: "Hey @#{sender.username}, how are you?")
|
||||
expect(described_class.new(status).hashable_text).to eq 'hey , how are you?'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#insufficient_data?' do
|
||||
it 'returns true when there is no text' do
|
||||
status = status_with_html('@alice')
|
||||
expect(described_class.new(status).insufficient_data?).to be true
|
||||
end
|
||||
|
||||
it 'returns false when there is text' do
|
||||
status = status_with_html('@alice h')
|
||||
expect(described_class.new(status).insufficient_data?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#digest' do
|
||||
it 'returns a string' do
|
||||
status = status_with_html('@alice Hello world')
|
||||
expect(described_class.new(status).digest).to be_a String
|
||||
end
|
||||
end
|
||||
|
||||
describe '#spam?' do
|
||||
it 'returns false for a unique status' do
|
||||
status = status_with_html('@alice Hello')
|
||||
expect(described_class.new(status).spam?).to be false
|
||||
end
|
||||
|
||||
it 'returns false for different statuses to the same recipient' do
|
||||
status1 = status_with_html('@alice Hello')
|
||||
described_class.new(status1).remember!
|
||||
status2 = status_with_html('@alice Are you available to talk?')
|
||||
expect(described_class.new(status2).spam?).to be false
|
||||
end
|
||||
|
||||
it 'returns false for statuses with different content warnings' do
|
||||
status1 = status_with_html('@alice Are you available to talk?')
|
||||
described_class.new(status1).remember!
|
||||
status2 = status_with_html('@alice Are you available to talk?', spoiler_text: 'This is a completely different matter than what I was talking about previously, I swear!')
|
||||
expect(described_class.new(status2).spam?).to be false
|
||||
end
|
||||
|
||||
it 'returns false for different statuses to different recipients' do
|
||||
status1 = status_with_html('@alice How is it going?')
|
||||
described_class.new(status1).remember!
|
||||
status2 = status_with_html('@bob Are you okay?')
|
||||
expect(described_class.new(status2).spam?).to be false
|
||||
end
|
||||
|
||||
it 'returns false for very short different statuses to different recipients' do
|
||||
status1 = status_with_html('@alice 🙄')
|
||||
described_class.new(status1).remember!
|
||||
status2 = status_with_html('@bob Huh?')
|
||||
expect(described_class.new(status2).spam?).to be false
|
||||
end
|
||||
|
||||
it 'returns false for statuses with no text' do
|
||||
status1 = status_with_html('@alice')
|
||||
described_class.new(status1).remember!
|
||||
status2 = status_with_html('@bob')
|
||||
expect(described_class.new(status2).spam?).to be false
|
||||
end
|
||||
|
||||
it 'returns true for duplicate statuses to the same recipient' do
|
||||
described_class::THRESHOLD.times do
|
||||
status1 = status_with_html('@alice Hello')
|
||||
described_class.new(status1).remember!
|
||||
end
|
||||
|
||||
status2 = status_with_html('@alice Hello')
|
||||
expect(described_class.new(status2).spam?).to be true
|
||||
end
|
||||
|
||||
it 'returns true for duplicate statuses to different recipients' do
|
||||
described_class::THRESHOLD.times do
|
||||
status1 = status_with_html('@alice Hello')
|
||||
described_class.new(status1).remember!
|
||||
end
|
||||
|
||||
status2 = status_with_html('@bob Hello')
|
||||
expect(described_class.new(status2).spam?).to be true
|
||||
end
|
||||
|
||||
it 'returns true for nearly identical statuses with random numbers' do
|
||||
source_text = 'Sodium, atomic number 11, was first isolated by Humphry Davy in 1807. A chemical component of salt, he named it Na in honor of the saltiest region on earth, North America.'
|
||||
|
||||
described_class::THRESHOLD.times do
|
||||
status1 = status_with_html('@alice ' + source_text + ' 1234')
|
||||
described_class.new(status1).remember!
|
||||
end
|
||||
|
||||
status2 = status_with_html('@bob ' + source_text + ' 9568')
|
||||
expect(described_class.new(status2).spam?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#skip?' do
|
||||
it 'returns true when the sender is already silenced' do
|
||||
status = status_with_html('@alice Hello')
|
||||
sender.silence!
|
||||
expect(described_class.new(status).skip?).to be true
|
||||
end
|
||||
|
||||
it 'returns true when the mentioned person follows the sender' do
|
||||
status = status_with_html('@alice Hello')
|
||||
alice.follow!(sender)
|
||||
expect(described_class.new(status).skip?).to be true
|
||||
end
|
||||
|
||||
it 'returns false when even one mentioned person doesn\'t follow the sender' do
|
||||
status = status_with_html('@alice @bob Hello')
|
||||
alice.follow!(sender)
|
||||
expect(described_class.new(status).skip?).to be false
|
||||
end
|
||||
|
||||
it 'returns true when the sender is replying to a status that mentions the sender' do
|
||||
parent = PostStatusService.new.call(alice, text: "Hey @#{sender.username}, how are you?")
|
||||
status = status_with_html('@alice @bob Hello', thread: parent)
|
||||
expect(described_class.new(status).skip?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remember!' do
|
||||
let(:status) { status_with_html('@alice') }
|
||||
let(:spam_check) { described_class.new(status) }
|
||||
let(:redis_key) { spam_check.send(:redis_key) }
|
||||
|
||||
it 'remembers' do
|
||||
expect(Redis.current.exists?(redis_key)).to be true
|
||||
spam_check.remember!
|
||||
expect(Redis.current.exists?(redis_key)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reset!' do
|
||||
let(:status) { status_with_html('@alice') }
|
||||
let(:spam_check) { described_class.new(status) }
|
||||
let(:redis_key) { spam_check.send(:redis_key) }
|
||||
|
||||
before do
|
||||
spam_check.remember!
|
||||
end
|
||||
|
||||
it 'resets' do
|
||||
expect(Redis.current.exists?(redis_key)).to be true
|
||||
spam_check.reset!
|
||||
expect(Redis.current.exists?(redis_key)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#flag!' do
|
||||
let!(:status1) { status_with_html('@alice General Kenobi you are a bold one') }
|
||||
let!(:status2) { status_with_html('@alice @bob General Kenobi, you are a bold one') }
|
||||
|
||||
before do
|
||||
described_class.new(status1).remember!
|
||||
described_class.new(status2).flag!
|
||||
end
|
||||
|
||||
it 'creates a report about the account' do
|
||||
expect(sender.targeted_reports.unresolved.count).to eq 1
|
||||
end
|
||||
|
||||
it 'attaches both matching statuses to the report' do
|
||||
expect(sender.targeted_reports.first.status_ids).to include(status1.id, status2.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -83,40 +83,4 @@ RSpec.describe TagManager do
|
||||
expect(TagManager.instance.local_url?('https://domainn.test/')).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#same_acct?' do
|
||||
# The following comparisons MUST be case-insensitive.
|
||||
|
||||
it 'returns true if the needle has a correct username and domain for remote user' do
|
||||
expect(TagManager.instance.same_acct?('username@domain.test', 'UsErNaMe@DoMaIn.Test')).to eq true
|
||||
end
|
||||
|
||||
it 'returns false if the needle is missing a domain for remote user' do
|
||||
expect(TagManager.instance.same_acct?('username@domain.test', 'UsErNaMe')).to eq false
|
||||
end
|
||||
|
||||
it 'returns false if the needle has an incorrect domain for remote user' do
|
||||
expect(TagManager.instance.same_acct?('username@domain.test', 'UsErNaMe@incorrect.test')).to eq false
|
||||
end
|
||||
|
||||
it 'returns false if the needle has an incorrect username for remote user' do
|
||||
expect(TagManager.instance.same_acct?('username@domain.test', 'incorrect@DoMaIn.test')).to eq false
|
||||
end
|
||||
|
||||
it 'returns true if the needle has a correct username and domain for local user' do
|
||||
expect(TagManager.instance.same_acct?('username', 'UsErNaMe@Cb6E6126.nGrOk.Io')).to eq true
|
||||
end
|
||||
|
||||
it 'returns true if the needle is missing a domain for local user' do
|
||||
expect(TagManager.instance.same_acct?('username', 'UsErNaMe')).to eq true
|
||||
end
|
||||
|
||||
it 'returns false if the needle has an incorrect username for local user' do
|
||||
expect(TagManager.instance.same_acct?('username', 'UsErNaM@Cb6E6126.nGrOk.Io')).to eq false
|
||||
end
|
||||
|
||||
it 'returns false if the needle has an incorrect domain for local user' do
|
||||
expect(TagManager.instance.same_acct?('username', 'incorrect@Cb6E6126.nGrOk.Io')).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,12 +10,12 @@ RSpec.describe NotificationMailer, type: :mailer do
|
||||
it 'renders subject localized for the locale of the receiver' do
|
||||
locale = %i(de en).sample
|
||||
receiver.update!(locale: locale)
|
||||
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: locale))
|
||||
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: locale))
|
||||
end
|
||||
|
||||
it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: I18n.default_locale))
|
||||
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: I18n.default_locale))
|
||||
end
|
||||
end
|
||||
|
||||
@ -59,12 +59,12 @@ RSpec.describe NotificationMailer, type: :mailer do
|
||||
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
|
||||
|
||||
it "renders the headers" do
|
||||
expect(mail.subject).to eq("bob favourited your status")
|
||||
expect(mail.subject).to eq("bob favourited your post")
|
||||
expect(mail.to).to eq([receiver.email])
|
||||
end
|
||||
|
||||
it "renders the body" do
|
||||
expect(mail.body.encoded).to match("Your status was favourited by bob")
|
||||
expect(mail.body.encoded).to match("Your post was favourited by bob")
|
||||
expect(mail.body.encoded).to include 'The body of the own status'
|
||||
end
|
||||
end
|
||||
@ -76,12 +76,12 @@ RSpec.describe NotificationMailer, type: :mailer do
|
||||
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
|
||||
|
||||
it "renders the headers" do
|
||||
expect(mail.subject).to eq("bob boosted your status")
|
||||
expect(mail.subject).to eq("bob boosted your post")
|
||||
expect(mail.to).to eq([receiver.email])
|
||||
end
|
||||
|
||||
it "renders the body" do
|
||||
expect(mail.body.encoded).to match("Your status was boosted by bob")
|
||||
expect(mail.body.encoded).to match("Your post was boosted by bob")
|
||||
expect(mail.body.encoded).to include 'The body of the own status'
|
||||
end
|
||||
end
|
||||
|
||||
@ -9,12 +9,12 @@ describe UserMailer, type: :mailer do
|
||||
it 'renders subject localized for the locale of the receiver' do
|
||||
locale = I18n.available_locales.sample
|
||||
receiver.update!(locale: locale)
|
||||
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: locale))
|
||||
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: locale))
|
||||
end
|
||||
|
||||
it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
|
||||
receiver.update!(locale: nil)
|
||||
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: I18n.default_locale))
|
||||
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: I18n.default_locale))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -134,18 +134,6 @@ RSpec.describe Account, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#subscribed?' do
|
||||
it 'returns false when no subscription expiration information is present' do
|
||||
account = Fabricate(:account, subscription_expires_at: nil)
|
||||
expect(account.subscribed?).to be false
|
||||
end
|
||||
|
||||
it 'returns true when subscription expiration has been set' do
|
||||
account = Fabricate(:account, subscription_expires_at: 30.days.from_now)
|
||||
expect(account.subscribed?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#possibly_stale?' do
|
||||
let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) }
|
||||
|
||||
@ -707,21 +695,6 @@ RSpec.describe Account, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'expiring' do
|
||||
it 'returns remote accounts with followers whose subscription expiration date is past or not given' do
|
||||
local = Fabricate(:account, domain: nil)
|
||||
matches = [
|
||||
{ domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' },
|
||||
].map(&method(:Fabricate).curry(2).call(:account))
|
||||
matches.each(&local.method(:follow!))
|
||||
Fabricate(:account, domain: 'remote', subscription_expires_at: nil)
|
||||
local.follow!(Fabricate(:account, domain: 'remote', subscription_expires_at: '2000-01-03T00:00:00Z'))
|
||||
local.follow!(Fabricate(:account, domain: nil, subscription_expires_at: nil))
|
||||
|
||||
expect(Account.expiring('2000-01-02T00:00:00Z').recent).to eq matches.reverse
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote' do
|
||||
it 'returns an array of accounts who have a domain' do
|
||||
account_1 = Fabricate(:account, domain: nil)
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountStat, type: :model do
|
||||
describe '#increment_count!' do
|
||||
it 'increments the count' do
|
||||
account_stat = AccountStat.create(account: Fabricate(:account))
|
||||
expect(account_stat.followers_count).to eq 0
|
||||
account_stat.increment_count!(:followers_count)
|
||||
expect(account_stat.followers_count).to eq 1
|
||||
end
|
||||
|
||||
it 'increments the count in multi-threaded an environment' do
|
||||
account_stat = AccountStat.create(account: Fabricate(:account), statuses_count: 0)
|
||||
increment_by = 15
|
||||
wait_for_start = true
|
||||
|
||||
threads = Array.new(increment_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
AccountStat.find(account_stat.id).increment_count!(:statuses_count)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(account_stat.reload.statuses_count).to eq increment_by
|
||||
end
|
||||
end
|
||||
|
||||
describe '#decrement_count!' do
|
||||
it 'decrements the count' do
|
||||
account_stat = AccountStat.create(account: Fabricate(:account), followers_count: 15)
|
||||
expect(account_stat.followers_count).to eq 15
|
||||
account_stat.decrement_count!(:followers_count)
|
||||
expect(account_stat.followers_count).to eq 14
|
||||
end
|
||||
|
||||
it 'decrements the count in multi-threaded an environment' do
|
||||
account_stat = AccountStat.create(account: Fabricate(:account), statuses_count: 15)
|
||||
decrement_by = 10
|
||||
wait_for_start = true
|
||||
|
||||
threads = Array.new(decrement_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
AccountStat.find(account_stat.id).decrement_count!(:statuses_count)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(account_stat.reload.statuses_count).to eq 5
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,38 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountTagStat, type: :model do
|
||||
key = 'accounts_count'
|
||||
let(:account_tag_stat) { Fabricate(:tag).account_tag_stat }
|
||||
|
||||
describe '#increment_count!' do
|
||||
it 'calls #update' do
|
||||
args = { key => account_tag_stat.public_send(key) + 1 }
|
||||
expect(account_tag_stat).to receive(:update).with(args)
|
||||
account_tag_stat.increment_count!(key)
|
||||
end
|
||||
|
||||
it 'increments value by 1' do
|
||||
expect do
|
||||
account_tag_stat.increment_count!(key)
|
||||
end.to change { account_tag_stat.accounts_count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#decrement_count!' do
|
||||
it 'calls #update' do
|
||||
args = { key => [account_tag_stat.public_send(key) - 1, 0].max }
|
||||
expect(account_tag_stat).to receive(:update).with(args)
|
||||
account_tag_stat.decrement_count!(key)
|
||||
end
|
||||
|
||||
it 'decrements value by 1' do
|
||||
account_tag_stat.update(key => 1)
|
||||
|
||||
expect do
|
||||
account_tag_stat.decrement_count!(key)
|
||||
end.to change { account_tag_stat.accounts_count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
47
spec/models/canonical_email_block_spec.rb
Normal file
47
spec/models/canonical_email_block_spec.rb
Normal file
@ -0,0 +1,47 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe CanonicalEmailBlock, type: :model do
|
||||
describe '#email=' do
|
||||
let(:target_hash) { '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b' }
|
||||
|
||||
it 'sets canonical_email_hash' do
|
||||
subject.email = 'test@example.com'
|
||||
expect(subject.canonical_email_hash).to eq target_hash
|
||||
end
|
||||
|
||||
it 'sets the same hash even with dot permutations' do
|
||||
subject.email = 't.e.s.t@example.com'
|
||||
expect(subject.canonical_email_hash).to eq target_hash
|
||||
end
|
||||
|
||||
it 'sets the same hash even with extensions' do
|
||||
subject.email = 'test+mastodon1@example.com'
|
||||
expect(subject.canonical_email_hash).to eq target_hash
|
||||
end
|
||||
|
||||
it 'sets the same hash with different casing' do
|
||||
subject.email = 'Test@EXAMPLE.com'
|
||||
expect(subject.canonical_email_hash).to eq target_hash
|
||||
end
|
||||
end
|
||||
|
||||
describe '.block?' do
|
||||
let!(:canonical_email_block) { Fabricate(:canonical_email_block, email: 'foo@bar.com') }
|
||||
|
||||
it 'returns true for the same email' do
|
||||
expect(described_class.block?('foo@bar.com')).to be true
|
||||
end
|
||||
|
||||
it 'returns true for the same email with dots' do
|
||||
expect(described_class.block?('f.oo@bar.com')).to be true
|
||||
end
|
||||
|
||||
it 'returns true for the same email with extensions' do
|
||||
expect(described_class.block?('foo+spam@bar.com')).to be true
|
||||
end
|
||||
|
||||
it 'returns false for different email' do
|
||||
expect(described_class.block?('hoge@bar.com')).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
60
spec/models/concerns/account_counters_spec.rb
Normal file
60
spec/models/concerns/account_counters_spec.rb
Normal file
@ -0,0 +1,60 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe AccountCounters do
|
||||
let!(:account) { Fabricate(:account) }
|
||||
|
||||
describe '#increment_count!' do
|
||||
it 'increments the count' do
|
||||
expect(account.followers_count).to eq 0
|
||||
account.increment_count!(:followers_count)
|
||||
expect(account.followers_count).to eq 1
|
||||
end
|
||||
|
||||
it 'increments the count in multi-threaded an environment' do
|
||||
increment_by = 15
|
||||
wait_for_start = true
|
||||
|
||||
threads = Array.new(increment_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
account.increment_count!(:statuses_count)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(account.statuses_count).to eq increment_by
|
||||
end
|
||||
end
|
||||
|
||||
describe '#decrement_count!' do
|
||||
it 'decrements the count' do
|
||||
account.followers_count = 15
|
||||
account.save!
|
||||
expect(account.followers_count).to eq 15
|
||||
account.decrement_count!(:followers_count)
|
||||
expect(account.followers_count).to eq 14
|
||||
end
|
||||
|
||||
it 'decrements the count in multi-threaded an environment' do
|
||||
decrement_by = 10
|
||||
wait_for_start = true
|
||||
|
||||
account.statuses_count = 15
|
||||
account.save!
|
||||
|
||||
threads = Array.new(decrement_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
account.decrement_count!(:statuses_count)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(account.statuses_count).to eq 5
|
||||
end
|
||||
end
|
||||
end
|
||||
4
spec/models/follow_recommendation_suppression_spec.rb
Normal file
4
spec/models/follow_recommendation_suppression_spec.rb
Normal file
@ -0,0 +1,4 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FollowRecommendationSuppression, type: :model do
|
||||
end
|
||||
@ -7,7 +7,7 @@ RSpec.describe FollowRequest, type: :model do
|
||||
let(:target_account) { Fabricate(:account) }
|
||||
|
||||
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
|
||||
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri)
|
||||
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, bypass_limit: true)
|
||||
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
|
||||
expect(follow_request).to receive(:destroy!)
|
||||
follow_request.authorize!
|
||||
|
||||
@ -56,47 +56,114 @@ RSpec.describe Notification, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.reload_stale_associations!' do
|
||||
context 'account_ids are empty' do
|
||||
let(:cached_items) { [] }
|
||||
|
||||
subject { described_class.reload_stale_associations!(cached_items) }
|
||||
|
||||
it 'returns nil' do
|
||||
is_expected.to be nil
|
||||
describe '.preload_cache_collection_target_statuses' do
|
||||
subject do
|
||||
described_class.preload_cache_collection_target_statuses(notifications) do |target_statuses|
|
||||
# preload account for testing instead of using cache_collection
|
||||
Status.preload(:account).where(id: target_statuses.map(&:id))
|
||||
end
|
||||
end
|
||||
|
||||
context 'account_ids are present' do
|
||||
context 'notifications are empty' do
|
||||
let(:notifications) { [] }
|
||||
|
||||
it 'returns []' do
|
||||
is_expected.to eq []
|
||||
end
|
||||
end
|
||||
|
||||
context 'notifications are present' do
|
||||
before do
|
||||
allow(accounts_with_ids).to receive(:[]).with(stale_account1.id).and_return(account1)
|
||||
allow(accounts_with_ids).to receive(:[]).with(stale_account2.id).and_return(account2)
|
||||
allow(Account).to receive_message_chain(:where, :includes, :each_with_object).and_return(accounts_with_ids)
|
||||
notifications.each(&:reload)
|
||||
end
|
||||
|
||||
let(:cached_items) do
|
||||
let(:mention) { Fabricate(:mention) }
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:reblog) { Fabricate(:status, reblog: Fabricate(:status)) }
|
||||
let(:follow) { Fabricate(:follow) }
|
||||
let(:follow_request) { Fabricate(:follow_request) }
|
||||
let(:favourite) { Fabricate(:favourite) }
|
||||
let(:poll) { Fabricate(:poll) }
|
||||
|
||||
let(:notifications) do
|
||||
[
|
||||
Fabricate(:notification, activity: Fabricate(:status)),
|
||||
Fabricate(:notification, activity: Fabricate(:follow)),
|
||||
Fabricate(:notification, type: :mention, activity: mention),
|
||||
Fabricate(:notification, type: :status, activity: status),
|
||||
Fabricate(:notification, type: :reblog, activity: reblog),
|
||||
Fabricate(:notification, type: :follow, activity: follow),
|
||||
Fabricate(:notification, type: :follow_request, activity: follow_request),
|
||||
Fabricate(:notification, type: :favourite, activity: favourite),
|
||||
Fabricate(:notification, type: :poll, activity: poll),
|
||||
]
|
||||
end
|
||||
|
||||
let(:stale_account1) { cached_items[0].from_account }
|
||||
let(:stale_account2) { cached_items[1].from_account }
|
||||
it 'preloads target status' do
|
||||
# mention
|
||||
expect(subject[0].type).to eq :mention
|
||||
expect(subject[0].association(:mention)).to be_loaded
|
||||
expect(subject[0].mention.association(:status)).to be_loaded
|
||||
|
||||
let(:account1) { Fabricate(:account) }
|
||||
let(:account2) { Fabricate(:account) }
|
||||
# status
|
||||
expect(subject[1].type).to eq :status
|
||||
expect(subject[1].association(:status)).to be_loaded
|
||||
|
||||
let(:accounts_with_ids) { { account1.id => account1, account2.id => account2 } }
|
||||
# reblog
|
||||
expect(subject[2].type).to eq :reblog
|
||||
expect(subject[2].association(:status)).to be_loaded
|
||||
expect(subject[2].status.association(:reblog)).to be_loaded
|
||||
|
||||
it 'reloads associations' do
|
||||
expect(cached_items[0].from_account).to be stale_account1
|
||||
expect(cached_items[1].from_account).to be stale_account2
|
||||
# follow: nothing
|
||||
expect(subject[3].type).to eq :follow
|
||||
expect(subject[3].target_status).to be_nil
|
||||
|
||||
described_class.reload_stale_associations!(cached_items)
|
||||
# follow_request: nothing
|
||||
expect(subject[4].type).to eq :follow_request
|
||||
expect(subject[4].target_status).to be_nil
|
||||
|
||||
expect(cached_items[0].from_account).to be account1
|
||||
expect(cached_items[1].from_account).to be account2
|
||||
# favourite
|
||||
expect(subject[5].type).to eq :favourite
|
||||
expect(subject[5].association(:favourite)).to be_loaded
|
||||
expect(subject[5].favourite.association(:status)).to be_loaded
|
||||
|
||||
# poll
|
||||
expect(subject[6].type).to eq :poll
|
||||
expect(subject[6].association(:poll)).to be_loaded
|
||||
expect(subject[6].poll.association(:status)).to be_loaded
|
||||
end
|
||||
|
||||
it 'replaces to cached status' do
|
||||
# mention
|
||||
expect(subject[0].type).to eq :mention
|
||||
expect(subject[0].target_status.association(:account)).to be_loaded
|
||||
expect(subject[0].target_status).to eq mention.status
|
||||
|
||||
# status
|
||||
expect(subject[1].type).to eq :status
|
||||
expect(subject[1].target_status.association(:account)).to be_loaded
|
||||
expect(subject[1].target_status).to eq status
|
||||
|
||||
# reblog
|
||||
expect(subject[2].type).to eq :reblog
|
||||
expect(subject[2].target_status.association(:account)).to be_loaded
|
||||
expect(subject[2].target_status).to eq reblog.reblog
|
||||
|
||||
# follow: nothing
|
||||
expect(subject[3].type).to eq :follow
|
||||
expect(subject[3].target_status).to be_nil
|
||||
|
||||
# follow_request: nothing
|
||||
expect(subject[4].type).to eq :follow_request
|
||||
expect(subject[4].target_status).to be_nil
|
||||
|
||||
# favourite
|
||||
expect(subject[5].type).to eq :favourite
|
||||
expect(subject[5].target_status.association(:account)).to be_loaded
|
||||
expect(subject[5].target_status).to eq favourite.status
|
||||
|
||||
# poll
|
||||
expect(subject[6].type).to eq :poll
|
||||
expect(subject[6].target_status.association(:account)).to be_loaded
|
||||
expect(subject[6].target_status).to eq poll.status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
5
spec/models/rule_spec.rb
Normal file
5
spec/models/rule_spec.rb
Normal file
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Rule, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@ -74,13 +74,13 @@ RSpec.describe SessionActivation, type: :model do
|
||||
let(:options) { { user: Fabricate(:user), session_id: '1' } }
|
||||
|
||||
it 'calls create! and purge_old' do
|
||||
expect(described_class).to receive(:create!).with(options)
|
||||
expect(described_class).to receive(:create!).with(**options)
|
||||
expect(described_class).to receive(:purge_old)
|
||||
described_class.activate(options)
|
||||
described_class.activate(**options)
|
||||
end
|
||||
|
||||
it 'returns an instance of SessionActivation' do
|
||||
expect(described_class.activate(options)).to be_kind_of SessionActivation
|
||||
expect(described_class.activate(**options)).to be_kind_of SessionActivation
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -99,11 +99,12 @@ RSpec.describe Setting, type: :model do
|
||||
end
|
||||
|
||||
it 'does not query the database' do
|
||||
expect do |callback|
|
||||
ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
|
||||
described_class[key]
|
||||
end
|
||||
end.not_to yield_control
|
||||
callback = double
|
||||
allow(callback).to receive(:call)
|
||||
ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
|
||||
described_class[key]
|
||||
end
|
||||
expect(callback).not_to have_received(:call)
|
||||
end
|
||||
|
||||
it 'returns the cached value' do
|
||||
|
||||
@ -96,6 +96,20 @@ RSpec.describe Tag, type: :model do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.matches_name' do
|
||||
it 'returns tags for multibyte case-insensitive names' do
|
||||
upcase_string = 'abcABCabcABCやゆよ'
|
||||
downcase_string = 'abcabcabcabcやゆよ';
|
||||
|
||||
tag = Fabricate(:tag, name: downcase_string)
|
||||
expect(Tag.matches_name(upcase_string)).to eq [tag]
|
||||
end
|
||||
|
||||
it 'uses the LIKE operator' do
|
||||
expect(Tag.matches_name('100%abc').to_sql).to eq %q[SELECT "tags".* FROM "tags" WHERE LOWER("tags"."name") LIKE LOWER('100\\%abc%')]
|
||||
end
|
||||
end
|
||||
|
||||
describe '.matching_name' do
|
||||
it 'returns tags for multibyte case-insensitive names' do
|
||||
upcase_string = 'abcABCabcABCやゆよ'
|
||||
|
||||
@ -7,9 +7,9 @@ RSpec.describe TrendingTags do
|
||||
|
||||
describe '.update!' do
|
||||
let!(:at_time) { Time.now.utc }
|
||||
let!(:tag1) { Fabricate(:tag, name: 'Catstodon') }
|
||||
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon') }
|
||||
let!(:tag3) { Fabricate(:tag, name: 'OCs') }
|
||||
let!(:tag1) { Fabricate(:tag, name: 'Catstodon', trendable: true) }
|
||||
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon', trendable: true) }
|
||||
let!(:tag3) { Fabricate(:tag, name: 'OCs', trendable: true) }
|
||||
|
||||
before do
|
||||
allow(Redis.current).to receive(:pfcount) do |key|
|
||||
|
||||
@ -175,7 +175,7 @@ RSpec.describe User, type: :model do
|
||||
user = Fabricate(:user)
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
|
||||
expect { user.send_confirmation_instructions }.to have_enqueued_job(ActionMailer::DeliveryJob)
|
||||
expect { user.send_confirmation_instructions }.to have_enqueued_job(ActionMailer::MailDeliveryJob)
|
||||
end
|
||||
end
|
||||
|
||||
@ -206,7 +206,7 @@ RSpec.describe User, type: :model do
|
||||
|
||||
describe 'whitelist' do
|
||||
around(:each) do |example|
|
||||
old_whitelist = Rails.configuration.x.email_whitelist
|
||||
old_whitelist = Rails.configuration.x.email_domains_whitelist
|
||||
|
||||
Rails.configuration.x.email_domains_whitelist = 'mastodon.space'
|
||||
|
||||
|
||||
@ -1,16 +1,94 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Web::PushSubscription, type: :model do
|
||||
let(:alerts) { { mention: true, reblog: false, follow: true, follow_request: false, favourite: true } }
|
||||
let(:push_subscription) { Web::PushSubscription.new(data: { alerts: alerts }) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
let(:policy) { 'all' }
|
||||
|
||||
let(:data) do
|
||||
{
|
||||
policy: policy,
|
||||
|
||||
alerts: {
|
||||
mention: true,
|
||||
reblog: false,
|
||||
follow: true,
|
||||
follow_request: false,
|
||||
favourite: true,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
subject { described_class.new(data: data) }
|
||||
|
||||
describe '#pushable?' do
|
||||
it 'obeys alert settings' do
|
||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Mention'))).to eq true
|
||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Status'))).to eq false
|
||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Follow'))).to eq true
|
||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'FollowRequest'))).to eq false
|
||||
expect(push_subscription.send(:pushable?, Notification.new(activity_type: 'Favourite'))).to eq true
|
||||
let(:notification_type) { :mention }
|
||||
let(:notification) { Fabricate(:notification, account: account, type: notification_type) }
|
||||
|
||||
%i(mention reblog follow follow_request favourite).each do |type|
|
||||
context "when notification is a #{type}" do
|
||||
let(:notification_type) { type }
|
||||
|
||||
it "returns boolean corresonding to alert setting" do
|
||||
expect(subject.pushable?(notification)).to eq data[:alerts][type]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when policy is all' do
|
||||
let(:policy) { 'all' }
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.pushable?(notification)).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when policy is none' do
|
||||
let(:policy) { 'none' }
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject.pushable?(notification)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when policy is followed' do
|
||||
let(:policy) { 'followed' }
|
||||
|
||||
context 'and notification is from someone you follow' do
|
||||
before do
|
||||
account.follow!(notification.from_account)
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.pushable?(notification)).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'and notification is not from someone you follow' do
|
||||
it 'returns false' do
|
||||
expect(subject.pushable?(notification)).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when policy is follower' do
|
||||
let(:policy) { 'follower' }
|
||||
|
||||
context 'and notification is from someone who follows you' do
|
||||
before do
|
||||
notification.from_account.follow!(account)
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject.pushable?(notification)).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'and notification is not from someone who follows you' do
|
||||
it 'returns false' do
|
||||
expect(subject.pushable?(notification)).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -13,7 +13,7 @@ RSpec.describe AccountRelationshipsPresenter do
|
||||
allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map)
|
||||
end
|
||||
|
||||
let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, options) }
|
||||
let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, **options) }
|
||||
let(:current_account_id) { Fabricate(:account).id }
|
||||
let(:account_ids) { [Fabricate(:account).id] }
|
||||
let(:default_map) { { 1 => true } }
|
||||
|
||||
@ -6,7 +6,7 @@ describe "The catch all route" do
|
||||
get "/test"
|
||||
|
||||
expect(response.status).to eq 404
|
||||
expect(response.content_type).to eq "text/html"
|
||||
expect(response.media_type).to eq "text/html"
|
||||
end
|
||||
end
|
||||
|
||||
@ -15,7 +15,7 @@ describe "The catch all route" do
|
||||
get "/test.test"
|
||||
|
||||
expect(response.status).to eq 404
|
||||
expect(response.content_type).to eq "text/html"
|
||||
expect(response.media_type).to eq "text/html"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -6,7 +6,7 @@ describe "The host_meta route" do
|
||||
get host_meta_url
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq "application/xrd+xml"
|
||||
expect(response.media_type).to eq "application/xrd+xml"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,7 +25,7 @@ describe 'Link headers' do
|
||||
end
|
||||
|
||||
def link_header_with_type(type)
|
||||
response.headers['Link'].links.find do |link|
|
||||
LinkHeader.parse(response.headers['Link'].to_s).links.find do |link|
|
||||
link.attr_pairs.any? { |pair| pair == ['type', type] }
|
||||
end
|
||||
end
|
||||
|
||||
@ -8,7 +8,7 @@ describe 'The webfinger route' do
|
||||
get webfinger_url(resource: alice.to_webfinger_s)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
expect(response.media_type).to eq 'application/jrd+json'
|
||||
end
|
||||
end
|
||||
|
||||
@ -17,7 +17,7 @@ describe 'The webfinger route' do
|
||||
get webfinger_url(resource: alice.to_webfinger_s, format: :json)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
expect(response.media_type).to eq 'application/jrd+json'
|
||||
end
|
||||
|
||||
it 'returns a json response for json accept header' do
|
||||
@ -25,7 +25,7 @@ describe 'The webfinger route' do
|
||||
get webfinger_url(resource: alice.to_webfinger_s), headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to eq 'application/jrd+json'
|
||||
expect(response.media_type).to eq 'application/jrd+json'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -5,12 +5,14 @@ RSpec.describe AfterBlockService, type: :service do
|
||||
-> { described_class.new.call(account, target_account) }
|
||||
end
|
||||
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:target_account) { Fabricate(:account) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:target_account) { Fabricate(:account) }
|
||||
let(:status) { Fabricate(:status, account: target_account) }
|
||||
let(:other_status) { Fabricate(:status, account: target_account) }
|
||||
let(:other_account_status) { Fabricate(:status) }
|
||||
let(:other_account_reblog) { Fabricate(:status, reblog_of_id: other_status.id) }
|
||||
|
||||
describe 'home timeline' do
|
||||
let(:status) { Fabricate(:status, account: target_account) }
|
||||
let(:other_account_status) { Fabricate(:status) }
|
||||
let(:home_timeline_key) { FeedManager.instance.key(:home, account.id) }
|
||||
|
||||
before do
|
||||
@ -20,10 +22,30 @@ RSpec.describe AfterBlockService, type: :service do
|
||||
it "clears account's statuses" do
|
||||
FeedManager.instance.push_to_home(account, status)
|
||||
FeedManager.instance.push_to_home(account, other_account_status)
|
||||
FeedManager.instance.push_to_home(account, other_account_reblog)
|
||||
|
||||
is_expected.to change {
|
||||
Redis.current.zrange(home_timeline_key, 0, -1)
|
||||
}.from([status.id.to_s, other_account_status.id.to_s]).to([other_account_status.id.to_s])
|
||||
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lists' do
|
||||
let(:list) { Fabricate(:list, account: account) }
|
||||
let(:list_timeline_key) { FeedManager.instance.key(:list, list.id) }
|
||||
|
||||
before do
|
||||
Redis.current.del(list_timeline_key)
|
||||
end
|
||||
|
||||
it "clears account's statuses" do
|
||||
FeedManager.instance.push_to_list(list, status)
|
||||
FeedManager.instance.push_to_list(list, other_account_status)
|
||||
FeedManager.instance.push_to_list(list, other_account_reblog)
|
||||
|
||||
is_expected.to change {
|
||||
Redis.current.zrange(list_timeline_key, 0, -1)
|
||||
}.from([status.id.to_s, other_account_status.id.to_s, other_account_reblog.id.to_s]).to([other_account_status.id.to_s])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -22,24 +22,6 @@ RSpec.describe AuthorizeFollowService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote OStatus' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
|
||||
|
||||
before do
|
||||
FollowRequest.create(account: bob, target_account: sender)
|
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(bob, sender)
|
||||
end
|
||||
|
||||
it 'removes follow request' do
|
||||
expect(bob.requested?(sender)).to be false
|
||||
end
|
||||
|
||||
it 'creates follow relation' do
|
||||
expect(bob.following?(sender)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote ActivityPub' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox')).account }
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
|
||||
subject { BatchedRemoveStatusService.new }
|
||||
|
||||
let!(:alice) { Fabricate(:account) }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
||||
let!(:jeff) { Fabricate(:user).account }
|
||||
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
|
||||
|
||||
@ -17,19 +17,6 @@ RSpec.describe BlockService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote OStatus' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
|
||||
|
||||
before do
|
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'creates a blocking relation' do
|
||||
expect(sender.blocking?(bob)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote ActivityPub' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
|
||||
|
||||
|
||||
@ -1,42 +1,4 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BootstrapTimelineService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#call' do
|
||||
let(:source_account) { Fabricate(:account) }
|
||||
|
||||
context 'when setting is empty' do
|
||||
let!(:admin) { Fabricate(:user, admin: true) }
|
||||
|
||||
before do
|
||||
Setting.bootstrap_timeline_accounts = nil
|
||||
subject.call(source_account)
|
||||
end
|
||||
|
||||
it 'follows admin accounts from account' do
|
||||
expect(source_account.following?(admin.account)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when setting is set' do
|
||||
let!(:alice) { Fabricate(:account, username: 'alice') }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob') }
|
||||
let!(:eve) { Fabricate(:account, username: 'eve', suspended: true) }
|
||||
|
||||
before do
|
||||
Setting.bootstrap_timeline_accounts = 'alice, @bob, eve, unknown'
|
||||
subject.call(source_account)
|
||||
end
|
||||
|
||||
it 'follows found accounts from account' do
|
||||
expect(source_account.following?(alice)).to be true
|
||||
expect(source_account.following?(bob)).to be true
|
||||
end
|
||||
|
||||
it 'does not follow suspended account' do
|
||||
expect(source_account.following?(eve)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -18,20 +18,6 @@ RSpec.describe FavouriteService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote OStatus' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
|
||||
let(:status) { Fabricate(:status, account: bob, uri: 'tag:example.com:blahblah') }
|
||||
|
||||
before do
|
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(sender, status)
|
||||
end
|
||||
|
||||
it 'creates a favourite' do
|
||||
expect(status.favourites.first).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote ActivityPub' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, protocol: :activitypub, username: 'bob', domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
|
||||
let(:status) { Fabricate(:status, account: bob) }
|
||||
|
||||
@ -77,6 +77,14 @@ RSpec.describe FetchLinkCardService, type: :service do
|
||||
expect(a_request(:get, 'http://example.com/test-')).to have_been_made.at_least_once
|
||||
end
|
||||
end
|
||||
|
||||
context do
|
||||
let(:status) { Fabricate(:status, text: 'testhttp://example.com/sjis') }
|
||||
|
||||
it 'does not fetch URLs with not isolated from their surroundings' do
|
||||
expect(a_request(:get, 'http://example.com/sjis')).to_not have_been_made
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'in a remote status' do
|
||||
|
||||
@ -31,56 +31,4 @@ RSpec.describe FetchRemoteStatusService, type: :service do
|
||||
expect(status.text).to eq 'Lorem ipsum'
|
||||
end
|
||||
end
|
||||
|
||||
context 'protocol is :ostatus' do
|
||||
subject { described_class.new }
|
||||
|
||||
before do
|
||||
Fabricate(:account, username: 'tracer', domain: 'real.domain', remote_url: 'https://real.domain/users/tracer')
|
||||
end
|
||||
|
||||
it 'does not create status with author at different domain' do
|
||||
status_body = <<-XML.squish
|
||||
<?xml version="1.0"?>
|
||||
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
|
||||
<id>tag:real.domain,2017-04-27:objectId=4487555:objectType=Status</id>
|
||||
<published>2017-04-27T13:49:25Z</published>
|
||||
<updated>2017-04-27T13:49:25Z</updated>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<author>
|
||||
<id>https://real.domain/users/tracer</id>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<uri>https://real.domain/users/tracer</uri>
|
||||
<name>tracer</name>
|
||||
</author>
|
||||
<content type="html">Overwatch rocks</content>
|
||||
</entry>
|
||||
XML
|
||||
|
||||
expect(subject.call('https://fake.domain/foo', status_body)).to be_nil
|
||||
end
|
||||
|
||||
it 'does not create status with wrong id when id uses http format' do
|
||||
status_body = <<-XML.squish
|
||||
<?xml version="1.0"?>
|
||||
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:mastodon="http://mastodon.social/schema/1.0">
|
||||
<id>https://other-real.domain/statuses/123</id>
|
||||
<published>2017-04-27T13:49:25Z</published>
|
||||
<updated>2017-04-27T13:49:25Z</updated>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<author>
|
||||
<id>https://real.domain/users/tracer</id>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<uri>https://real.domain/users/tracer</uri>
|
||||
<name>tracer</name>
|
||||
</author>
|
||||
<content type="html">Overwatch rocks</content>
|
||||
</entry>
|
||||
XML
|
||||
|
||||
expect(subject.call('https://real.domain/statuses/456', status_body)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,7 +10,7 @@ RSpec.describe FollowService, type: :service do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
subject.call(sender, bob.acct)
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'creates a follow request with reblogs' do
|
||||
@ -22,7 +22,7 @@ RSpec.describe FollowService, type: :service do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
subject.call(sender, bob.acct, reblogs: false)
|
||||
subject.call(sender, bob, reblogs: false)
|
||||
end
|
||||
|
||||
it 'creates a follow request without reblogs' do
|
||||
@ -35,7 +35,7 @@ RSpec.describe FollowService, type: :service do
|
||||
|
||||
before do
|
||||
sender.touch(:silenced_at)
|
||||
subject.call(sender, bob.acct)
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'creates a follow request with reblogs' do
|
||||
@ -48,7 +48,7 @@ RSpec.describe FollowService, type: :service do
|
||||
|
||||
before do
|
||||
bob.mute!(sender)
|
||||
subject.call(sender, bob.acct)
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'creates a following relation with reblogs' do
|
||||
@ -61,7 +61,7 @@ RSpec.describe FollowService, type: :service do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
subject.call(sender, bob.acct)
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'creates a following relation with reblogs' do
|
||||
@ -74,7 +74,7 @@ RSpec.describe FollowService, type: :service do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
|
||||
before do
|
||||
subject.call(sender, bob.acct, reblogs: false)
|
||||
subject.call(sender, bob, reblogs: false)
|
||||
end
|
||||
|
||||
it 'creates a following relation without reblogs' do
|
||||
@ -88,7 +88,7 @@ RSpec.describe FollowService, type: :service do
|
||||
|
||||
before do
|
||||
sender.follow!(bob)
|
||||
subject.call(sender, bob.acct)
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'keeps a following relation' do
|
||||
@ -101,7 +101,7 @@ RSpec.describe FollowService, type: :service do
|
||||
|
||||
before do
|
||||
sender.follow!(bob, reblogs: true)
|
||||
subject.call(sender, bob.acct, reblogs: false)
|
||||
subject.call(sender, bob, reblogs: false)
|
||||
end
|
||||
|
||||
it 'disables reblogs' do
|
||||
@ -114,7 +114,7 @@ RSpec.describe FollowService, type: :service do
|
||||
|
||||
before do
|
||||
sender.follow!(bob, reblogs: false)
|
||||
subject.call(sender, bob.acct, reblogs: true)
|
||||
subject.call(sender, bob, reblogs: true)
|
||||
end
|
||||
|
||||
it 'disables reblogs' do
|
||||
@ -128,7 +128,7 @@ RSpec.describe FollowService, type: :service do
|
||||
|
||||
before do
|
||||
stub_request(:post, "http://example.com/inbox").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(sender, bob.acct)
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'creates follow request' do
|
||||
|
||||
@ -7,37 +7,6 @@ RSpec.describe ProcessMentionsService, type: :service do
|
||||
|
||||
subject { ProcessMentionsService.new }
|
||||
|
||||
context 'OStatus with public toot' do
|
||||
let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
|
||||
|
||||
before do
|
||||
stub_request(:post, remote_user.salmon_url)
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'does not create a mention' do
|
||||
expect(remote_user.mentions.where(status: status).count).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context 'OStatus with private toot' do
|
||||
let(:visibility) { :private }
|
||||
let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
|
||||
|
||||
before do
|
||||
stub_request(:post, remote_user.salmon_url)
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'does not create a mention' do
|
||||
expect(remote_user.mentions.where(status: status).count).to eq 0
|
||||
end
|
||||
|
||||
it 'does not post to remote user\'s Salmon end point' do
|
||||
expect(a_request(:post, remote_user.salmon_url)).to_not have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
context 'ActivityPub' do
|
||||
context do
|
||||
let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
|
||||
@ -32,22 +32,6 @@ RSpec.describe ReblogService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
context 'OStatus' do
|
||||
let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com') }
|
||||
let(:status) { Fabricate(:status, account: bob, uri: 'tag:example.com;something:something') }
|
||||
|
||||
subject { ReblogService.new }
|
||||
|
||||
before do
|
||||
stub_request(:post, 'http://salmon.example.com')
|
||||
subject.call(alice, status)
|
||||
end
|
||||
|
||||
it 'creates a reblog' do
|
||||
expect(status.reblogs.count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'ActivityPub' do
|
||||
let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
let(:status) { Fabricate(:status, account: bob) }
|
||||
|
||||
@ -22,24 +22,6 @@ RSpec.describe RejectFollowService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote OStatus' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
|
||||
|
||||
before do
|
||||
FollowRequest.create(account: bob, target_account: sender)
|
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(bob, sender)
|
||||
end
|
||||
|
||||
it 'removes follow request' do
|
||||
expect(bob.requested?(sender)).to be false
|
||||
end
|
||||
|
||||
it 'does not create follow relation' do
|
||||
expect(bob.following?(sender)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote ActivityPub' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox')).account }
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ RSpec.describe RemoveStatusService, type: :service do
|
||||
subject { RemoveStatusService.new }
|
||||
|
||||
let!(:alice) { Fabricate(:account, user: Fabricate(:user)) }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
|
||||
let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
|
||||
let!(:jeff) { Fabricate(:account) }
|
||||
let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
|
||||
|
||||
@ -13,6 +13,47 @@ RSpec.describe ResolveAccountService, type: :service do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:hoge@example.com').to_return(status: 410)
|
||||
end
|
||||
|
||||
context 'using skip_webfinger' do
|
||||
context 'when account is known' do
|
||||
let!(:remote_account) { Fabricate(:account, username: 'foo', domain: 'ap.example.com', protocol: 'activitypub') }
|
||||
|
||||
context 'when domain is banned' do
|
||||
let!(:domain_block) { Fabricate(:domain_block, domain: 'ap.example.com', severity: :suspend) }
|
||||
|
||||
it 'does not return an account' do
|
||||
expect(subject.call('foo@ap.example.com', skip_webfinger: true)).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make a webfinger query' do
|
||||
subject.call('foo@ap.example.com', skip_webfinger: true)
|
||||
expect(a_request(:get, 'https://ap.example.com/.well-known/webfinger?resource=acct:foo@ap.example.com')).to_not have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
context 'when domain is not banned' do
|
||||
it 'returns the expected account' do
|
||||
expect(subject.call('foo@ap.example.com', skip_webfinger: true)).to eq remote_account
|
||||
end
|
||||
|
||||
it 'does not make a webfinger query' do
|
||||
subject.call('foo@ap.example.com', skip_webfinger: true)
|
||||
expect(a_request(:get, 'https://ap.example.com/.well-known/webfinger?resource=acct:foo@ap.example.com')).to_not have_been_made
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not known' do
|
||||
it 'does not return an account' do
|
||||
expect(subject.call('foo@ap.example.com', skip_webfinger: true)).to be_nil
|
||||
end
|
||||
|
||||
it 'does not make a webfinger query' do
|
||||
subject.call('foo@ap.example.com', skip_webfinger: true)
|
||||
expect(a_request(:get, 'https://ap.example.com/.well-known/webfinger?resource=acct:foo@ap.example.com')).to_not have_been_made
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is an LRDD endpoint but no resolvable account' do
|
||||
before do
|
||||
stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
|
||||
|
||||
@ -18,20 +18,6 @@ RSpec.describe UnblockService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote OStatus' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
|
||||
|
||||
before do
|
||||
sender.block!(bob)
|
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'destroys the blocking relation' do
|
||||
expect(sender.blocking?(bob)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote ActivityPub' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
|
||||
|
||||
|
||||
@ -18,20 +18,6 @@ RSpec.describe UnfollowService, type: :service do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote OStatus' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
|
||||
|
||||
before do
|
||||
sender.follow!(bob)
|
||||
stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
subject.call(sender, bob)
|
||||
end
|
||||
|
||||
it 'destroys the following relation' do
|
||||
expect(sender.following?(bob)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote ActivityPub' do
|
||||
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
|
||||
|
||||
|
||||
@ -9,23 +9,36 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do
|
||||
|
||||
before do
|
||||
allow(user).to receive(:valid_invitation?) { false }
|
||||
allow_any_instance_of(described_class).to receive(:blocked_email?) { blocked_email }
|
||||
described_class.new.validate(user)
|
||||
allow_any_instance_of(described_class).to receive(:blocked_email_provider?) { blocked_email }
|
||||
end
|
||||
|
||||
context 'blocked_email?' do
|
||||
subject { described_class.new.validate(user); errors }
|
||||
|
||||
context 'when e-mail provider is blocked' do
|
||||
let(:blocked_email) { true }
|
||||
|
||||
it 'calls errors.add' do
|
||||
expect(errors).to have_received(:add).with(:email, I18n.t('users.blocked_email_provider'))
|
||||
it 'adds error' do
|
||||
expect(subject).to have_received(:add).with(:email, :blocked)
|
||||
end
|
||||
end
|
||||
|
||||
context '!blocked_email?' do
|
||||
context 'when e-mail provider is not blocked' do
|
||||
let(:blocked_email) { false }
|
||||
|
||||
it 'not calls errors.add' do
|
||||
expect(errors).not_to have_received(:add).with(:email, I18n.t('users.blocked_email_provider'))
|
||||
it 'does not add errors' do
|
||||
expect(subject).not_to have_received(:add).with(:email, :blocked)
|
||||
end
|
||||
|
||||
context 'when canonical e-mail is blocked' do
|
||||
let(:other_user) { Fabricate(:user, email: 'i.n.f.o@mail.com') }
|
||||
|
||||
before do
|
||||
other_user.account.suspend!
|
||||
end
|
||||
|
||||
it 'adds error' do
|
||||
expect(subject).to have_received(:add).with(:email, :taken)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -6,6 +6,24 @@ describe EmailMxValidator do
|
||||
describe '#validate' do
|
||||
let(:user) { double(email: 'foo@example.com', errors: double(add: nil)) }
|
||||
|
||||
it 'does not add errors if there are no DNS records for an e-mail domain that is explicitly allowed' do
|
||||
old_whitelist = Rails.configuration.x.email_domains_whitelist
|
||||
Rails.configuration.x.email_domains_whitelist = 'example.com'
|
||||
|
||||
resolver = double
|
||||
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::MX).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
||||
allow(resolver).to receive(:timeouts=).and_return(nil)
|
||||
allow(Resolv::DNS).to receive(:open).and_yield(resolver)
|
||||
|
||||
subject.validate(user)
|
||||
expect(user.errors).to_not have_received(:add)
|
||||
|
||||
Rails.configuration.x.email_domains_whitelist = old_whitelist
|
||||
end
|
||||
|
||||
it 'adds an error if there are no DNS records for the e-mail domain' do
|
||||
resolver = double
|
||||
|
||||
|
||||
33
spec/validators/note_length_validator_spec.rb
Normal file
33
spec/validators/note_length_validator_spec.rb
Normal file
@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe NoteLengthValidator do
|
||||
subject { NoteLengthValidator.new(attributes: { note: true }, maximum: 500) }
|
||||
|
||||
describe '#validate' do
|
||||
it 'adds an error when text is over 500 characters' do
|
||||
text = 'a' * 520
|
||||
account = double(note: text, errors: double(add: nil))
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'counts URLs as 23 characters flat' do
|
||||
text = ('a' * 476) + " http://#{'b' * 30}.com/example"
|
||||
account = double(note: text, errors: double(add: nil))
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
it 'does not count non-autolinkable URLs as 23 characters flat' do
|
||||
text = ('a' * 476) + "http://#{'b' * 30}.com/example"
|
||||
account = double(note: text, errors: double(add: nil))
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -42,6 +42,14 @@ describe StatusLengthValidator do
|
||||
expect(status.errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
it 'does not count non-autolinkable URLs as 23 characters flat' do
|
||||
text = ('a' * 476) + "http://#{'b' * 30}.com/example"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'counts only the front part of remote usernames' do
|
||||
text = ('a' * 475) + " @alice@#{'b' * 30}.com"
|
||||
status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
|
||||
|
||||
@ -13,7 +13,7 @@ RSpec.describe UnreservedUsernameValidator, type: :validator do
|
||||
let(:account) { double(username: username, errors: errors) }
|
||||
let(:errors ) { double(add: nil) }
|
||||
|
||||
context '@username.nil?' do
|
||||
context '@username.blank?' do
|
||||
let(:username) { nil }
|
||||
|
||||
it 'not calls errors.add' do
|
||||
@ -21,14 +21,14 @@ RSpec.describe UnreservedUsernameValidator, type: :validator do
|
||||
end
|
||||
end
|
||||
|
||||
context '!@username.nil?' do
|
||||
let(:username) { '' }
|
||||
context '!@username.blank?' do
|
||||
let(:username) { 'f' }
|
||||
|
||||
context 'reserved_username?' do
|
||||
let(:reserved_username) { true }
|
||||
|
||||
it 'calls erros.add' do
|
||||
expect(errors).to have_received(:add).with(:username, I18n.t('accounts.reserved_username'))
|
||||
expect(errors).to have_received(:add).with(:username, :reserved)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UrlValidator, type: :validator do
|
||||
RSpec.describe URLValidator, type: :validator do
|
||||
describe '#validate_each' do
|
||||
before do
|
||||
allow(validator).to receive(:compliant?).with(value) { compliant }
|
||||
|
||||
48
spec/workers/web/push_notification_worker_spec.rb
Normal file
48
spec/workers/web/push_notification_worker_spec.rb
Normal file
@ -0,0 +1,48 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Web::PushNotificationWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:p256dh) { 'BN4GvZtEZiZuqFxSKVZfSfluwKBD7UxHNBmWkfiZfCtgDE8Bwh-_MtLXbBxTBAWH9r7IPKL0lhdcaqtL1dfxU5E=' }
|
||||
let(:auth) { 'Q2BoAjC09xH3ywDLNJr-dA==' }
|
||||
let(:endpoint) { 'https://updates.push.services.mozilla.com/push/v1/subscription-id' }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:notification) { Fabricate(:notification) }
|
||||
let(:subscription) { Fabricate(:web_push_subscription, user_id: user.id, key_p256dh: p256dh, key_auth: auth, endpoint: endpoint, data: { alerts: { notification.type => true } }) }
|
||||
let(:vapid_public_key) { 'BB37UCyc8LLX4PNQSe-04vSFvpUWGrENubUaslVFM_l5TxcGVMY0C3RXPeUJAQHKYlcOM2P4vTYmkoo0VZGZTM4=' }
|
||||
let(:vapid_private_key) { 'OPrw1Sum3gRoL4-DXfSCC266r-qfFSRZrnj8MgIhRHg=' }
|
||||
let(:vapid_key) { Webpush::VapidKey.from_keys(vapid_public_key, vapid_private_key) }
|
||||
let(:contact_email) { 'sender@example.com' }
|
||||
let(:ciphertext) { "+\xB8\xDBT}\x13\xB6\xDD.\xF9\xB0\xA7\xC8\xD2\x80\xFD\x99#\xF7\xAC\x83\xA4\xDB,\x1F\xB5\xB9w\x85>\xF7\xADr" }
|
||||
let(:salt) { "X\x97\x953\xE4X\xF8_w\xE7T\x95\xC51q\xFE" }
|
||||
let(:server_public_key) { "\x04\b-RK9w\xDD$\x16lFz\xF9=\xB4~\xC6\x12k\xF3\xF40t\xA9\xC1\fR\xC3\x81\x80\xAC\f\x7F\xE4\xCC\x8E\xC2\x88 n\x8BB\xF1\x9C\x14\a\xFA\x8D\xC9\x80\xA1\xDDyU\\&c\x01\x88#\x118Ua" }
|
||||
let(:shared_secret) { "\t\xA7&\x85\t\xC5m\b\xA8\xA7\xF8B{1\xADk\xE1y'm\xEDE\xEC\xDD\xEDj\xB3$s\xA9\xDA\xF0" }
|
||||
let(:payload) { { ciphertext: ciphertext, salt: salt, server_public_key: server_public_key, shared_secret: shared_secret } }
|
||||
|
||||
describe 'perform' do
|
||||
before do
|
||||
allow_any_instance_of(subscription.class).to receive(:contact_email).and_return(contact_email)
|
||||
allow_any_instance_of(subscription.class).to receive(:vapid_key).and_return(vapid_key)
|
||||
allow(Webpush::Encryption).to receive(:encrypt).and_return(payload)
|
||||
allow(JWT).to receive(:encode).and_return('jwt.encoded.payload')
|
||||
|
||||
stub_request(:post, endpoint).to_return(status: 201, body: '')
|
||||
|
||||
subject.perform(subscription.id, notification.id)
|
||||
end
|
||||
|
||||
it 'calls the relevant service with the correct headers' do
|
||||
expect(a_request(:post, endpoint).with(headers: {
|
||||
'Content-Encoding' => 'aesgcm',
|
||||
'Content-Type' => 'application/octet-stream',
|
||||
'Crypto-Key' => 'dh=BAgtUks5d90kFmxGevk9tH7GEmvz9DB0qcEMUsOBgKwMf-TMjsKIIG6LQvGcFAf6jcmAod15VVwmYwGIIxE4VWE;p256ecdsa=' + vapid_public_key.delete('='),
|
||||
'Encryption' => 'salt=WJeVM-RY-F9351SVxTFx_g',
|
||||
'Ttl' => '172800',
|
||||
'Urgency' => 'normal',
|
||||
'Authorization' => 'WebPush jwt.encoded.payload',
|
||||
}, body: "+\xB8\xDBT}\u0013\xB6\xDD.\xF9\xB0\xA7\xC8Ҁ\xFD\x99#\xF7\xAC\x83\xA4\xDB,\u001F\xB5\xB9w\x85>\xF7\xADr")).to have_been_made
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user