forked from oauth2-proxy/oauth2-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make address/domain comparisons case-insensitive
- Loading branch information
Mike Bland
committed
Apr 7, 2015
1 parent
9534808
commit 781f34e
Showing
2 changed files
with
46 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestValidatorComparisonsAreCaseInsensitive(t *testing.T) { | ||
auth_email_file, err := ioutil.TempFile("", "test_auth_emails_") | ||
if err != nil { | ||
t.Fatal("failed to create temp file: " + err.Error()) | ||
} | ||
defer os.Remove(auth_email_file.Name()) | ||
|
||
auth_email_file.WriteString( | ||
strings.Join([]string{"Foo.Bar@Example.Com"}, "\n")) | ||
err = auth_email_file.Close() | ||
if err != nil { | ||
t.Fatal("failed to close temp file " + auth_email_file.Name() + | ||
": " + err.Error()) | ||
} | ||
|
||
domains := []string{"Frobozz.Com"} | ||
validator := NewValidator(domains, auth_email_file.Name()) | ||
|
||
if !validator("foo.bar@example.com") { | ||
t.Error("loaded email addresses are not lower-cased") | ||
} | ||
if !validator("Foo.Bar@Example.Com") { | ||
t.Error("validated email addresses are not lower-cased") | ||
} | ||
if !validator("foo.bar@frobozz.com") { | ||
t.Error("loaded domains are not lower-cased") | ||
} | ||
if !validator("foo.bar@Frobozz.Com") { | ||
t.Error("validated domains are not lower-cased") | ||
} | ||
} |