forked from thomseddon/traefik-forward-auth
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Max Mitchell
committed
Jan 12, 2021
1 parent
4906a18
commit 4091bb1
Showing
3 changed files
with
60 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,53 +61,53 @@ func TestAuthValidateCookie(t *testing.T) { | |
assert.Equal("[email protected]", email, "valid request should return user email") | ||
} | ||
|
||
func TestAuthValidateEmail(t *testing.T) { | ||
func TestAuthValidateUser(t *testing.T) { | ||
assert := assert.New(t) | ||
config, _ = NewConfig([]string{}) | ||
|
||
// Should allow any with no whitelist/domain is specified | ||
v := ValidateEmail("[email protected]", "default") | ||
v := ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow any domain if email domain is not defined") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow any domain if email domain is not defined") | ||
|
||
// Should allow matching domain | ||
config.Domains = []string{"test.com"} | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.False(v, "should not allow user from another domain") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow user from allowed domain") | ||
|
||
// Should allow matching whitelisted email address | ||
config.Domains = []string{} | ||
config.Whitelist = []string{"[email protected]"} | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.False(v, "should not allow user not in whitelist") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow user in whitelist") | ||
|
||
// Should allow only matching email address when | ||
// MatchWhitelistOrDomain is disabled | ||
config.Domains = []string{"example.com"} | ||
config.Whitelist = []string{"[email protected]"} | ||
config.MatchWhitelistOrDomain = false | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.False(v, "should not allow user not in either") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.False(v, "should not allow user from allowed domain") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow user in whitelist") | ||
|
||
// Should allow either matching domain or email address when | ||
// MatchWhitelistOrDomain is enabled | ||
config.Domains = []string{"example.com"} | ||
config.Whitelist = []string{"[email protected]"} | ||
config.MatchWhitelistOrDomain = true | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.False(v, "should not allow user not in either") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow user from allowed domain") | ||
v = ValidateEmail("[email protected]", "default") | ||
v = ValidateUser("[email protected]", "default") | ||
assert.True(v, "should allow user in whitelist") | ||
|
||
// Rule testing | ||
|
@@ -117,11 +117,11 @@ func TestAuthValidateEmail(t *testing.T) { | |
config.Whitelist = []string{"[email protected]"} | ||
config.Rules = map[string]*Rule{"test": NewRule()} | ||
config.MatchWhitelistOrDomain = true | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user not in either") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user from allowed global domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user in global whitelist") | ||
|
||
// Should allow matching domain in rule | ||
|
@@ -131,11 +131,11 @@ func TestAuthValidateEmail(t *testing.T) { | |
config.Rules = map[string]*Rule{"test": rule} | ||
rule.Domains = []string{"testrule.com"} | ||
config.MatchWhitelistOrDomain = false | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from another domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from global domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user from allowed domain") | ||
|
||
// Should allow matching whitelist in rule | ||
|
@@ -145,11 +145,11 @@ func TestAuthValidateEmail(t *testing.T) { | |
config.Rules = map[string]*Rule{"test": rule} | ||
rule.Whitelist = []string{"[email protected]"} | ||
config.MatchWhitelistOrDomain = false | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from another domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from global domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user from allowed domain") | ||
|
||
// Should allow only matching email address when | ||
|
@@ -161,15 +161,15 @@ func TestAuthValidateEmail(t *testing.T) { | |
rule.Domains = []string{"examplerule.com"} | ||
rule.Whitelist = []string{"[email protected]"} | ||
config.MatchWhitelistOrDomain = false | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user not in either") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user in global whitelist") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from global domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from allowed domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user in whitelist") | ||
|
||
// Should allow either matching domain or email address when | ||
|
@@ -181,15 +181,15 @@ func TestAuthValidateEmail(t *testing.T) { | |
rule.Domains = []string{"examplerule.com"} | ||
rule.Whitelist = []string{"[email protected]"} | ||
config.MatchWhitelistOrDomain = true | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user not in either") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user in global whitelist") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.False(v, "should not allow user from global domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user from allowed domain") | ||
v = ValidateEmail("[email protected]", "test") | ||
v = ValidateUser("[email protected]", "test") | ||
assert.True(v, "should allow user in whitelist") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters