-
Notifications
You must be signed in to change notification settings - Fork 331
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
1 parent
5f336c4
commit f95f2ad
Showing
2 changed files
with
57 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package domains | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
|
||
"github.com/vouch/vouch-proxy/pkg/cfg" | ||
) | ||
|
||
func init() { | ||
cfg.InitForTestPurposes() | ||
cfg.Cfg.Domains = []string{"vouch.github.io", "sub.test.mydomain.com", "test.mydomain.com"} | ||
Refresh() | ||
} | ||
|
||
func TestIsUnderManagement(t *testing.T) { | ||
assert.True(t, IsUnderManagement("[email protected]")) | ||
assert.True(t, IsUnderManagement("[email protected]")) | ||
assert.True(t, IsUnderManagement("[email protected]")) | ||
assert.True(t, IsUnderManagement("[email protected]")) | ||
|
||
assert.False(t, IsUnderManagement("[email protected]")) | ||
assert.False(t, IsUnderManagement("[email protected]")) | ||
assert.False(t, IsUnderManagement("[email protected]")) | ||
assert.False(t, IsUnderManagement("[email protected]")) | ||
} | ||
|
||
func TestMatches(t *testing.T) { | ||
// Full email should not be accepted | ||
assert.Equal(t, "", Matches("[email protected]")) | ||
|
||
assert.Equal(t, "vouch.github.io", Matches("vouch.github.io")) | ||
assert.Equal(t, "vouch.github.io", Matches("sub.vouch.github.io")) | ||
assert.Equal(t, "", Matches("a-different-vouch.github.io")) | ||
|
||
assert.Equal(t, "", Matches("mydomain.com")) | ||
|
||
assert.Equal(t, "test.mydomain.com", Matches("test.mydomain.com")) | ||
assert.Equal(t, "sub.test.mydomain.com", Matches("sub.test.mydomain.com")) | ||
assert.Equal(t, "sub.test.mydomain.com", Matches("subsub.sub.test.mydomain.com")) | ||
assert.Equal(t, "test.mydomain.com", Matches("other.test.mydomain.com")) | ||
} |