Revert "FEATURE: reject accounts created with an email address similar to a known spammer email"
This reverts commit 39be48a441
.
Conflicts:
spec/models/screened_email_spec.rb
This commit is contained in:
parent
572b8e0664
commit
b526cdc55c
|
@ -17,27 +17,8 @@ class ScreenedEmail < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.should_block?(email)
|
def self.should_block?(email)
|
||||||
levenshtein_distance = SiteSetting.levenshtein_distance_spammer_emails
|
screened_email = ScreenedEmail.find_by(email: email)
|
||||||
|
|
||||||
sql = <<-SQL
|
|
||||||
JOIN (
|
|
||||||
SELECT email, levenshtein_less_equal(email, :email, :levenshtein_distance) AS distance
|
|
||||||
FROM screened_emails
|
|
||||||
ORDER BY created_at DESC
|
|
||||||
LIMIT 100
|
|
||||||
) AS sed ON sed.email = screened_emails.email
|
|
||||||
SQL
|
|
||||||
|
|
||||||
screened_emails_distance = ScreenedEmail.sql_fragment(sql, email: email, levenshtein_distance: levenshtein_distance)
|
|
||||||
|
|
||||||
screened_email = ScreenedEmail.joins(screened_emails_distance)
|
|
||||||
.where("sed.distance <= ?", levenshtein_distance)
|
|
||||||
.order("sed.distance ASC")
|
|
||||||
.limit(1)
|
|
||||||
.first
|
|
||||||
|
|
||||||
screened_email.record_match! if screened_email
|
screened_email.record_match! if screened_email
|
||||||
|
|
||||||
screened_email && screened_email.action_type == actions[:block]
|
screened_email && screened_email.action_type == actions[:block]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -890,8 +890,6 @@ en:
|
||||||
white_listed_spam_host_domains: "A pipe-delimited list of domains excluded from spam host testing, new users will be able to create an unrestricted count of posts with links to this domain"
|
white_listed_spam_host_domains: "A pipe-delimited list of domains excluded from spam host testing, new users will be able to create an unrestricted count of posts with links to this domain"
|
||||||
staff_like_weight: "Extra weighting factor given to likes when performed by staff."
|
staff_like_weight: "Extra weighting factor given to likes when performed by staff."
|
||||||
|
|
||||||
levenshtein_distance_spammer_emails: "Number of characters different from a known spammer email."
|
|
||||||
|
|
||||||
reply_by_email_enabled: "Enable replying to topics via email"
|
reply_by_email_enabled: "Enable replying to topics via email"
|
||||||
reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com"
|
reply_by_email_address: "Template for reply by email incoming email address, for example: %{reply_key}@reply.example.com or replies+%{reply_key}@example.com"
|
||||||
|
|
||||||
|
|
|
@ -527,7 +527,6 @@ spam:
|
||||||
white_listed_spam_host_domains:
|
white_listed_spam_host_domains:
|
||||||
default: ''
|
default: ''
|
||||||
type: list
|
type: list
|
||||||
levenshtein_distance_spammer_emails: 2
|
|
||||||
|
|
||||||
rate_limits:
|
rate_limits:
|
||||||
unique_posts_mins:
|
unique_posts_mins:
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
class AddFuzzyStrMatchExtension < ActiveRecord::Migration
|
|
||||||
def self.up
|
|
||||||
execute "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.down
|
|
||||||
execute "DROP EXTENSION fuzzystrmatch"
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -3,34 +3,33 @@ require 'spec_helper'
|
||||||
describe ScreenedEmail do
|
describe ScreenedEmail do
|
||||||
|
|
||||||
let(:email) { 'block@spamfromhome.org' }
|
let(:email) { 'block@spamfromhome.org' }
|
||||||
let(:similar_email) { 'bl0ck@spamfromhome.org' }
|
|
||||||
|
|
||||||
describe "new record" do
|
describe "new record" do
|
||||||
it "sets a default action_type" do
|
it "sets a default action_type" do
|
||||||
ScreenedEmail.create(email: email).action_type.should == ScreenedEmail.actions[:block]
|
described_class.create(email: email).action_type.should == described_class.actions[:block]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "last_match_at is null" do
|
it "last_match_at is null" do
|
||||||
# If we manually load the table with some emails, we can see whether those emails
|
# If we manually load the table with some emails, we can see whether those emails
|
||||||
# have ever been blocked by looking at last_match_at.
|
# have ever been blocked by looking at last_match_at.
|
||||||
ScreenedEmail.create(email: email).last_match_at.should be_nil
|
described_class.create(email: email).last_match_at.should be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#block' do
|
describe '#block' do
|
||||||
context 'email is not being blocked' do
|
context 'email is not being blocked' do
|
||||||
it 'creates a new record with default action of :block' do
|
it 'creates a new record with default action of :block' do
|
||||||
record = ScreenedEmail.block(email)
|
record = described_class.block(email)
|
||||||
record.should_not be_new_record
|
record.should_not be_new_record
|
||||||
record.email.should == email
|
record.email.should == email
|
||||||
record.action_type.should == ScreenedEmail.actions[:block]
|
record.action_type.should == described_class.actions[:block]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'lets action_type be overriden' do
|
it 'lets action_type be overriden' do
|
||||||
record = ScreenedEmail.block(email, action_type: ScreenedEmail.actions[:do_nothing])
|
record = described_class.block(email, action_type: described_class.actions[:do_nothing])
|
||||||
record.should_not be_new_record
|
record.should_not be_new_record
|
||||||
record.email.should == email
|
record.email.should == email
|
||||||
record.action_type.should == ScreenedEmail.actions[:do_nothing]
|
record.action_type.should == described_class.actions[:do_nothing]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,34 +37,22 @@ describe ScreenedEmail do
|
||||||
let!(:existing) { Fabricate(:screened_email, email: email) }
|
let!(:existing) { Fabricate(:screened_email, email: email) }
|
||||||
|
|
||||||
it "doesn't create a new record" do
|
it "doesn't create a new record" do
|
||||||
expect { ScreenedEmail.block(email) }.to_not change { ScreenedEmail.count }
|
expect { described_class.block(email) }.to_not change { described_class.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the existing record" do
|
it "returns the existing record" do
|
||||||
ScreenedEmail.block(email).should == existing
|
described_class.block(email).should == existing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#should_block?' do
|
describe '#should_block?' do
|
||||||
subject { ScreenedEmail.should_block?(email) }
|
subject { described_class.should_block?(email) }
|
||||||
|
|
||||||
it "returns false when there are no record with a similar email" do
|
it "returns false if a record with the email doesn't exist" do
|
||||||
subject.should be_false
|
subject.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns true when there is a record with the email" do
|
|
||||||
ScreenedEmail.should_block?(email).should be_false
|
|
||||||
ScreenedEmail.create(email: email).save
|
|
||||||
ScreenedEmail.should_block?(email).should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns true when there is a record with a similar email" do
|
|
||||||
ScreenedEmail.should_block?(email).should be_false
|
|
||||||
ScreenedEmail.create(email: similar_email).save
|
|
||||||
ScreenedEmail.should_block?(email).should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples "when a ScreenedEmail record matches" do
|
shared_examples "when a ScreenedEmail record matches" do
|
||||||
it "updates statistics" do
|
it "updates statistics" do
|
||||||
Timecop.freeze(Time.zone.now) do
|
Timecop.freeze(Time.zone.now) do
|
||||||
|
@ -76,13 +63,13 @@ describe ScreenedEmail do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "action_type is :block" do
|
context "action_type is :block" do
|
||||||
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:block]) }
|
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: described_class.actions[:block]) }
|
||||||
it { should be_true }
|
it { should be_true }
|
||||||
include_examples "when a ScreenedEmail record matches"
|
include_examples "when a ScreenedEmail record matches"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "action_type is :do_nothing" do
|
context "action_type is :do_nothing" do
|
||||||
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:do_nothing]) }
|
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: described_class.actions[:do_nothing]) }
|
||||||
it { should be_false }
|
it { should be_false }
|
||||||
include_examples "when a ScreenedEmail record matches"
|
include_examples "when a ScreenedEmail record matches"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue