eBooru/test/unit/email_blacklist_test.rb

51 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "test_helper"
class EmailBlacklistTest < ActiveSupport::TestCase
2019-02-09 21:42:43 -05:00
setup do
@user = create(:user)
CurrentUser.user = create(:mod_user)
2019-02-09 21:42:43 -05:00
end
should "detect email by suffix" do
block = EmailBlacklist.create(creator: @user, domain: '.xyz', reason: 'test')
assert(EmailBlacklist.is_banned?('spam@what.xyz'))
assert_equal(false, EmailBlacklist.is_banned?('good@angelic.com'))
end
should "detect email by mx" do
block = EmailBlacklist.create(creator: @user, domain: 'google.com', reason: 'test')
2022-05-26 16:49:43 -04:00
EmailBlacklist.stubs(:get_mx_records).returns(['google.com'])
assert(EmailBlacklist.is_banned?('spam@e621.net'))
2022-05-26 16:49:43 -04:00
EmailBlacklist.unstub(:get_mx_records)
assert_equal(false, EmailBlacklist.is_banned?('what@me.xynzs'))
2019-02-09 21:42:43 -05:00
end
should "keep accounts verified if there are too many matches" do
stub_const(EmailBlacklist, :UNVERIFY_COUNT_TRESHOLD, 5) do
users = create_list(:user, EmailBlacklist::UNVERIFY_COUNT_TRESHOLD + 1) do |user, i|
user.email = "#{i}@domain.com"
end
EmailBlacklist.create(creator: @user, domain: "domain.com", reason: "test")
users.each(&:reload)
assert users.all?(&:is_verified?)
end
end
should "unverify accounts if there are few matches" do
@domain_blocked_user = create(:user, email: "0@domain.com")
@other_user1 = create(:user, email: "0@prefix.domain.com")
@other_user2 = create(:user, email: "0@somethingelse.xynzs")
EmailBlacklist.create(creator: @user, domain: "domain.com", reason: "test")
@domain_blocked_user.reload
@other_user1.reload
@other_user2.reload
assert_not @domain_blocked_user.is_verified?
assert @other_user1.is_verified?
assert @other_user2.is_verified?
end
end