packaging and much more
This commit is contained in:
parent
988a556fa9
commit
201109f9c2
29 changed files with 356 additions and 272 deletions
|
@ -5,11 +5,9 @@
|
|||
package mock
|
||||
|
||||
import (
|
||||
oidc "github.com/caos/oidc/pkg/oidc"
|
||||
u "github.com/caos/oidc/pkg/op/u"
|
||||
op "github.com/caos/oidc/pkg/op"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
schema "github.com/gorilla/schema"
|
||||
http "net/http"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
|
@ -64,39 +62,25 @@ func (mr *MockAuthorizerMockRecorder) Encoder() *gomock.Call {
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Encoder", reflect.TypeOf((*MockAuthorizer)(nil).Encoder))
|
||||
}
|
||||
|
||||
// ErrorHandler mocks base method
|
||||
func (m *MockAuthorizer) ErrorHandler() func(http.ResponseWriter, *http.Request, *oidc.AuthRequest, error) {
|
||||
// Signer mocks base method
|
||||
func (m *MockAuthorizer) Signer() op.Signer {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ErrorHandler")
|
||||
ret0, _ := ret[0].(func(http.ResponseWriter, *http.Request, *oidc.AuthRequest, error))
|
||||
ret := m.ctrl.Call(m, "Signer")
|
||||
ret0, _ := ret[0].(op.Signer)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ErrorHandler indicates an expected call of ErrorHandler
|
||||
func (mr *MockAuthorizerMockRecorder) ErrorHandler() *gomock.Call {
|
||||
// Signer indicates an expected call of Signer
|
||||
func (mr *MockAuthorizerMockRecorder) Signer() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ErrorHandler", reflect.TypeOf((*MockAuthorizer)(nil).ErrorHandler))
|
||||
}
|
||||
|
||||
// Signe mocks base method
|
||||
func (m *MockAuthorizer) Signe() u.Signer {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Signe")
|
||||
ret0, _ := ret[0].(u.Signer)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Signe indicates an expected call of Signe
|
||||
func (mr *MockAuthorizerMockRecorder) Signe() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Signe", reflect.TypeOf((*MockAuthorizer)(nil).Signe))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Signer", reflect.TypeOf((*MockAuthorizer)(nil).Signer))
|
||||
}
|
||||
|
||||
// Storage mocks base method
|
||||
func (m *MockAuthorizer) Storage() u.Storage {
|
||||
func (m *MockAuthorizer) Storage() op.Storage {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Storage")
|
||||
ret0, _ := ret[0].(u.Storage)
|
||||
ret0, _ := ret[0].(op.Storage)
|
||||
return ret0
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
package mock
|
||||
|
||||
import (
|
||||
http "net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/gorilla/schema"
|
||||
|
||||
oidc "github.com/caos/oidc/pkg/oidc"
|
||||
"github.com/caos/oidc/pkg/op"
|
||||
u "github.com/caos/oidc/pkg/op/u"
|
||||
)
|
||||
|
||||
func NewAuthorizer(t *testing.T) op.Authorizer {
|
||||
|
@ -24,7 +20,7 @@ func NewAuthorizerExpectValid(t *testing.T, wantErr bool) op.Authorizer {
|
|||
ExpectEncoder(m)
|
||||
ExpectSigner(m, t)
|
||||
ExpectStorage(m, t)
|
||||
ExpectErrorHandler(m, t, wantErr)
|
||||
// ExpectErrorHandler(m, t, wantErr)
|
||||
return m
|
||||
}
|
||||
|
||||
|
@ -50,27 +46,27 @@ func ExpectEncoder(a op.Authorizer) {
|
|||
|
||||
func ExpectSigner(a op.Authorizer, t *testing.T) {
|
||||
mockA := a.(*MockAuthorizer)
|
||||
mockA.EXPECT().Signe().DoAndReturn(
|
||||
func() u.Signer {
|
||||
mockA.EXPECT().Signer().DoAndReturn(
|
||||
func() op.Signer {
|
||||
return &Sig{}
|
||||
})
|
||||
}
|
||||
|
||||
func ExpectErrorHandler(a op.Authorizer, t *testing.T, wantErr bool) {
|
||||
mockA := a.(*MockAuthorizer)
|
||||
mockA.EXPECT().ErrorHandler().AnyTimes().
|
||||
Return(func(w http.ResponseWriter, r *http.Request, authReq *oidc.AuthRequest, err error) {
|
||||
if wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
// func ExpectErrorHandler(a op.Authorizer, t *testing.T, wantErr bool) {
|
||||
// mockA := a.(*MockAuthorizer)
|
||||
// mockA.EXPECT().ErrorHandler().AnyTimes().
|
||||
// Return(func(w http.ResponseWriter, r *http.Request, authReq *oidc.AuthRequest, err error) {
|
||||
// if wantErr {
|
||||
// require.Error(t, err)
|
||||
// return
|
||||
// }
|
||||
// require.NoError(t, err)
|
||||
// })
|
||||
// }
|
||||
|
||||
type Sig struct{}
|
||||
|
||||
func (s *Sig) Sign(*oidc.IDTokenClaims) (string, error) {
|
||||
func (s *Sig) SignIDToken(*oidc.IDTokenClaims) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package mock
|
||||
|
||||
//go:generate mockgen -package mock -destination ./storage.mock.go github.com/caos/oidc/pkg/op/u Storage
|
||||
//go:generate mockgen -package mock -destination ./storage.mock.go github.com/caos/oidc/pkg/op Storage
|
||||
//go:generate mockgen -package mock -destination ./authorizer.mock.go github.com/caos/oidc/pkg/op Authorizer
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/caos/oidc/pkg/op/u (interfaces: Storage)
|
||||
// Source: github.com/caos/oidc/pkg/op (interfaces: Storage)
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
|
||||
import (
|
||||
oidc "github.com/caos/oidc/pkg/oidc"
|
||||
op "github.com/caos/oidc/pkg/op"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
@ -34,10 +35,10 @@ func (m *MockStorage) EXPECT() *MockStorageMockRecorder {
|
|||
}
|
||||
|
||||
// AuthRequestByCode mocks base method
|
||||
func (m *MockStorage) AuthRequestByCode(arg0 oidc.Client, arg1, arg2 string) (*oidc.AuthRequest, error) {
|
||||
func (m *MockStorage) AuthRequestByCode(arg0 op.Client, arg1, arg2 string) (op.AuthRequest, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AuthRequestByCode", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(*oidc.AuthRequest)
|
||||
ret0, _ := ret[0].(op.AuthRequest)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
@ -49,10 +50,10 @@ func (mr *MockStorageMockRecorder) AuthRequestByCode(arg0, arg1, arg2 interface{
|
|||
}
|
||||
|
||||
// AuthRequestByID mocks base method
|
||||
func (m *MockStorage) AuthRequestByID(arg0 string) (*oidc.AuthRequest, error) {
|
||||
func (m *MockStorage) AuthRequestByID(arg0 string) (op.AuthRequest, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AuthRequestByID", arg0)
|
||||
ret0, _ := ret[0].(*oidc.AuthRequest)
|
||||
ret0, _ := ret[0].(op.AuthRequest)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
@ -64,10 +65,10 @@ func (mr *MockStorageMockRecorder) AuthRequestByID(arg0 interface{}) *gomock.Cal
|
|||
}
|
||||
|
||||
// AuthorizeClientIDCodeVerifier mocks base method
|
||||
func (m *MockStorage) AuthorizeClientIDCodeVerifier(arg0, arg1 string) (oidc.Client, error) {
|
||||
func (m *MockStorage) AuthorizeClientIDCodeVerifier(arg0, arg1 string) (op.Client, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AuthorizeClientIDCodeVerifier", arg0, arg1)
|
||||
ret0, _ := ret[0].(oidc.Client)
|
||||
ret0, _ := ret[0].(op.Client)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
@ -79,10 +80,10 @@ func (mr *MockStorageMockRecorder) AuthorizeClientIDCodeVerifier(arg0, arg1 inte
|
|||
}
|
||||
|
||||
// AuthorizeClientIDSecret mocks base method
|
||||
func (m *MockStorage) AuthorizeClientIDSecret(arg0, arg1 string) (oidc.Client, error) {
|
||||
func (m *MockStorage) AuthorizeClientIDSecret(arg0, arg1 string) (op.Client, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AuthorizeClientIDSecret", arg0, arg1)
|
||||
ret0, _ := ret[0].(oidc.Client)
|
||||
ret0, _ := ret[0].(op.Client)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
@ -94,11 +95,12 @@ func (mr *MockStorageMockRecorder) AuthorizeClientIDSecret(arg0, arg1 interface{
|
|||
}
|
||||
|
||||
// CreateAuthRequest mocks base method
|
||||
func (m *MockStorage) CreateAuthRequest(arg0 *oidc.AuthRequest) error {
|
||||
func (m *MockStorage) CreateAuthRequest(arg0 *oidc.AuthRequest) (op.AuthRequest, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateAuthRequest", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
ret0, _ := ret[0].(op.AuthRequest)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateAuthRequest indicates an expected call of CreateAuthRequest
|
||||
|
@ -122,10 +124,10 @@ func (mr *MockStorageMockRecorder) DeleteAuthRequestAndCode(arg0, arg1 interface
|
|||
}
|
||||
|
||||
// GetClientByClientID mocks base method
|
||||
func (m *MockStorage) GetClientByClientID(arg0 string) (oidc.Client, error) {
|
||||
func (m *MockStorage) GetClientByClientID(arg0 string) (op.Client, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetClientByClientID", arg0)
|
||||
ret0, _ := ret[0].(oidc.Client)
|
||||
ret0, _ := ret[0].(op.Client)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue