2022-11-09 08:24:21 +01:00
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Account::Field, type: :model do
|
|
|
|
|
describe '#verified?' do
|
|
|
|
|
subject { described_class.new(account, 'name' => 'Foo', 'value' => 'Bar', 'verified_at' => verified_at) }
|
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
|
let(:account) { double('Account', local?: true) }
|
|
|
|
|
|
2022-11-09 08:24:21 +01:00
|
|
|
|
context 'when verified_at is set' do
|
|
|
|
|
let(:verified_at) { Time.now.utc.iso8601 }
|
|
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
|
expect(subject.verified?).to be true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when verified_at is not set' do
|
|
|
|
|
let(:verified_at) { nil }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verified?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#mark_verified!' do
|
2023-02-20 05:24:14 +01:00
|
|
|
|
subject { described_class.new(account, original_hash) }
|
|
|
|
|
|
2022-11-09 08:24:21 +01:00
|
|
|
|
let(:account) { double('Account', local?: true) }
|
|
|
|
|
let(:original_hash) { { 'name' => 'Foo', 'value' => 'Bar' } }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
subject.mark_verified!
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'updates verified_at' do
|
|
|
|
|
expect(subject.verified_at).to_not be_nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'updates original hash' do
|
|
|
|
|
expect(original_hash['verified_at']).to_not be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#verifiable?' do
|
|
|
|
|
subject { described_class.new(account, 'name' => 'Foo', 'value' => value) }
|
|
|
|
|
|
2023-02-20 05:24:14 +01:00
|
|
|
|
let(:account) { double('Account', local?: local) }
|
|
|
|
|
|
2022-11-09 08:24:21 +01:00
|
|
|
|
context 'for local accounts' do
|
|
|
|
|
let(:local) { true }
|
|
|
|
|
|
|
|
|
|
context 'for a URL with misleading authentication' do
|
|
|
|
|
let(:value) { 'https://spacex.com @h.43z.one' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for a URL' do
|
|
|
|
|
let(:value) { 'https://example.com' }
|
|
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
|
expect(subject.verifiable?).to be true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-11-10 06:27:45 +01:00
|
|
|
|
context 'for an IDN URL' do
|
2022-11-20 19:28:13 +01:00
|
|
|
|
let(:value) { 'https://twitter.com∕dougallj∕status∕1590357240443437057.ê.cc/twitter.html' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for a URL with a non-normalized path' do
|
|
|
|
|
let(:value) { 'https://github.com/octocatxxxxxxxx/../mastodon' }
|
2022-11-10 06:27:45 +01:00
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-11-09 08:24:21 +01:00
|
|
|
|
context 'for text that is not a URL' do
|
|
|
|
|
let(:value) { 'Hello world' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for text that contains a URL' do
|
|
|
|
|
let(:value) { 'Hello https://example.com world' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-17 22:56:20 +01:00
|
|
|
|
|
2022-11-13 21:02:09 +01:00
|
|
|
|
context 'for text which is blank' do
|
|
|
|
|
let(:value) { '' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-11-09 08:24:21 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for remote accounts' do
|
|
|
|
|
let(:local) { false }
|
|
|
|
|
|
|
|
|
|
context 'for a link' do
|
|
|
|
|
let(:value) { '<a href="https://www.patreon.com/mastodon" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://www.</span><span class="">patreon.com/mastodon</span><span class="invisible"></span></a>' }
|
|
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
|
expect(subject.verifiable?).to be true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for a link with misleading authentication' do
|
|
|
|
|
let(:value) { '<a href="https://google.com @h.43z.one" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://</span><span class="">google.com</span><span class="invisible"> @h.43z.one</span></a>' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for HTML that has more than just a link' do
|
|
|
|
|
let(:value) { '<a href="https://google.com" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://</span><span class="">google.com</span><span class="invisible"></span></a> @h.43z.one' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for a link with different visible text' do
|
|
|
|
|
let(:value) { '<a href="https://google.com/bar">https://example.com/foo</a>' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for text that is a URL but is not linked' do
|
|
|
|
|
let(:value) { 'https://example.com/foo' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-17 22:56:20 +01:00
|
|
|
|
|
2022-11-13 21:02:09 +01:00
|
|
|
|
context 'for text which is blank' do
|
|
|
|
|
let(:value) { '' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-11-09 08:24:21 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|