Fix tests
This commit is contained in:
parent
58bc09833e
commit
7bbe01fe97
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
|
|
||||||
|
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
|
@ -39,7 +37,7 @@ func newCidaasProvider(serverURL *url.URL) *CIDAASProvider {
|
||||||
Scheme: serverURL.Scheme,
|
Scheme: serverURL.Scheme,
|
||||||
Host: serverURL.Host,
|
Host: serverURL.Host,
|
||||||
Path: "/api"},
|
Path: "/api"},
|
||||||
Scope: "openid profile offline_access",
|
Scope: "openid profile offline_access roles groups",
|
||||||
EmailClaim: "email",
|
EmailClaim: "email",
|
||||||
GroupsClaim: "groups",
|
GroupsClaim: "groups",
|
||||||
Verifier: oidc.NewVerifier(
|
Verifier: oidc.NewVerifier(
|
||||||
|
|
@ -49,7 +47,7 @@ func newCidaasProvider(serverURL *url.URL) *CIDAASProvider {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
p := NewCIDAASProvider(providerData, options.CidaasOptions{})
|
p := NewCIDAASProvider(providerData)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +77,6 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
ExistingSession *sessions.SessionState
|
ExistingSession *sessions.SessionState
|
||||||
EmailClaim string
|
EmailClaim string
|
||||||
GroupsClaim string
|
GroupsClaim string
|
||||||
FilterGroups FilterGroups
|
|
||||||
ProfileJSON map[string]interface{}
|
ProfileJSON map[string]interface{}
|
||||||
ExpectedError error
|
ExpectedError error
|
||||||
ExpectedSession *sessions.SessionState
|
ExpectedSession *sessions.SessionState
|
||||||
|
|
@ -240,13 +237,13 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
"email": "already@populated.com",
|
"email": "already@populated.com",
|
||||||
"groups2": []map[string]interface{}{
|
"groups2": []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"sub": "aa4980ee-0939-4ea7-b67f-81883f143d39",
|
"sub": "aa5181ea-0841-4ea7-b67f-81882f153d40",
|
||||||
"groupId": "CIDAAS_ADMINS",
|
"groupId": "CIDAAS_ADMINS",
|
||||||
"path": "/CIDAAS_ADMINS/",
|
"path": "/CIDAAS_ADMINS/",
|
||||||
"roles": []string{"ADMIN"},
|
"roles": []string{"ADMIN"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sub": "aa4980ee-0939-4ea7-b67f-81883f143d39",
|
"sub": "aa5181ea-0841-4ea7-b67f-81882f153d39",
|
||||||
"groupId": "customers",
|
"groupId": "customers",
|
||||||
"groupType": "Customers",
|
"groupType": "Customers",
|
||||||
"path": "/customers/",
|
"path": "/customers/",
|
||||||
|
|
@ -272,7 +269,7 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
RefreshToken: refreshToken,
|
RefreshToken: refreshToken,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Filter Groups": {
|
"Just format Groups": {
|
||||||
ExistingSession: &sessions.SessionState{
|
ExistingSession: &sessions.SessionState{
|
||||||
User: "already",
|
User: "already",
|
||||||
Email: "already@populated.com",
|
Email: "already@populated.com",
|
||||||
|
|
@ -283,18 +280,11 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
},
|
},
|
||||||
EmailClaim: "email",
|
EmailClaim: "email",
|
||||||
GroupsClaim: "groups2",
|
GroupsClaim: "groups2",
|
||||||
FilterGroups: []string{"customers"},
|
|
||||||
ProfileJSON: map[string]interface{}{
|
ProfileJSON: map[string]interface{}{
|
||||||
"email": "already@populated.com",
|
"email": "already@populated.com",
|
||||||
"groups2": []map[string]interface{}{
|
"groups2": []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"sub": "aa4980ee-0939-4ea7-b67f-81883f143d39",
|
"sub": "aa5181ea-0841-4ea7-b67f-81882f153d39",
|
||||||
"groupId": "CIDAAS_ADMINS",
|
|
||||||
"path": "/CIDAAS_ADMINS/",
|
|
||||||
"roles": []string{"ADMIN"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"sub": "aa4980ee-0939-4ea7-b67f-81883f143d39",
|
|
||||||
"groupId": "customers",
|
"groupId": "customers",
|
||||||
"groupType": "Customers",
|
"groupType": "Customers",
|
||||||
"path": "/customers/",
|
"path": "/customers/",
|
||||||
|
|
@ -314,7 +304,7 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
ExpectedSession: &sessions.SessionState{
|
ExpectedSession: &sessions.SessionState{
|
||||||
User: "already",
|
User: "already",
|
||||||
Email: "already@populated.com",
|
Email: "already@populated.com",
|
||||||
Groups: []string{"customers:CUSTOMER_ACCOUNT_LOGIN", "customers:GROUP_ADMIN"},
|
Groups: []string{"customers:CUSTOMER_ACCOUNT_LOGIN", "customers:GROUP_ADMIN", "CIDAAS_USERS:USER", "cidaas:USER"},
|
||||||
IDToken: idToken,
|
IDToken: idToken,
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
RefreshToken: refreshToken,
|
RefreshToken: refreshToken,
|
||||||
|
|
@ -334,13 +324,13 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
ProfileJSON: map[string]interface{}{
|
ProfileJSON: map[string]interface{}{
|
||||||
"groups": []map[string]interface{}{
|
"groups": []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"sub": "aa4980ee-0939-4ea7-b67f-81883f143d39",
|
"sub": "aa5181ea-0841-4ea7-b67f-81882f153d40",
|
||||||
"groupId": "CIDAAS_ADMINS",
|
"groupId": "CIDAAS_ADMINS",
|
||||||
"path": "/CIDAAS_ADMINS/",
|
"path": "/CIDAAS_ADMINS/",
|
||||||
"roles": []string{"ADMIN"},
|
"roles": []string{"ADMIN"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sub": "aa4980ee-0939-4ea7-b67f-81883f143d39",
|
"sub": "aa5181ea-0841-4ea7-b67f-81882f153d39",
|
||||||
"groupId": "customers",
|
"groupId": "customers",
|
||||||
"groupType": "Customers",
|
"groupType": "Customers",
|
||||||
"path": "/customers/",
|
"path": "/customers/",
|
||||||
|
|
@ -401,7 +391,6 @@ func TestCidaasProvider_EnrichSession(t *testing.T) {
|
||||||
|
|
||||||
provider.EmailClaim = tc.EmailClaim
|
provider.EmailClaim = tc.EmailClaim
|
||||||
provider.GroupsClaim = tc.GroupsClaim
|
provider.GroupsClaim = tc.GroupsClaim
|
||||||
provider.FilterGroups = tc.FilterGroups
|
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
err = provider.EnrichSession(context.Background(), tc.ExistingSession)
|
err = provider.EnrichSession(context.Background(), tc.ExistingSession)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ func NewProvider(providerConfig options.Provider) (Provider, error) {
|
||||||
case options.OIDCProvider:
|
case options.OIDCProvider:
|
||||||
return NewOIDCProvider(providerData, providerConfig.OIDCConfig), nil
|
return NewOIDCProvider(providerData, providerConfig.OIDCConfig), nil
|
||||||
case options.CidaasProvider:
|
case options.CidaasProvider:
|
||||||
return NewCIDAASProvider(providerData, providerConfig.CidaasConfig), nil
|
return NewCIDAASProvider(providerData), nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown provider type %q", providerConfig.Type)
|
return nil, fmt.Errorf("unknown provider type %q", providerConfig.Type)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue