mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-12 21:26:17 -05:00
Add some spec coverage (#40306)
This commit is contained in:
@@ -4,17 +4,11 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe PrivateAddressCheck do
|
||||
describe 'private_address?' do
|
||||
let(:private_ips) { %w(192.168.1.7 0.0.0.0 127.0.0.1 ::ffff:0.0.0.1 ::127.0.0.1 ::ffff:127.0.0.1 ::ffff:10.0.0.1 ::ffff:169.254.169.254 ::) }
|
||||
|
||||
it 'returns true for private addresses' do
|
||||
# rubocop:disable RSpec/ExpectActual
|
||||
expect(
|
||||
[
|
||||
'192.168.1.7',
|
||||
'0.0.0.0',
|
||||
'127.0.0.1',
|
||||
'::ffff:0.0.0.1',
|
||||
]
|
||||
).to all satisfy('return true') { |addr| described_class.private_address?(IPAddr.new(addr)) }
|
||||
# rubocop:enable RSpec/ExpectActual
|
||||
expect(private_ips)
|
||||
.to all satisfy('return true') { |addr| described_class.private_address?(IPAddr.new(addr)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,6 +109,46 @@ RSpec.describe ActivityPub::ProcessCollectionService do
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory)
|
||||
end
|
||||
|
||||
context 'when receiving a status with an unsupported JSON-LD keyword' do
|
||||
let(:payload) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'foo',
|
||||
type: 'Announce',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(actor),
|
||||
'@reverse': {
|
||||
object: {
|
||||
type: 'Undo',
|
||||
id: 'bar',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(actor),
|
||||
},
|
||||
},
|
||||
object: {
|
||||
id: 'bar',
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
},
|
||||
signature: {
|
||||
type: 'RsaSignature2017',
|
||||
creator: "#{ActivityPub::TagManager.instance.uri_for(actor)}#foo",
|
||||
created: '2022-03-09T21:57:25Z',
|
||||
signatureValue: 'foo',
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
it 'does not process payload' do
|
||||
signature_double = instance_double(ActivityPub::LinkedDataSignature, verify_actor!: nil)
|
||||
allow(ActivityPub::LinkedDataSignature).to receive(:new).and_return(signature_double)
|
||||
allow(ActivityPub::Activity).to receive(:factory)
|
||||
|
||||
subject.call(json, forwarder)
|
||||
|
||||
expect(signature_double).to_not have_received(:verify_actor!)
|
||||
expect(ActivityPub::Activity).to_not have_received(:factory)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when receiving a fabricated status' do
|
||||
let!(:actor) do
|
||||
Fabricate(:account,
|
||||
|
||||
31
spec/validators/email_address_validator_spec.rb
Normal file
31
spec/validators/email_address_validator_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EmailAddressValidator do
|
||||
context 'with no options' do
|
||||
let(:record_class) do
|
||||
Class.new do
|
||||
include ActiveModel::Model
|
||||
|
||||
def self.name = 'Record'
|
||||
|
||||
attr_accessor :email
|
||||
|
||||
validates :email, email_address: true
|
||||
end
|
||||
end
|
||||
|
||||
it 'considers a valid email address as such' do
|
||||
expect(record_class.new(email: 'foo@example.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'considers an invalid email address as such' do
|
||||
expect(record_class.new(email: 'foo @ example.com')).to_not be_valid
|
||||
end
|
||||
|
||||
it 'considers an email address with a % as invalid' do
|
||||
expect(record_class.new(email: 'foo@example.com%foo.example.com')).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user