mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 00:08:46 +00:00
Merge commit 'dbb20f76a781defe35d077529c8269d712c1fbd2' into glitch-soc/merge-upstream
Conflicts: - `tsconfig.json`: glitch-soc had extra paths under `app/javascript/flavours`, but upstream added `app/javascript` as a whole, so updated to upstream's.
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Oauth::AuthorizationsController do
|
||||
RSpec.describe OAuth::AuthorizationsController do
|
||||
render_views
|
||||
|
||||
let(:app) { Doorkeeper::Application.create!(name: 'test', redirect_uri: 'http://localhost/', scopes: 'read') }
|
||||
|
||||
describe 'GET #new' do
|
||||
@@ -24,6 +26,8 @@ RSpec.describe Oauth::AuthorizationsController do
|
||||
.to have_http_status(200)
|
||||
expect(response.headers['Cache-Control'])
|
||||
.to include('private, no-store')
|
||||
expect(response.parsed_body.at('body.modal-layout'))
|
||||
.to be_present
|
||||
expect(controller.stored_location_for(:user))
|
||||
.to eq authorize_path_for(app)
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Oauth::AuthorizedApplicationsController do
|
||||
RSpec.describe OAuth::AuthorizedApplicationsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
@@ -21,6 +21,8 @@ RSpec.describe Oauth::AuthorizedApplicationsController do
|
||||
.to have_http_status(200)
|
||||
expect(response.headers['Cache-Control'])
|
||||
.to include('private, no-store')
|
||||
expect(response.parsed_body.at('body.admin'))
|
||||
.to be_present
|
||||
expect(controller.stored_location_for(:user))
|
||||
.to eq '/oauth/authorized_applications'
|
||||
end
|
||||
|
||||
7
spec/fabricators/instance_moderation_note_fabricator.rb
Normal file
7
spec/fabricators/instance_moderation_note_fabricator.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:instance_moderation_note) do
|
||||
domain { sequence(:domain) { |i| "#{i}#{Faker::Internet.domain_name}" } }
|
||||
account { Fabricate.build(:account) }
|
||||
content { Faker::Lorem.sentence }
|
||||
end
|
||||
42
spec/models/doorkeeper/access_grant_spec.rb
Normal file
42
spec/models/doorkeeper/access_grant_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Doorkeeper::AccessGrant do
|
||||
describe 'Validations' do
|
||||
subject { Fabricate :access_grant }
|
||||
|
||||
it { is_expected.to validate_presence_of(:application_id) }
|
||||
it { is_expected.to validate_presence_of(:expires_in) }
|
||||
it { is_expected.to validate_presence_of(:redirect_uri) }
|
||||
it { is_expected.to validate_presence_of(:token) }
|
||||
end
|
||||
|
||||
describe 'Scopes' do
|
||||
describe '.expired' do
|
||||
let!(:unexpired) { Fabricate :access_grant, expires_in: 10.hours }
|
||||
let!(:expired) do
|
||||
travel_to 10.minutes.ago do
|
||||
Fabricate :access_grant, expires_in: 5.minutes
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns records past their expired time' do
|
||||
expect(described_class.expired)
|
||||
.to include(expired)
|
||||
.and not_include(unexpired)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.revoked' do
|
||||
let!(:revoked) { Fabricate :access_grant, revoked_at: 10.minutes.ago }
|
||||
let!(:unrevoked) { Fabricate :access_grant, revoked_at: 10.minutes.from_now }
|
||||
|
||||
it 'returns records past their expired time' do
|
||||
expect(described_class.revoked)
|
||||
.to include(revoked)
|
||||
.and not_include(unrevoked)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
63
spec/models/doorkeeper/access_token_spec.rb
Normal file
63
spec/models/doorkeeper/access_token_spec.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Doorkeeper::AccessToken do
|
||||
describe 'Associations' do
|
||||
it { is_expected.to have_many(:web_push_subscriptions).class_name('Web::PushSubscription').inverse_of(:access_token) }
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
subject { Fabricate :access_token }
|
||||
|
||||
it { is_expected.to validate_presence_of(:token) }
|
||||
end
|
||||
|
||||
describe 'Scopes' do
|
||||
describe '.expired' do
|
||||
let!(:unexpired) { Fabricate :access_token, expires_in: 10.hours }
|
||||
let!(:expired) do
|
||||
travel_to 10.minutes.ago do
|
||||
Fabricate :access_token, expires_in: 5.minutes
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns records past their expired time' do
|
||||
expect(described_class.expired)
|
||||
.to include(expired)
|
||||
.and not_include(unexpired)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.revoked' do
|
||||
let!(:revoked) { Fabricate :access_token, revoked_at: 10.minutes.ago }
|
||||
let!(:unrevoked) { Fabricate :access_token, revoked_at: 10.minutes.from_now }
|
||||
|
||||
it 'returns records past their expired time' do
|
||||
expect(described_class.revoked)
|
||||
.to include(revoked)
|
||||
.and not_include(unrevoked)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#revoke' do
|
||||
let(:record) { Fabricate :access_token, revoked_at: 10.days.from_now }
|
||||
|
||||
it 'marks the record as revoked' do
|
||||
expect { record.revoke }
|
||||
.to change(record, :revoked_at).to(be_within(1).of(Time.now.utc))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_last_used' do
|
||||
let(:record) { Fabricate :access_token, last_used_at: nil, last_used_ip: nil }
|
||||
let(:request) { instance_double(ActionDispatch::Request, remote_ip: '1.1.1.1') }
|
||||
|
||||
it 'marks the record as revoked' do
|
||||
expect { record.update_last_used(request) }
|
||||
.to change(record, :last_used_at).to(be_within(1).of(Time.now.utc))
|
||||
.and change(record, :last_used_ip).to(IPAddr.new('1.1.1.1'))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,8 +8,45 @@ RSpec.describe Doorkeeper::Application do
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
subject { Fabricate :application }
|
||||
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
it { is_expected.to validate_presence_of(:uid) }
|
||||
|
||||
it { is_expected.to validate_length_of(:name).is_at_most(described_class::APP_NAME_LIMIT) }
|
||||
it { is_expected.to validate_length_of(:redirect_uri).is_at_most(described_class::APP_REDIRECT_URI_LIMIT) }
|
||||
it { is_expected.to validate_length_of(:website).is_at_most(described_class::APP_WEBSITE_LIMIT) }
|
||||
end
|
||||
|
||||
describe '#redirect_uris' do
|
||||
subject { Fabricate.build(:application, redirect_uri:).redirect_uris }
|
||||
|
||||
context 'with single value' do
|
||||
let(:redirect_uri) { 'https://test.example/one' }
|
||||
|
||||
it { is_expected.to be_an(Array).and(eq(['https://test.example/one'])) }
|
||||
end
|
||||
|
||||
context 'with multiple values' do
|
||||
let(:redirect_uri) { "https://test.example/one\nhttps://test.example/two" }
|
||||
|
||||
it { is_expected.to be_an(Array).and(eq(['https://test.example/one', 'https://test.example/two'])) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#confirmation_redirect_uri' do
|
||||
subject { Fabricate.build(:application, redirect_uri:).confirmation_redirect_uri }
|
||||
|
||||
context 'with single value' do
|
||||
let(:redirect_uri) { 'https://test.example/one ' }
|
||||
|
||||
it { is_expected.to eq('https://test.example/one') }
|
||||
end
|
||||
|
||||
context 'with multiple values' do
|
||||
let(:redirect_uri) { "https://test.example/one \nhttps://test.example/two " }
|
||||
|
||||
it { is_expected.to eq('https://test.example/one') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
37
spec/models/instance_moderation_note_spec.rb
Normal file
37
spec/models/instance_moderation_note_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe InstanceModerationNote do
|
||||
describe 'chronological' do
|
||||
it 'returns the instance notes sorted by oldest first' do
|
||||
instance = Instance.find_or_initialize_by(domain: TagManager.instance.normalize_domain('mastodon.example'))
|
||||
|
||||
note1 = Fabricate(:instance_moderation_note, domain: instance.domain)
|
||||
note2 = Fabricate(:instance_moderation_note, domain: instance.domain)
|
||||
|
||||
expect(instance.moderation_notes.chronological).to eq [note1, note2]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'is invalid if the content is empty' do
|
||||
note = Fabricate.build(:instance_moderation_note, domain: 'mastodon.example', content: '')
|
||||
expect(note.valid?).to be false
|
||||
end
|
||||
|
||||
it 'is invalid if content is longer than character limit' do
|
||||
note = Fabricate.build(:instance_moderation_note, domain: 'mastodon.example', content: comment_over_limit)
|
||||
expect(note.valid?).to be false
|
||||
end
|
||||
|
||||
it 'is valid even if the instance does not exist yet' do
|
||||
note = Fabricate.build(:instance_moderation_note, domain: 'non-existent.example', content: 'test comment')
|
||||
expect(note.valid?).to be true
|
||||
end
|
||||
|
||||
def comment_over_limit
|
||||
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,9 +3,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Instance do
|
||||
describe 'Scopes' do
|
||||
before { described_class.refresh }
|
||||
before { described_class.refresh }
|
||||
|
||||
describe 'Scopes' do
|
||||
describe '#searchable' do
|
||||
let(:expected_domain) { 'host.example' }
|
||||
let(:blocked_domain) { 'other.example' }
|
||||
|
||||
@@ -166,6 +166,34 @@ RSpec.describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#email_domain' do
|
||||
subject { described_class.new(email: email).email_domain }
|
||||
|
||||
context 'when value is nil' do
|
||||
let(:email) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when value is blank' do
|
||||
let(:email) { '' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when value has valid domain' do
|
||||
let(:email) { 'user@host.example' }
|
||||
|
||||
it { is_expected.to eq('host.example') }
|
||||
end
|
||||
|
||||
context 'when value has no split' do
|
||||
let(:email) { 'user$host.example' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_sign_in!' do
|
||||
context 'with an existing user' do
|
||||
let!(:user) { Fabricate :user, last_sign_in_at: 10.days.ago, current_sign_in_at: 1.hour.ago, sign_in_count: 123 }
|
||||
|
||||
16
spec/requests/admin/instances/moderation_notes_spec.rb
Normal file
16
spec/requests/admin/instances/moderation_notes_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Report Notes' do
|
||||
describe 'POST /admin/instance/moderation_notes' do
|
||||
before { sign_in Fabricate(:admin_user) }
|
||||
|
||||
it 'gracefully handles invalid nested params' do
|
||||
post admin_instance_moderation_notes_path(instance_id: 'mastodon.test', instance_note: 'invalid')
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,9 +4,9 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Instances' do
|
||||
describe 'GET /admin/instances/:id' do
|
||||
context 'with an unknown domain' do
|
||||
before { sign_in Fabricate(:admin_user) }
|
||||
before { sign_in Fabricate(:admin_user) }
|
||||
|
||||
context 'with an unknown domain' do
|
||||
it 'returns http success' do
|
||||
get admin_instance_path(id: 'unknown.example')
|
||||
|
||||
@@ -14,5 +14,14 @@ RSpec.describe 'Admin Instances' do
|
||||
.to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid domain' do
|
||||
it 'returns http success' do
|
||||
get admin_instance_path(id: ' ')
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Oauth Userinfo Endpoint' do
|
||||
RSpec.describe 'OAuth Userinfo Endpoint' do
|
||||
include RoutingHelper
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Admin::AccountModerationNotes' do
|
||||
end
|
||||
|
||||
def delete_note
|
||||
within('.report-notes__item__actions') do
|
||||
within('.report-notes__item:first-child .report-notes__item__actions') do
|
||||
click_on I18n.t('admin.reports.notes.delete')
|
||||
end
|
||||
end
|
||||
|
||||
51
spec/system/admin/instance/moderation_notes_spec.rb
Normal file
51
spec/system/admin/instance/moderation_notes_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin::Instances::ModerationNotesController' do
|
||||
let(:current_user) { Fabricate(:admin_user) }
|
||||
let(:instance_domain) { 'mastodon.example' }
|
||||
|
||||
before { sign_in current_user }
|
||||
|
||||
describe 'Managing instance moderation notes' do
|
||||
it 'saves and then deletes a record' do
|
||||
visit admin_instance_path(instance_domain)
|
||||
|
||||
fill_in 'instance_moderation_note_content', with: ''
|
||||
expect { submit_form }
|
||||
.to not_change(InstanceModerationNote, :count)
|
||||
expect(page)
|
||||
.to have_content(/error below/)
|
||||
|
||||
fill_in 'instance_moderation_note_content', with: 'Test message ' * InstanceModerationNote::CONTENT_SIZE_LIMIT
|
||||
expect { submit_form }
|
||||
.to not_change(InstanceModerationNote, :count)
|
||||
expect(page)
|
||||
.to have_content(/error below/)
|
||||
|
||||
fill_in 'instance_moderation_note_content', with: 'Test message'
|
||||
expect { submit_form }
|
||||
.to change(InstanceModerationNote, :count).by(1)
|
||||
expect(page)
|
||||
.to have_current_path(admin_instance_path(instance_domain))
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.instances.moderation_notes.created_msg'))
|
||||
|
||||
expect { delete_note }
|
||||
.to change(InstanceModerationNote, :count).by(-1)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.instances.moderation_notes.destroyed_msg'))
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.instances.moderation_notes.create')
|
||||
end
|
||||
|
||||
def delete_note
|
||||
within('.report-notes__item:first-child .report-notes__item__actions') do
|
||||
click_on I18n.t('admin.reports.notes.delete')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user