Merge commit '9e245d147bcb2c72cc552ff8c276a1c34e2f686d' into glitch-soc/merge-upstream

Conflicts:
- `app/views/settings/profiles/show.html.haml`:
  Upstream redesigned the settings page, where glitch-soc had changes because of
  the ability to set some custom limits.
  Went with upstream's design while keeping our custom limits.
- `yarn.lock`:
  Upstream updated dependencies textually close to a glitch-soc-only dependency.
  Updated the dependnencies as well.
This commit is contained in:
Claire
2023-06-18 13:41:33 +02:00
214 changed files with 3232 additions and 3494 deletions

View File

@ -3,17 +3,17 @@
require 'rails_helper'
RSpec.describe ActivityPub::FollowersSynchronizationsController do
let!(:account) { Fabricate(:account) }
let!(:follower_1) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/a') }
let!(:follower_2) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/b') }
let!(:follower_3) { Fabricate(:account, domain: 'foo.com', uri: 'https://foo.com/users/a') }
let!(:follower_4) { Fabricate(:account, username: 'instance-actor', domain: 'example.com', uri: 'https://example.com') }
let!(:account) { Fabricate(:account) }
let!(:follower_example_com_user_a) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/a') }
let!(:follower_example_com_user_b) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/b') }
let!(:follower_foo_com_user_a) { Fabricate(:account, domain: 'foo.com', uri: 'https://foo.com/users/a') }
let!(:follower_example_com_instance_actor) { Fabricate(:account, username: 'instance-actor', domain: 'example.com', uri: 'https://example.com') }
before do
follower_1.follow!(account)
follower_2.follow!(account)
follower_3.follow!(account)
follower_4.follow!(account)
follower_example_com_user_a.follow!(account)
follower_example_com_user_b.follow!(account)
follower_foo_com_user_a.follow!(account)
follower_example_com_instance_actor.follow!(account)
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
end
@ -47,7 +47,11 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController do
it 'returns orderedItems with followers from example.com' do
expect(body[:orderedItems]).to be_an Array
expect(body[:orderedItems]).to contain_exactly(follower_4.uri, follower_1.uri, follower_2.uri)
expect(body[:orderedItems]).to contain_exactly(
follower_example_com_instance_actor.uri,
follower_example_com_user_a.uri,
follower_example_com_user_b.uri
)
end
it 'returns private Cache-Control header' do

View File

@ -7,9 +7,9 @@ RSpec.describe Admin::InstancesController do
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
let!(:account) { Fabricate(:account, domain: 'popular') }
let!(:account2) { Fabricate(:account, domain: 'popular') }
let!(:account3) { Fabricate(:account, domain: 'less.popular') }
let!(:account_popular_main) { Fabricate(:account, domain: 'popular') }
let!(:account_popular_other) { Fabricate(:account, domain: 'popular') }
let!(:account_less_popular) { Fabricate(:account, domain: 'less.popular') }
before do
sign_in current_user, scope: :user

View File

@ -13,14 +13,6 @@ RSpec.describe Api::V1::AccountsController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'POST #create' do
let(:app) { Fabricate(:application) }
let(:token) { Doorkeeper::AccessToken.find_or_create_for(application: app, resource_owner: nil, scopes: 'read write', use_refresh_token: false) }

View File

@ -15,22 +15,6 @@ RSpec.describe Api::V1::Admin::AccountActionsController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'POST #create' do
context 'with type of disable' do
before do

View File

@ -15,22 +15,6 @@ RSpec.describe Api::V1::Admin::AccountsController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
let!(:remote_account) { Fabricate(:account, domain: 'example.org') }
let!(:other_remote_account) { Fabricate(:account, domain: 'foo.bar') }

View File

@ -16,22 +16,6 @@ describe Api::V1::Admin::Trends::Links::PreviewCardProvidersController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
it 'returns http success' do
get :index, params: { account_id: account.id, limit: 2 }

View File

@ -16,22 +16,6 @@ describe Api::V1::Admin::Trends::LinksController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
it 'returns http success' do
get :index, params: { account_id: account.id, limit: 2 }

View File

@ -16,22 +16,6 @@ describe Api::V1::Admin::Trends::StatusesController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
it 'returns http success' do
get :index, params: { account_id: account.id, limit: 2 }

View File

@ -16,22 +16,6 @@ describe Api::V1::Admin::Trends::TagsController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
it 'returns http success' do
get :index, params: { account_id: account.id, limit: 2 }

View File

@ -1,45 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Apps::CredentialsController do
render_views
let(:token) { Fabricate(:accessible_access_token, scopes: 'read', application: Fabricate(:application)) }
context 'with an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'GET #show' do
before do
get :show
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'does not contain client credentials' do
json = body_as_json
expect(json).to_not have_key(:client_secret)
expect(json).to_not have_key(:client_id)
end
end
end
context 'without an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token).and_return(nil)
end
describe 'GET #show' do
it 'returns http unauthorized' do
get :show
expect(response).to have_http_status(401)
end
end
end
end

View File

@ -1,88 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::AppsController 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: app_params
end
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
context 'with an unsupported scope' do
let(:scopes) { 'hoge' }
it 'returns http unprocessable entity' do
expect(response).to have_http_status(422)
end
end
context 'with many duplicate scopes' do
let(:scopes) { (%w(read) * 40).join(' ') }
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

View File

@ -35,5 +35,23 @@ RSpec.describe Api::V1::ConversationsController do
json = body_as_json
expect(json.size).to eq 1
end
context 'with since_id' do
context 'when requesting old posts' do
it 'returns conversations' do
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
json = body_as_json
expect(json.size).to eq 1
end
end
context 'when requesting posts in the future' do
it 'returns no conversation' do
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.from_now, with_random: false) }
json = body_as_json
expect(json.size).to eq 0
end
end
end
end
end

View File

@ -1,77 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::DomainBlocksController do
render_views
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
before do
user.account.block_domain!('example.com')
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #show' do
let(:scopes) { 'read:blocks' }
before do
get :show, params: { limit: 1 }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns blocked domains' do
expect(body_as_json.first).to eq 'example.com'
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
end
describe 'POST #create' do
let(:scopes) { 'write:blocks' }
before do
post :create, params: { domain: 'example.org' }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'creates a domain block' do
expect(user.account.domain_blocking?('example.org')).to be true
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
end
describe 'DELETE #destroy' do
let(:scopes) { 'write:blocks' }
before do
delete :destroy, params: { domain: 'example.com' }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'deletes a domain block' do
expect(user.account.domain_blocking?('example.com')).to be false
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
end
end

View File

@ -1,72 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FollowRequestsController do
render_views
let(:user) { Fabricate(:user, account_attributes: { locked: true }) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:follower) { Fabricate(:account) }
before do
FollowService.new.call(follower, user.account)
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'GET #index' do
let(:scopes) { 'read:follows' }
before do
get :index, params: { limit: 1 }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #authorize' do
let(:scopes) { 'write:follows' }
before do
post :authorize, params: { id: follower.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'allows follower to follow' do
expect(follower.following?(user.account)).to be true
end
it 'returns JSON with followed_by=true' do
json = body_as_json
expect(json[:followed_by]).to be true
end
end
describe 'POST #reject' do
let(:scopes) { 'write:follows' }
before do
post :reject, params: { id: follower.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'removes follow request' do
expect(FollowRequest.where(target_account: user.account, account: follower).count).to eq 0
end
it 'returns JSON with followed_by=false' do
json = body_as_json
expect(json[:followed_by]).to be false
end
end
end

View File

@ -1,80 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::ListsController do
render_views
let!(:user) { Fabricate(:user) }
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let!(:list) { Fabricate(:list, account: user.account) }
before { allow(controller).to receive(:doorkeeper_token) { token } }
describe 'GET #index' do
let(:scopes) { 'read:lists' }
it 'returns http success' do
get :index
expect(response).to have_http_status(200)
end
end
describe 'GET #show' do
let(:scopes) { 'read:lists' }
it 'returns http success' do
get :show, params: { id: list.id }
expect(response).to have_http_status(200)
end
end
describe 'POST #create' do
let(:scopes) { 'write:lists' }
before do
post :create, params: { title: 'Foo bar' }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'creates list' do
expect(List.where(account: user.account).count).to eq 2
expect(List.last.title).to eq 'Foo bar'
end
end
describe 'PUT #update' do
let(:scopes) { 'write:lists' }
before do
put :update, params: { id: list.id, title: 'Updated title' }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'updates the list' do
expect(list.reload.title).to eq 'Updated title'
end
end
describe 'DELETE #destroy' do
let(:scopes) { 'write:lists' }
before do
delete :destroy, params: { id: list.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'deletes the list' do
expect(List.find_by(id: list.id)).to be_nil
end
end
end

View File

@ -15,22 +15,6 @@ RSpec.describe Api::V2::Admin::AccountsController do
allow(controller).to receive(:doorkeeper_token) { token }
end
shared_examples 'forbidden for wrong scope' do |wrong_scope|
let(:scopes) { wrong_scope }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
shared_examples 'forbidden for wrong role' do |wrong_role|
let(:role) { UserRole.find_by(name: wrong_role) }
it 'returns http forbidden' do
expect(response).to have_http_status(403)
end
end
describe 'GET #index' do
let!(:remote_account) { Fabricate(:account, domain: 'example.org') }
let!(:other_remote_account) { Fabricate(:account, domain: 'foo.bar') }

View File

@ -5,13 +5,13 @@ require 'rails_helper'
describe FollowerAccountsController do
render_views
let(:alice) { Fabricate(:account) }
let(:follower0) { Fabricate(:account) }
let(:follower1) { Fabricate(:account) }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:follower_bob) { Fabricate(:account, username: 'bob') }
let(:follower_chris) { Fabricate(:account, username: 'curt') }
describe 'GET #index' do
let!(:follow0) { follower0.follow!(alice) }
let!(:follow1) { follower1.follow!(alice) }
let!(:follow_from_bob) { follower_bob.follow!(alice) }
let!(:follow_from_chris) { follower_chris.follow!(alice) }
context 'when format is html' do
subject(:response) { get :index, params: { account_username: alice.username, format: :html } }

View File

@ -5,13 +5,13 @@ require 'rails_helper'
describe FollowingAccountsController do
render_views
let(:alice) { Fabricate(:account) }
let(:followee0) { Fabricate(:account) }
let(:followee1) { Fabricate(:account) }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:followee_bob) { Fabricate(:account, username: 'bob') }
let(:followee_chris) { Fabricate(:account, username: 'chris') }
describe 'GET #index' do
let!(:follow0) { alice.follow!(followee0) }
let!(:follow1) { alice.follow!(followee1) }
let!(:follow_of_bob) { alice.follow!(followee_bob) }
let!(:follow_of_chris) { alice.follow!(followee_chris) }
context 'when format is html' do
subject(:response) { get :index, params: { account_username: alice.username, format: :html } }