| 1 |
package google_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config" |
| 8 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/providers/google" |
| 9 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/types" |
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
) |
| 12 |
|
| 13 |
func TestProviderBasics(t *testing.T) { |
| 14 |
t.Parallel() |
| 15 |
|
| 16 |
provider, err := google.NewProvider(t.Context(), new(config.Defaults), http.DefaultClient) |
| 17 |
require.NoError(t, err) |
| 18 |
require.Equal(t, google.Name, provider.GetName()) |
| 19 |
|
| 20 |
providerConfig, err := provider.GetProviderConfig() |
| 21 |
require.NoError(t, err) |
| 22 |
require.Equal(t, []string{types.ScopeEmail, types.ScopeProfile, types.ScopeOpenID}, providerConfig.Scopes) |
| 23 |
require.Empty(t, providerConfig.AuthCodeOptions) |
| 24 |
} |
| 25 |
|
| 26 |
func TestGetProviderConfigWithRefreshValidation(t *testing.T) { |
| 27 |
t.Parallel() |
| 28 |
|
| 29 |
conf := config.Defaults |
| 30 |
conf.OAuth2.Refresh.Enabled = true |
| 31 |
conf.OAuth2.Refresh.ValidateUser = true |
| 32 |
|
| 33 |
provider, err := google.NewProvider(t.Context(), &conf, http.DefaultClient) |
| 34 |
require.NoError(t, err) |
| 35 |
|
| 36 |
providerConfig, err := provider.GetProviderConfig() |
| 37 |
require.NoError(t, err) |
| 38 |
require.Len(t, providerConfig.AuthCodeOptions, 2) |
| 39 |
} |
| 40 |
|
| 41 |
func TestGetProviderConfigWithGroupValidation(t *testing.T) { |
| 42 |
t.Parallel() |
| 43 |
|
| 44 |
conf := config.Defaults |
| 45 |
conf.OAuth2.Validate.Groups = []string{"group-id"} |
| 46 |
|
| 47 |
provider, err := google.NewProvider(t.Context(), &conf, http.DefaultClient) |
| 48 |
require.NoError(t, err) |
| 49 |
|
| 50 |
providerConfig, err := provider.GetProviderConfig() |
| 51 |
require.NoError(t, err) |
| 52 |
require.Contains(t, providerConfig.Scopes, "https://www.googleapis.com/auth/cloud-identity.groups.readonly") |
| 53 |
} |