Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

chore: rename from white/black to allow/block

goenning96a73f51cbd8
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index d2ca91723..885a47cca 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -54,8 +54,8 @@ type config struct {
}
Email struct {
NoReply string `env:"EMAIL_NOREPLY,required"`
- Whitelist string `env:"EMAIL_WHITELIST"`
- Blacklist string `env:"EMAIL_BLACKLIST"`
+ Allowlist string `env:"EMAIL_ALLOWLIST"`
+ Blocklist string `env:"EMAIL_BLOCKLIST"`
Mailgun struct {
APIKey string `env:"EMAIL_MAILGUN_API"`
Domain string `env:"EMAIL_MAILGUN_DOMAIN"`
diff --git a/app/services/email/email.go b/app/services/email/email.go
index 0ace66c5f..e178e5b25 100644
--- a/app/services/email/email.go
+++ b/app/services/email/email.go
@@ -10,21 +10,21 @@ import (
// NoReply is the default 'from' address
var NoReply = env.Config.Email.NoReply
-var whitelist = env.Config.Email.Whitelist
-var whitelistRegex = regexp.MustCompile(whitelist)
-var blacklist = env.Config.Email.Blacklist
-var blacklistRegex = regexp.MustCompile(blacklist)
-
-// SetWhitelist can be used to change email whitelist during runtime
-func SetWhitelist(s string) {
- whitelist = s
- whitelistRegex = regexp.MustCompile(whitelist)
+var allowlist = env.Config.Email.Allowlist
+var allowlistRegex = regexp.MustCompile(allowlist)
+var blocklist = env.Config.Email.Blocklist
+var blocklistRegex = regexp.MustCompile(blocklist)
+
+// SetAllowlist can be used to change email allowlist during runtime
+func SetAllowlist(s string) {
+ allowlist = s
+ allowlistRegex = regexp.MustCompile(allowlist)
}
-// SetBlacklist can be used to change email blacklist during runtime
-func SetBlacklist(s string) {
- blacklist = s
- blacklistRegex = regexp.MustCompile(blacklist)
+// SetBlocklist can be used to change email blocklist during runtime
+func SetBlocklist(s string) {
+ blocklist = s
+ blocklistRegex = regexp.MustCompile(blocklist)
}
// CanSendTo returns true if Fider is allowed to send email to given address
@@ -33,12 +33,12 @@ func CanSendTo(address string) bool {
return false
}
- if whitelist != "" {
- return whitelistRegex.MatchString(address)
+ if allowlist != "" {
+ return allowlistRegex.MatchString(address)
}
- if blacklist != "" {
- return !blacklistRegex.MatchString(address)
+ if blocklist != "" {
+ return !blocklistRegex.MatchString(address)
}
return true
diff --git a/app/services/email/email_test.go b/app/services/email/email_test.go
index 89412a44e..ec746ea66 100644
--- a/app/services/email/email_test.go
+++ b/app/services/email/email_test.go
@@ -53,58 +53,58 @@ func TestCanSendTo(t *testing.T) {
RegisterT(t)
testCases := []struct {
- whitelist string
- blacklist string
+ allowlist string
+ blocklist string
input []string
canSend bool
}{
{
- whitelist: "(^[email protected]$)|(^darthvader\\.fider(\\+.*)?@gmail\\.com$)",
- blacklist: "",
+ allowlist: "(^[email protected]$)|(^darthvader\\.fider(\\+.*)?@gmail\\.com$)",
+ blocklist: "",
canSend: true,
},
{
- whitelist: "(^[email protected]$)|(^darthvader\\.fider(\\+.*)?@gmail\\.com$)",
- blacklist: "",
+ allowlist: "(^[email protected]$)|(^darthvader\\.fider(\\+.*)?@gmail\\.com$)",
+ blocklist: "",
input: []string{"[email protected]", "[email protected]", "[email protected]", "@fider.io"},
canSend: false,
},
{
- whitelist: "(^[email protected]$)|(^darthvader\\.fider(\\+.*)?@gmail\\.com$)",
- blacklist: "(^[email protected]$)",
+ allowlist: "(^[email protected]$)|(^darthvader\\.fider(\\+.*)?@gmail\\.com$)",
+ blocklist: "(^[email protected]$)",
input: []string{"[email protected]"},
canSend: true,
},
{
- whitelist: "",
- blacklist: "(^[email protected]$)",
+ allowlist: "",
+ blocklist: "(^[email protected]$)",
input: []string{"[email protected]", "[email protected]"},
canSend: false,
},
{
- whitelist: "",
- blacklist: "(^[email protected]$)",
+ allowlist: "",
+ blocklist: "(^[email protected]$)",
input: []string{"[email protected]", "[email protected]"},
canSend: true,
},
{
- whitelist: "",
- blacklist: "",
+ allowlist: "",
+ blocklist: "",
input: []string{"[email protected]"},
canSend: true,
},
{
- whitelist: "",
- blacklist: "",
+ allowlist: "",
+ blocklist: "",
input: []string{"", " "},
canSend: false,
},
}
for _, testCase := range testCases {
- email.SetWhitelist(testCase.whitelist)
- email.SetBlacklist(testCase.blacklist)
+ email.SetAllowlist(testCase.allowlist)
+ email.SetBlocklist(testCase.blocklist)
for _, input := range testCase.input {
Expect(email.CanSendTo(input)).Equals(testCase.canSend)
}
diff --git a/app/services/email/mailgun/mailgun_test.go b/app/services/email/mailgun/mailgun_test.go
index 04fd1d4c4..0e4cd95d0 100644
--- a/app/services/email/mailgun/mailgun_test.go
+++ b/app/services/email/mailgun/mailgun_test.go
@@ -122,7 +122,7 @@ func TestSend_SkipEmptyAddress(t *testing.T) {
func TestSend_SkipUnlistedAddress(t *testing.T) {
RegisterT(t)
reset()
- email.SetWhitelist("^.*@gmail.com$")
+ email.SetAllowlist("^.*@gmail.com$")
bus.Publish(ctx, &cmd.SendMail{
From: "Fider Test",
@@ -144,7 +144,7 @@ func TestSend_SkipUnlistedAddress(t *testing.T) {
func TestBatch_Success(t *testing.T) {
RegisterT(t)
reset()
- email.SetWhitelist("")
+ email.SetAllowlist("")
bus.Publish(ctx, &cmd.SendMail{
From: "Fider Test",
diff --git a/app/services/email/smtp/smtp_test.go b/app/services/email/smtp/smtp_test.go
index 580431931..e787ab88c 100644
--- a/app/services/email/smtp/smtp_test.go
+++ b/app/services/email/smtp/smtp_test.go
@@ -97,7 +97,7 @@ func TestSend_SkipEmptyAddress(t *testing.T) {
func TestSend_SkipUnlistedAddress(t *testing.T) {
RegisterT(t)
reset()
- email.SetWhitelist("^.*@gmail.com$")
+ email.SetAllowlist("^.*@gmail.com$")
bus.Publish(ctx, &cmd.SendMail{
From: "Fider Test",
@@ -119,7 +119,7 @@ func TestSend_SkipUnlistedAddress(t *testing.T) {
func TestBatch_Success(t *testing.T) {
RegisterT(t)
reset()
- email.SetWhitelist("")
+ email.SetAllowlist("")
bus.Publish(ctx, &cmd.SendMail{
From: "Fider Test",