packaging and much more

This commit is contained in:
Livio Amstutz 2019-11-29 13:31:55 +01:00
parent 988a556fa9
commit 201109f9c2
29 changed files with 356 additions and 272 deletions

View file

@ -6,27 +6,27 @@ import (
"github.com/golang/mock/gomock"
"github.com/caos/oidc/pkg/oidc"
u "github.com/caos/oidc/pkg/op/u"
"github.com/caos/oidc/pkg/op"
op2 "github.com/caos/oidc/pkg/op"
)
func NewStorage(t *testing.T) u.Storage {
func NewStorage(t *testing.T) op2.Storage {
return NewMockStorage(gomock.NewController(t))
}
func NewMockStorageExpectValidClientID(t *testing.T) u.Storage {
func NewMockStorageExpectValidClientID(t *testing.T) op2.Storage {
m := NewStorage(t)
ExpectValidClientID(m)
return m
}
func NewMockStorageExpectInvalidClientID(t *testing.T) u.Storage {
func NewMockStorageExpectInvalidClientID(t *testing.T) op2.Storage {
m := NewStorage(t)
ExpectInvalidClientID(m)
return m
}
func NewMockStorageAny(t *testing.T) u.Storage {
func NewMockStorageAny(t *testing.T) op2.Storage {
m := NewStorage(t)
mockS := m.(*MockStorage)
mockS.EXPECT().GetClientByClientID(gomock.Any()).AnyTimes().Return(&ConfClient{}, nil)
@ -34,30 +34,30 @@ func NewMockStorageAny(t *testing.T) u.Storage {
return m
}
func ExpectInvalidClientID(s u.Storage) {
func ExpectInvalidClientID(s op2.Storage) {
mockS := s.(*MockStorage)
mockS.EXPECT().GetClientByClientID(gomock.Any()).Return(nil, errors.New("client not found"))
}
func ExpectValidClientID(s u.Storage) {
func ExpectValidClientID(s op2.Storage) {
mockS := s.(*MockStorage)
mockS.EXPECT().GetClientByClientID(gomock.Any()).DoAndReturn(
func(id string) (oidc.Client, error) {
var appType oidc.ApplicationType
func(id string) (op.Client, error) {
var appType op.ApplicationType
switch id {
case "web_client":
appType = oidc.ApplicationTypeWeb
appType = op.ApplicationTypeWeb
case "native_client":
appType = oidc.ApplicationTypeNative
appType = op.ApplicationTypeNative
case "useragent_client":
appType = oidc.ApplicationTypeUserAgent
appType = op.ApplicationTypeUserAgent
}
return &ConfClient{appType: appType}, nil
})
}
type ConfClient struct {
appType oidc.ApplicationType
appType op.ApplicationType
}
func (c *ConfClient) RedirectURIs() []string {
@ -73,6 +73,6 @@ func (c *ConfClient) LoginURL(id string) string {
return "login?id=" + id
}
func (c *ConfClient) ApplicationType() oidc.ApplicationType {
func (c *ConfClient) ApplicationType() op.ApplicationType {
return c.appType
}