aboutsummaryrefslogtreecommitdiff
path: root/server/auth/github/github_test.go
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-04-22 23:01:32 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-04-22 23:16:11 +0100
commitbd1e6a57fe354ccfe51d295fec3c06a1c878c3f7 (patch)
tree8741e4537293221e64d5bf9dc6df3b9fb8816bc6 /server/auth/github/github_test.go
parent5a57870d808f1601d85a35d08429b9ae19dafe93 (diff)
Add github oauth provider.
Diffstat (limited to 'server/auth/github/github_test.go')
-rw-r--r--server/auth/github/github_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/server/auth/github/github_test.go b/server/auth/github/github_test.go
new file mode 100644
index 0000000..383642f
--- /dev/null
+++ b/server/auth/github/github_test.go
@@ -0,0 +1,49 @@
+package github
+
+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"
+ organization = "exampleorg"
+)
+
+func TestNew(t *testing.T) {
+ a := assert.New(t)
+
+ p := newGithub()
+ g := p.(*Config)
+ a.Equal(g.config.ClientID, oauthClientID)
+ a.Equal(g.config.ClientSecret, oauthClientSecret)
+ a.Equal(g.config.RedirectURL, oauthCallbackURL)
+ a.Equal(g.organization, organization)
+}
+
+func TestStartSession(t *testing.T) {
+ a := assert.New(t)
+
+ p := newGithub()
+ s := p.StartSession("test_state")
+ a.Equal(s.State, "test_state")
+ a.Contains(s.AuthURL, "github.com/login/oauth/authorize")
+ a.Contains(s.AuthURL, "state=test_state")
+ a.Contains(s.AuthURL, fmt.Sprintf("client_id=%s", oauthClientID))
+}
+
+func newGithub() auth.Provider {
+ c := &config.Auth{
+ OauthClientID: oauthClientID,
+ OauthClientSecret: oauthClientSecret,
+ OauthCallbackURL: oauthCallbackURL,
+ ProviderOpts: map[string]string{"organization": organization},
+ }
+ return New(c)
+}