2023-02-22 09:55:31 +09:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-11-09 16:24:21 +09:00
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
2023-05-04 12:49:53 +09:00
|
|
|
|
RSpec.describe Account::Field do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
describe '#verified?' do
|
|
|
|
|
subject { described_class.new(account, 'name' => 'Foo', 'value' => 'Bar', 'verified_at' => verified_at) }
|
|
|
|
|
|
2023-06-22 21:55:22 +09:00
|
|
|
|
let(:account) { instance_double(Account, local?: true) }
|
2023-02-20 13:24:14 +09:00
|
|
|
|
|
2022-11-09 16:24:21 +09: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 13:24:14 +09:00
|
|
|
|
subject { described_class.new(account, original_hash) }
|
|
|
|
|
|
2023-06-22 21:55:22 +09:00
|
|
|
|
let(:account) { instance_double(Account, local?: true) }
|
2022-11-09 16:24:21 +09:00
|
|
|
|
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-06-22 21:55:22 +09:00
|
|
|
|
let(:account) { instance_double(Account, local?: local) }
|
2023-02-20 13:24:14 +09:00
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with local accounts' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:local) { true }
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with a URL with misleading authentication' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:value) { 'https://spacex.com @h.43z.one' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with a URL' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:value) { 'https://example.com' }
|
|
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
|
expect(subject.verifiable?).to be true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with an IDN URL' do
|
2022-11-21 03:28:13 +09:00
|
|
|
|
let(:value) { 'https://twitter.com∕dougallj∕status∕1590357240443437057.ê.cc/twitter.html' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with a URL with a non-normalized path' do
|
2022-11-21 03:28:13 +09:00
|
|
|
|
let(:value) { 'https://github.com/octocatxxxxxxxx/../mastodon' }
|
2022-11-10 14:27:45 +09:00
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with text that is not a URL' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:value) { 'Hello world' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with text that contains a URL' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:value) { 'Hello https://example.com world' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-18 06:56:20 +09:00
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with text which is blank' do
|
2022-11-14 05:02:09 +09:00
|
|
|
|
let(:value) { '' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-11-09 16:24:21 +09:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with remote accounts' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:local) { false }
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with a link' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
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
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with a link with misleading authentication' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
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
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with HTML that has more than just a link' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
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
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with a link with different visible text' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
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
|
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with text that is a URL but is not linked' do
|
2022-11-09 16:24:21 +09:00
|
|
|
|
let(:value) { 'https://example.com/foo' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-02-18 06:56:20 +09:00
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
|
context 'with text which is blank' do
|
2022-11-14 05:02:09 +09:00
|
|
|
|
let(:value) { '' }
|
|
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
|
expect(subject.verifiable?).to be false
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-11-09 16:24:21 +09:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|