Convert attempt IP from EmailDomainBlock history tracking to string before recording (#38137)

This commit is contained in:
Matt Jankowski
2026-03-11 06:49:07 -04:00
committed by GitHub
parent d047a10cf5
commit dc004caf71
3 changed files with 10 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ class EmailDomainBlock < ApplicationRecord
def blocking?(allow_with_approval: false) def blocking?(allow_with_approval: false)
blocks = EmailDomainBlock.where(domain: domains_with_variants, allow_with_approval: allow_with_approval).by_domain_length blocks = EmailDomainBlock.where(domain: domains_with_variants, allow_with_approval: allow_with_approval).by_domain_length
blocks.each { |block| block.history.add(@attempt_ip) } if @attempt_ip.present? blocks.each { |block| block.history.add(@attempt_ip.to_s) } if @attempt_ip.present?
blocks.any? blocks.any?
end end

View File

@@ -40,11 +40,11 @@ class Trends::History
with_redis { |redis| redis.get(key_for(:uses)).to_i } with_redis { |redis| redis.get(key_for(:uses)).to_i }
end end
def add(account_id) def add(value)
with_redis do |redis| with_redis do |redis|
redis.pipelined do |pipeline| redis.pipelined do |pipeline|
pipeline.incrby(key_for(:uses), 1) pipeline.incrby(key_for(:uses), 1)
pipeline.pfadd(key_for(:accounts), account_id) pipeline.pfadd(key_for(:accounts), value)
pipeline.expire(key_for(:uses), EXPIRE_AFTER) pipeline.expire(key_for(:uses), EXPIRE_AFTER)
pipeline.expire(key_for(:accounts), EXPIRE_AFTER) pipeline.expire(key_for(:accounts), EXPIRE_AFTER)
end end

View File

@@ -56,16 +56,20 @@ RSpec.describe EmailDomainBlock do
end end
describe '.requires_approval?' do describe '.requires_approval?' do
subject { described_class.requires_approval?(input) } subject { described_class.requires_approval?(input, attempt_ip: IPAddr.new('100.100.100.100')) }
let(:input) { nil } let(:input) { nil }
context 'with a matching block requiring approval' do context 'with a matching block requiring approval' do
before { Fabricate :email_domain_block, domain: input, allow_with_approval: true } let!(:email_domain_block) { Fabricate :email_domain_block, domain: input, allow_with_approval: true }
let(:input) { 'host.example' } let(:input) { 'host.example' }
it { is_expected.to be true } it 'returns true and records attempt' do
expect do
expect(subject).to be(true)
end.to change { email_domain_block.history.get(Date.current).accounts }.by(1)
end
end end
context 'with a matching block not requiring approval' do context 'with a matching block not requiring approval' do