Skip to content

Commit

Permalink
sad (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Apr 29, 2024
1 parent 16d336d commit 72d7e29
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
15 changes: 7 additions & 8 deletions go/controller/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,24 @@ func ValidateEmail(
if len(parts) != 2 { //nolint:gomnd
return false
}

domain := parts[1]

if slices.Contains(blockedEmailDomains, domain) {
if slices.Contains(blockedEmails, email) {
return false
}

if slices.Contains(blockedEmails, email) {
return false
if slices.Contains(allowedEmails, email) {
return true
}

if len(allowedEmailDomains) > 0 && !slices.Contains(allowedEmailDomains, domain) {
if slices.Contains(blockedEmailDomains, domain) {
return false
}

if len(allowedEmails) > 0 && !slices.Contains(allowedEmails, email) {
return false
if slices.Contains(allowedEmailDomains, domain) {
return true
}

return true
return len(allowedEmailDomains) == 0 && len(allowedEmails) == 0
}
}
63 changes: 63 additions & 0 deletions go/controller/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,69 @@ func TestValidateEmail(t *testing.T) {
email: "[email protected]",
expected: false,
},
{
name: "precedence - unrelated",
blockedDomains: []string{"blocked.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: false,
},
{
name: "precedence - allowed email",
blockedDomains: []string{"blocked.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: true,
},
{
name: "precedence - blocked email",
blockedDomains: []string{"blocked.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: false,
},
{
name: "precedence - blocked domain",
blockedDomains: []string{"blocked.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: false,
},
{
name: "precedence - allowed domain",
blockedDomains: []string{"blocked.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: true,
},
{
name: "blocking take precedence over allowing",
blockedDomains: []string{"acme.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: false,
},
{
name: "blocking take precedence over allowing",
blockedDomains: []string{"acme.com"},
blockedEmails: []string{"[email protected]"},
allowedDomains: []string{"acme.com"},
allowedEmails: []string{"[email protected]"},
email: "[email protected]",
expected: false,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 72d7e29

Please sign in to comment.