From 2ce3b86e0ff69538935db3149d1ed2f24aea09a3 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Mon, 13 Apr 2020 23:57:13 -0400 Subject: Simplify --- server/auth/gitlab/gitlab_test.go | 98 --------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 server/auth/gitlab/gitlab_test.go (limited to 'server/auth/gitlab/gitlab_test.go') diff --git a/server/auth/gitlab/gitlab_test.go b/server/auth/gitlab/gitlab_test.go deleted file mode 100644 index 93b348b..0000000 --- a/server/auth/gitlab/gitlab_test.go +++ /dev/null @@ -1,98 +0,0 @@ -package gitlab - -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" - allusers = "" - siteurl = "https://exampleorg/" - group = "exampleorg" -) - -func TestNew(t *testing.T) { - a := assert.New(t) - - p, _ := newGitlab() - g := p.(*Config) - a.Equal(g.config.ClientID, oauthClientID) - a.Equal(g.config.ClientSecret, oauthClientSecret) - a.Equal(g.config.RedirectURL, oauthCallbackURL) -} - -func TestNewBrokenSiteURL(t *testing.T) { - siteurl = "https://exampleorg" - a := assert.New(t) - - _, err := newGitlab() - a.EqualError(err, "gitlab_opts siteurl must end in /") - - siteurl = "https://exampleorg/" -} - -func TestBadAllUsers(t *testing.T) { - allusers = "true" - siteurl = "" - a := assert.New(t) - - _, err := newGitlab() - a.EqualError(err, "gitlab_opts if allusers is set, siteurl must be set") - - allusers = "" - siteurl = "https://exampleorg/" -} - -func TestGoodAllUsers(t *testing.T) { - allusers = "true" - a := assert.New(t) - - p, _ := newGitlab() - s := p.StartSession("test_state") - a.Contains(s, "exampleorg/oauth/authorize") - a.Contains(s, "state=test_state") - a.Contains(s, fmt.Sprintf("client_id=%s", oauthClientID)) - - allusers = "" -} - -func TestNewEmptyGroupList(t *testing.T) { - group = "" - a := assert.New(t) - - _, err := newGitlab() - a.EqualError(err, "gitlab_opts group and the users whitelist must not be both empty if allusers isn't true") - - group = "exampleorg" -} - -func TestStartSession(t *testing.T) { - a := assert.New(t) - - p, _ := newGitlab() - s := p.StartSession("test_state") - a.Contains(s, "exampleorg/oauth/authorize") - a.Contains(s, "state=test_state") - a.Contains(s, fmt.Sprintf("client_id=%s", oauthClientID)) -} - -func newGitlab() (auth.Provider, error) { - c := &config.Auth{ - OauthClientID: oauthClientID, - OauthClientSecret: oauthClientSecret, - OauthCallbackURL: oauthCallbackURL, - ProviderOpts: map[string]string{ - "group": group, - "siteurl": siteurl, - "allusers": allusers, - }, - } - return New(c) -} -- cgit v1.2.3