-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
domain_list_match.go
59 lines (47 loc) · 2.35 KB
/
domain_list_match.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package truemail
// Whitelist/Blacklist validation, zero validation level
type validationDomainListMatch struct{ result *ValidatorResult }
// interface implementation
func (validation *validationDomainListMatch) check(validatorResult *ValidatorResult) *ValidatorResult {
validation.result = validatorResult
validation.setValidatorResultDomain()
// Failure scenario
if validation.isBlacklistedDomain() || (validation.isWhitelistValidation() && !validation.isWhitelistedDomain()) {
validatorResult.ValidationType = domainListMatchBlacklist
validatorResult.addError(validationTypeDomainListMatch, domainListMatchErrorContext)
return validatorResult
}
// Successful scenario
validatorResult.Success = true
// Handle flow with ValidationType persisting
if !validation.isWhitelistValidation() && !(!validation.isBlacklistedDomain() && !validation.isWhitelistedDomain()) {
validatorResult.ValidationType = domainListMatchWhitelist
}
// Handle flow for processing validatorResult via next validation level
if (validation.isWhitelistValidation() && validation.isWhitelistedDomain()) ||
(!validation.isBlacklistedDomain() && !validation.isWhitelistedDomain()) {
validatorResult.isPassFromDomainListMatch = true
}
return validatorResult
}
// validationDomainListMatch methods
// Assigns domain based on validator result email to validatorResult
func (validation *validationDomainListMatch) setValidatorResultDomain() {
validatorResult := validation.result
validatorResult.Domain = emailDomain(validatorResult.Email)
}
// Returns true if email domain is included in whitelisted domains slice, otherwise returns false
func (validation *validationDomainListMatch) isWhitelistedDomain() bool {
validatorResult := validation.result
return isIncluded(validatorResult.Configuration.WhitelistedDomains, validatorResult.Domain)
}
// Returns true if whitelist validation enabled, otherwise returns false
func (validation *validationDomainListMatch) isWhitelistValidation() bool {
validatorResult := validation.result
return validatorResult.Configuration.WhitelistValidation
}
// Returns true if email domain is included in blacklisted domains slice, otherwise returns false
func (validation *validationDomainListMatch) isBlacklistedDomain() bool {
validatorResult := validation.result
return isIncluded(validatorResult.Configuration.BlacklistedDomains, validatorResult.Domain)
}