BREAKING CHANGE: - The various verifier types are merged into a oidc.Verifir. - oidc.Verfier became a struct with exported fields * use type aliases for oidc.Verifier this binds the correct contstructor to each verifier usecase. * fix: handle the zero cases for oidc.Time * add unit tests to oidc verifier * fix: correct returned field for JWTTokenRequest JWTTokenRequest.GetIssuedAt() was returning the ExpiresAt field. This change corrects that by returning IssuedAt instead.
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/gorilla/schema"
|
|
"gopkg.in/square/go-jose.v2"
|
|
|
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
|
"github.com/zitadel/oidc/v3/pkg/op"
|
|
)
|
|
|
|
func NewAuthorizer(t *testing.T) op.Authorizer {
|
|
return NewMockAuthorizer(gomock.NewController(t))
|
|
}
|
|
|
|
func NewAuthorizerExpectValid(t *testing.T, wantErr bool) op.Authorizer {
|
|
m := NewAuthorizer(t)
|
|
ExpectDecoder(m)
|
|
ExpectEncoder(m)
|
|
//ExpectSigner(m, t)
|
|
ExpectStorage(m, t)
|
|
ExpectVerifier(m, t)
|
|
// ExpectErrorHandler(m, t, wantErr)
|
|
return m
|
|
}
|
|
|
|
func ExpectDecoder(a op.Authorizer) {
|
|
mockA := a.(*MockAuthorizer)
|
|
mockA.EXPECT().Decoder().AnyTimes().Return(schema.NewDecoder())
|
|
}
|
|
|
|
func ExpectEncoder(a op.Authorizer) {
|
|
mockA := a.(*MockAuthorizer)
|
|
mockA.EXPECT().Encoder().AnyTimes().Return(schema.NewEncoder())
|
|
}
|
|
|
|
//
|
|
//func ExpectSigner(a op.Authorizer, t *testing.T) {
|
|
// mockA := a.(*MockAuthorizer)
|
|
// mockA.EXPECT().Signer().DoAndReturn(
|
|
// func() op.Signer {
|
|
// return &Sig{}
|
|
// })
|
|
//}
|
|
|
|
func ExpectVerifier(a op.Authorizer, t *testing.T) {
|
|
mockA := a.(*MockAuthorizer)
|
|
mockA.EXPECT().IDTokenHintVerifier(gomock.Any()).DoAndReturn(
|
|
func() *op.IDTokenHintVerifier {
|
|
return op.NewIDTokenHintVerifier("", nil)
|
|
})
|
|
}
|
|
|
|
type Verifier struct{}
|
|
|
|
func (v *Verifier) Verify(ctx context.Context, accessToken, idToken string) (*oidc.IDTokenClaims, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (v *Verifier) VerifyIDToken(ctx context.Context, idToken string) (*oidc.IDTokenClaims, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type Sig struct {
|
|
signer jose.Signer
|
|
}
|
|
|
|
func (s *Sig) Signer() jose.Signer {
|
|
return s.signer
|
|
}
|
|
|
|
func (s *Sig) Health(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *Sig) SignatureAlgorithm() jose.SignatureAlgorithm {
|
|
return jose.HS256
|
|
}
|
|
|
|
func ExpectStorage(a op.Authorizer, t *testing.T) {
|
|
mockA := a.(*MockAuthorizer)
|
|
mockA.EXPECT().Storage().AnyTimes().Return(NewMockStorageAny(t))
|
|
}
|