fix: tests
This commit is contained in:
parent
4eb2c4e270
commit
476a198f27
2 changed files with 55 additions and 15 deletions
|
@ -160,98 +160,98 @@ func TestValidateAuthReqRedirectURI(t *testing.T) {
|
||||||
{
|
{
|
||||||
"empty fails",
|
"empty fails",
|
||||||
args{"",
|
args{"",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unregistered fails",
|
"unregistered fails",
|
||||||
args{"https://unregistered.com/callback",
|
args{"https://unregistered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http not confidential fails",
|
"code flow registered http not confidential fails",
|
||||||
args{"http://registered.com/callback",
|
args{"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered http confidential ok",
|
"code flow registered http confidential ok",
|
||||||
args{"http://registered.com/callback",
|
args{"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeWeb, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeWeb, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered custom not native fails",
|
"code flow registered custom not native fails",
|
||||||
args{"custom://callback",
|
args{"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeUserAgent, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow registered custom native ok",
|
"code flow registered custom native ok",
|
||||||
args{"custom://callback",
|
args{"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"code flow dev mode http ok",
|
"code flow dev mode http ok",
|
||||||
args{"http://registered.com/callback",
|
args{"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, true),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, true),
|
||||||
oidc.ResponseTypeCode},
|
oidc.ResponseTypeCode},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered ok",
|
"implicit flow registered ok",
|
||||||
args{"https://registered.com/callback",
|
args{"https://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow unregistered ok",
|
"implicit flow unregistered ok",
|
||||||
args{"https://unregistered.com/callback",
|
args{"https://unregistered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, false),
|
mock.NewClientWithConfig(t, []string{"https://registered.com/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered http localhost native ok",
|
"implicit flow registered http localhost native ok",
|
||||||
args{"http://localhost:9999/callback",
|
args{"http://localhost:9999/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeNative, false),
|
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow registered http localhost user agent fails",
|
"implicit flow registered http localhost user agent fails",
|
||||||
args{"http://localhost:9999/callback",
|
args{"http://localhost:9999/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeUserAgent, false),
|
mock.NewClientWithConfig(t, []string{"http://localhost:9999/callback"}, op.ApplicationTypeUserAgent, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow http non localhost fails",
|
"implicit flow http non localhost fails",
|
||||||
args{"http://registered.com/callback",
|
args{"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, false),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow custom fails",
|
"implicit flow custom fails",
|
||||||
args{"custom://callback",
|
args{"custom://callback",
|
||||||
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, false),
|
mock.NewClientWithConfig(t, []string{"custom://callback"}, op.ApplicationTypeNative, nil, false),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"implicit flow dev mode http ok",
|
"implicit flow dev mode http ok",
|
||||||
args{"http://registered.com/callback",
|
args{"http://registered.com/callback",
|
||||||
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, true),
|
mock.NewClientWithConfig(t, []string{"http://registered.com/callback"}, op.ApplicationTypeNative, nil, true),
|
||||||
oidc.ResponseTypeIDToken},
|
oidc.ResponseTypeIDToken},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -265,6 +265,44 @@ func TestValidateAuthReqRedirectURI(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateAuthReqResponseType(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
responseType oidc.ResponseType
|
||||||
|
client op.Client
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"empty response type",
|
||||||
|
args{"",
|
||||||
|
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true)},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"response type missing in client config",
|
||||||
|
args{oidc.ResponseTypeIDToken,
|
||||||
|
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true)},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"valid response type",
|
||||||
|
args{oidc.ResponseTypeCode,
|
||||||
|
mock.NewClientWithConfig(t, nil, op.ApplicationTypeNative, []oidc.ResponseType{oidc.ResponseTypeCode}, true)},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if err := op.ValidateAuthReqResponseType(tt.args.client, tt.args.responseType); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("ValidateAuthReqScopes() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRedirectToLogin(t *testing.T) {
|
func TestRedirectToLogin(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
authReqID string
|
authReqID string
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package mock
|
package mock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/caos/oidc/pkg/oidc"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
@ -28,11 +29,12 @@ func NewClientExpectAny(t *testing.T, appType op.ApplicationType) op.Client {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientWithConfig(t *testing.T, uri []string, appType op.ApplicationType, devMode bool) op.Client {
|
func NewClientWithConfig(t *testing.T, uri []string, appType op.ApplicationType, responseTypes []oidc.ResponseType, devMode bool) op.Client {
|
||||||
c := NewClient(t)
|
c := NewClient(t)
|
||||||
m := c.(*MockClient)
|
m := c.(*MockClient)
|
||||||
m.EXPECT().RedirectURIs().AnyTimes().Return(uri)
|
m.EXPECT().RedirectURIs().AnyTimes().Return(uri)
|
||||||
m.EXPECT().ApplicationType().AnyTimes().Return(appType)
|
m.EXPECT().ApplicationType().AnyTimes().Return(appType)
|
||||||
|
m.EXPECT().ResponseTypes().AnyTimes().Return(responseTypes)
|
||||||
m.EXPECT().DevMode().AnyTimes().Return(devMode)
|
m.EXPECT().DevMode().AnyTimes().Return(devMode)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue