1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-08-08 22:46:33 +02:00

Streamline Google to use default Authorize

This commit is contained in:
Nick Meves
2020-09-26 19:24:06 -07:00
parent eb58ea2ed9
commit b92fd4b0bb
6 changed files with 40 additions and 44 deletions

View File

@ -10,7 +10,7 @@ import (
"net/url"
"testing"
"github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
admin "google.golang.org/api/admin/directory/v1"
@ -110,19 +110,19 @@ func TestGoogleProviderGetEmailAddress(t *testing.T) {
assert.Equal(t, "refresh12345", session.RefreshToken)
}
func TestGoogleProviderAuthorize(t *testing.T) {
func TestGoogleProviderGroupValidator(t *testing.T) {
const sessionEmail = "michael.bland@gsa.gov"
testCases := map[string]struct {
session *sessions.SessionState
validatorFunc func(*sessions.SessionState, bool) bool
validatorFunc func(*sessions.SessionState) bool
expectedAuthZ bool
}{
"Email is authorized with GroupValidator": {
session: &sessions.SessionState{
Email: sessionEmail,
},
validatorFunc: func(s *sessions.SessionState, _ bool) bool {
validatorFunc: func(s *sessions.SessionState) bool {
return s.Email == sessionEmail
},
expectedAuthZ: true,
@ -131,7 +131,7 @@ func TestGoogleProviderAuthorize(t *testing.T) {
session: &sessions.SessionState{
Email: sessionEmail,
},
validatorFunc: func(s *sessions.SessionState, _ bool) bool {
validatorFunc: func(s *sessions.SessionState) bool {
return s.Email != sessionEmail
},
expectedAuthZ: false,
@ -151,9 +151,7 @@ func TestGoogleProviderAuthorize(t *testing.T) {
if tc.validatorFunc != nil {
p.GroupValidator = tc.validatorFunc
}
authorized, err := p.Authorize(context.Background(), tc.session)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(authorized).To(Equal(tc.expectedAuthZ))
g.Expect(p.GroupValidator(tc.session)).To(Equal(tc.expectedAuthZ))
})
}
}