FEATURE: when blocking emails prefer blocking canonical

Previously we relied entirely on levenshtein_distance_spammer_emails site
setting to handle "similar looking" emails.

This commit improves the situation by always preferring to block (and check)
canonical emails.

This means that if:

`samevil+test@domain.com` is blocked the system will block `samevil@domain.com`

This means that `samevil+2@domain.com` (ad infinitum) will be blocked
This commit is contained in:
Sam Saffron
2020-04-24 14:09:51 +10:00
parent 6a18c9aa0b
commit cbceadf48b
2 changed files with 23 additions and 1 deletions

View File

@ -26,6 +26,7 @@ describe ScreenedEmail do
describe '#block' do
context 'email is not being blocked' do
it 'creates a new record with default action of :block' do
record = ScreenedEmail.block(email)
expect(record).not_to be_new_record
@ -57,6 +58,14 @@ describe ScreenedEmail do
describe '#should_block?' do
subject { ScreenedEmail.should_block?(email) }
it "automatically blocks via email canonicalization" do
SiteSetting.levenshtein_distance_spammer_emails = 0
ScreenedEmail.block('bad.acTor+1@gmail.com')
ScreenedEmail.block('bad.actOr+2@gmail.com')
expect(ScreenedEmail.should_block?('b.a.dactor@gmail.com')).to eq(true)
end
it "returns false if a record with the email doesn't exist" do
expect(subject).to eq(false)
end