aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-04-20 00:57:46 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-04-20 00:57:46 +0100
commit33d76216e8fc8742c06cf3416ad47fff5b1957c0 (patch)
tree712ab0be3f62caf5464b6a756c1f43c55c69d301 /server
parentf95b916652bf0cd02da0daedf6bfc647d4b32ca7 (diff)
dumb tests for the google auth provider
Diffstat (limited to 'server')
-rw-r--r--server/auth/google/google_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/server/auth/google/google_test.go b/server/auth/google/google_test.go
new file mode 100644
index 0000000..489aa1a
--- /dev/null
+++ b/server/auth/google/google_test.go
@@ -0,0 +1,51 @@
+package google
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/nsheridan/cashier/server/auth"
+ "github.com/nsheridan/cashier/server/config"
+ "github.com/stretchr/testify/assert"
+)
+
+var (
+ oauthClientID = "id"
+ oauthClientSecret = "secret"
+ oauthCallbackURL = "url"
+ domain = "example.com"
+)
+
+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)
+}
+
+func TestStartSession(t *testing.T) {
+ a := assert.New(t)
+
+ p := newGoogle()
+ s := p.StartSession("test_state")
+ a.Equal(s.State, "test_state")
+ a.Contains(s.AuthURL, "accounts.google.com/o/oauth2/auth")
+ a.Contains(s.AuthURL, "state=test_state")
+ a.Contains(s.AuthURL, fmt.Sprintf("hd=%s", domain))
+ a.Contains(s.AuthURL, fmt.Sprintf("client_id=%s", oauthClientID))
+}
+
+func newGoogle() auth.Provider {
+ c := &config.Auth{
+ OauthClientID: oauthClientID,
+ OauthClientSecret: oauthClientSecret,
+ OauthCallbackURL: oauthCallbackURL,
+ GoogleOpts: make(map[string]interface{}),
+ }
+ c.GoogleOpts["domain"] = domain
+ return New(c)
+}