authreq
This commit is contained in:
parent
d1d04295a6
commit
8ee38d2ec8
14 changed files with 469 additions and 85 deletions
|
@ -1,11 +1,13 @@
|
|||
package mock
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/oidc/pkg/oidc"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
||||
"github.com/caos/oidc/pkg/oidc"
|
||||
"github.com/caos/oidc/pkg/op"
|
||||
)
|
||||
|
||||
|
@ -19,6 +21,12 @@ func NewMockStorageExpectValidClientID(t *testing.T) op.Storage {
|
|||
return m
|
||||
}
|
||||
|
||||
func NewMockStorageExpectInvalidClientID(t *testing.T) op.Storage {
|
||||
m := NewStorage(t)
|
||||
ExpectInvalidClientID(m)
|
||||
return m
|
||||
}
|
||||
|
||||
func NewMockStorageAny(t *testing.T) op.Storage {
|
||||
m := NewStorage(t)
|
||||
mockS := m.(*MockStorage)
|
||||
|
@ -27,19 +35,36 @@ func NewMockStorageAny(t *testing.T) op.Storage {
|
|||
return m
|
||||
}
|
||||
|
||||
func ExpectInvalidClientID(s op.Storage) {
|
||||
mockS := s.(*MockStorage)
|
||||
mockS.EXPECT().GetClientByClientID(gomock.Any()).Return(nil, errors.New("client not found"))
|
||||
}
|
||||
|
||||
func ExpectValidClientID(s op.Storage) {
|
||||
mockS := s.(*MockStorage)
|
||||
mockS.EXPECT().GetClientByClientID(gomock.Any()).Return(&ConfClient{}, nil)
|
||||
mockS.EXPECT().GetClientByClientID(gomock.Any()).DoAndReturn(
|
||||
func(id string) (oidc.Client, error) {
|
||||
var appType oidc.ApplicationType
|
||||
switch id {
|
||||
case "web_client":
|
||||
appType = oidc.ApplicationTypeWeb
|
||||
case "native_client":
|
||||
appType = oidc.ApplicationTypeNative
|
||||
case "useragent_client":
|
||||
appType = oidc.ApplicationTypeUserAgent
|
||||
}
|
||||
return &ConfClient{appType: appType}, nil
|
||||
})
|
||||
}
|
||||
|
||||
type ConfClient struct{}
|
||||
|
||||
func (c *ConfClient) Type() oidc.ClientType {
|
||||
return oidc.ClientTypeConfidential
|
||||
type ConfClient struct {
|
||||
appType oidc.ApplicationType
|
||||
}
|
||||
|
||||
func (c *ConfClient) RedirectURIs() []string {
|
||||
return []string{
|
||||
"https://registered.com/callback",
|
||||
"http://registered.com/callback",
|
||||
"http://localhost:9999/callback",
|
||||
"custom://callback",
|
||||
}
|
||||
|
@ -48,3 +73,7 @@ func (c *ConfClient) RedirectURIs() []string {
|
|||
func (c *ConfClient) LoginURL(id string) string {
|
||||
return "login?id=" + id
|
||||
}
|
||||
|
||||
func (c *ConfClient) ApplicationType() oidc.ApplicationType {
|
||||
return c.appType
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue