Skip to content

A platform for community discussion. Free, open, simple.

Add specs to check email domain whitelist/blacklist for To and Cc

Gerhard Schlager9f7ae908d818
diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb
index 1ae5e656b36..3c5017aec38 100644
--- a/spec/components/email/receiver_spec.rb
+++ b/spec/components/email/receiver_spec.rb
@@ -674,7 +674,7 @@ describe Email::Receiver do
end
end
- context "no staged users on error" do
+ context "staged users" do
before do
SiteSetting.enable_staged_users = true
end
@@ -711,7 +711,7 @@ describe Email::Receiver do
include_examples "no staged users", :unsubscribe_new_user, Email::Receiver::UnsubscribeNotAllowed
end
- context "when email address is not on whitelist" do
+ context "when From email address is not on whitelist" do
before do
SiteSetting.email_domains_whitelist = "example.com|bar.com"
end
@@ -719,7 +719,7 @@ describe Email::Receiver do
include_examples "no staged users", :blacklist_whitelist_email, Email::Receiver::EmailNotAllowed
end
- context "when email address is on blacklist" do
+ context "when From email address is on blacklist" do
before do
SiteSetting.email_domains_blacklist = "email.com|mail.com"
end
@@ -727,6 +727,30 @@ describe Email::Receiver do
include_examples "no staged users", :blacklist_whitelist_email, Email::Receiver::EmailNotAllowed
end
+ context "blacklist and whitelist for To and Cc" do
+ before do
+ Fabricate(:group, incoming_email: "[email protected]")
+ end
+
+ it "does not create staged users for email addresses not on whitelist" do
+ SiteSetting.email_domains_whitelist = "mail.com|example.com"
+ process(:blacklist_whitelist_email)
+
+ expect(User.find_by_email("[email protected]")).to be_nil
+ expect(User.find_by_email("[email protected]")).to be_nil
+ expect(User.find_by_email("[email protected]")).to be_present
+ end
+
+ it "does not create staged users for email addresses on blacklist" do
+ SiteSetting.email_domains_blacklist = "email.com|foo.com"
+ process(:blacklist_whitelist_email)
+
+ expect(User.find_by_email("[email protected]")).to be_nil
+ expect(User.find_by_email("[email protected]")).to be_nil
+ expect(User.find_by_email("[email protected]")).to be_present
+ end
+ end
+
context "when destinations aren't matching any of the incoming emails" do
include_examples "no staged users", :bad_destinations, Email::Receiver::BadDestinationAddress
end
diff --git a/spec/fixtures/emails/blacklist_whitelist_email.eml b/spec/fixtures/emails/blacklist_whitelist_email.eml
index f6b38bfcce3..f9b0adf7905 100644
--- a/spec/fixtures/emails/blacklist_whitelist_email.eml
+++ b/spec/fixtures/emails/blacklist_whitelist_email.eml
@@ -1,5 +1,7 @@
Return-Path: <[email protected]>
From: Foo <[email protected]>
Date: Fri, 15 Jan 2016 00:12:43 +0100
Message-ID: <[email protected]>
Mime-Version: 1.0