aboutsummaryrefslogtreecommitdiff
path: root/server/auth/google/google_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/auth/google/google_test.go')
-rw-r--r--server/auth/google/google_test.go45
1 files changed, 30 insertions, 15 deletions
diff --git a/server/auth/google/google_test.go b/server/auth/google/google_test.go
index 781cf6f..b3d2633 100644
--- a/server/auth/google/google_test.go
+++ b/server/auth/google/google_test.go
@@ -4,7 +4,6 @@ import (
"fmt"
"testing"
- "github.com/nsheridan/cashier/server/auth"
"github.com/nsheridan/cashier/server/config"
"github.com/stretchr/testify/assert"
)
@@ -14,27 +13,42 @@ var (
oauthClientSecret = "secret"
oauthCallbackURL = "url"
domain = "example.com"
+ users = []string{"user"}
)
func TestNew(t *testing.T) {
a := assert.New(t)
-
- p, _ := newGoogle()
- g := p.(*Config)
- a.Equal(g.config.ClientID, oauthClientID)
- a.Equal(g.config.ClientSecret, oauthClientSecret)
- a.Equal(g.config.RedirectURL, oauthCallbackURL)
- a.Equal(g.domain, domain)
+ p, err := newGoogle()
+ a.NoError(err)
+ a.Equal(p.config.ClientID, oauthClientID)
+ a.Equal(p.config.ClientSecret, oauthClientSecret)
+ a.Equal(p.config.RedirectURL, oauthCallbackURL)
+ a.Equal(p.domain, domain)
+ a.Equal(p.whitelist, map[string]bool{"user": true})
}
-func TestNewWithoutDomain(t *testing.T) {
- domain = ""
-
- if _, err := newGoogle(); err == nil {
+func TestWhitelist(t *testing.T) {
+ c := &config.Auth{
+ OauthClientID: oauthClientID,
+ OauthClientSecret: oauthClientSecret,
+ OauthCallbackURL: oauthCallbackURL,
+ ProviderOpts: map[string]string{"domain": ""},
+ UsersWhitelist: []string{},
+ }
+ if _, err := New(c); err == nil {
t.Error("creating a provider without a domain set should return an error")
}
-
- domain = "example.com"
+ // Set a user whitelist but no domain
+ c.UsersWhitelist = users
+ if _, err := New(c); err != nil {
+ t.Error("creating a provider with users but no domain should not return an error")
+ }
+ // Unset the user whitelist and set a domain
+ c.UsersWhitelist = []string{}
+ c.ProviderOpts = map[string]string{"domain": domain}
+ if _, err := New(c); err != nil {
+ t.Error("creating a provider with a domain set but without a user whitelist should not return an error")
+ }
}
func TestStartSession(t *testing.T) {
@@ -49,12 +63,13 @@ func TestStartSession(t *testing.T) {
a.Contains(s.AuthURL, fmt.Sprintf("client_id=%s", oauthClientID))
}
-func newGoogle() (auth.Provider, error) {
+func newGoogle() (*Config, error) {
c := &config.Auth{
OauthClientID: oauthClientID,
OauthClientSecret: oauthClientSecret,
OauthCallbackURL: oauthCallbackURL,
ProviderOpts: map[string]string{"domain": domain},
+ UsersWhitelist: users,
}
return New(c)
}