Repository navigation
Expand file tree
/
Copy pathoidc_test.go
More file actions
67 lines (53 loc) · 2 KB
/
Copy pathoidc_test.go
File metadata and controls
67 lines (53 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package oidc
import (
"encoding/json"
"io/ioutil"
"net/url"
"testing"
"golang.org/x/oauth2"
"github.com/stretchr/testify/assert"
"github.com/argoproj/argo-cd/server/settings/oidc"
)
func TestInferGrantType(t *testing.T) {
for _, path := range []string{"dex", "okta", "auth0", "onelogin"} {
t.Run(path, func(t *testing.T) {
rawConfig, err := ioutil.ReadFile("testdata/" + path + ".json")
assert.NoError(t, err)
var config OIDCConfiguration
err = json.Unmarshal(rawConfig, &config)
assert.NoError(t, err)
grantType := InferGrantType(&config)
assert.Equal(t, GrantTypeAuthorizationCode, grantType)
var noCodeResponseTypes []string
for _, supportedResponseType := range config.ResponseTypesSupported {
if supportedResponseType != ResponseTypeCode {
noCodeResponseTypes = append(noCodeResponseTypes, supportedResponseType)
}
}
config.ResponseTypesSupported = noCodeResponseTypes
grantType = InferGrantType(&config)
assert.Equal(t, GrantTypeImplicit, grantType)
})
}
}
func TestIDTokenClaims(t *testing.T) {
oauth2Config := &oauth2.Config{
ClientID: "DUMMY_OIDC_PROVIDER",
ClientSecret: "0987654321",
Endpoint: oauth2.Endpoint{AuthURL: "https://argocd-dev.onelogin.com/oidc/auth", TokenURL: "https://argocd-dev.onelogin.com/oidc/token"},
Scopes: []string{"oidc", "profile", "groups"},
RedirectURL: "https://argocd-dev.io/redirect_url",
}
var opts []oauth2.AuthCodeOption
requestedClaims := make(map[string]*oidc.Claim)
opts = AppendClaimsAuthenticationRequestParameter(opts, requestedClaims)
assert.Len(t, opts, 0)
requestedClaims["groups"] = &oidc.Claim{Essential: true}
opts = AppendClaimsAuthenticationRequestParameter(opts, requestedClaims)
assert.Len(t, opts, 1)
authCodeURL, err := url.Parse(oauth2Config.AuthCodeURL("TEST", opts...))
assert.NoError(t, err)
values, err := url.ParseQuery(authCodeURL.RawQuery)
assert.NoError(t, err)
assert.Equal(t, "{\"id_token\":{\"groups\":{\"essential\":true}}}", values.Get("claims"))
}