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:
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 }
|
||||
|
||||
Reference in New Issue
Block a user