Debian Codegraph @

pkg/op/mock/authorizer.mock.impl.go

raw
1 package mock
2
3 import (
4 "context"
5 "testing"
6
7 jose "github.com/go-jose/go-jose/v4"
8 "github.com/golang/mock/gomock"
9 "github.com/zitadel/schema"
10
11 "github.com/zitadel/oidc/v3/pkg/oidc"
12 "github.com/zitadel/oidc/v3/pkg/op"
13 )
14
15 func NewAuthorizer(t *testing.T) op.Authorizer {
16 return NewMockAuthorizer(gomock.NewController(t))
17 }
18
19 func NewAuthorizerExpectValid(t *testing.T, wantErr bool) op.Authorizer {
20 m := NewAuthorizer(t)
21 ExpectDecoder(m)
22 ExpectEncoder(m)
23 //ExpectSigner(m, t)
24 ExpectStorage(m, t)
25 ExpectVerifier(m, t)
26 // ExpectErrorHandler(m, t, wantErr)
27 return m
28 }
29
30 func ExpectDecoder(a op.Authorizer) {
31 mockA := a.(*MockAuthorizer)
32 mockA.EXPECT().Decoder().AnyTimes().Return(schema.NewDecoder())
33 }
34
35 func ExpectEncoder(a op.Authorizer) {
36 mockA := a.(*MockAuthorizer)
37 mockA.EXPECT().Encoder().AnyTimes().Return(schema.NewEncoder())
38 }
39
40 //
41 //func ExpectSigner(a op.Authorizer, t *testing.T) {
42 // mockA := a.(*MockAuthorizer)
43 // mockA.EXPECT().Signer().DoAndReturn(
44 // func() op.Signer {
45 // return &Sig{}
46 // })
47 //}
48
49 func ExpectVerifier(a op.Authorizer, t *testing.T) {
50 mockA := a.(*MockAuthorizer)
51 mockA.EXPECT().IDTokenHintVerifier(gomock.Any()).DoAndReturn(
52 func() *op.IDTokenHintVerifier {
53 return op.NewIDTokenHintVerifier("", nil)
54 })
55 }
56
57 type Verifier struct{}
58
59 func (v *Verifier) Verify(ctx context.Context, accessToken, idToken string) (*oidc.IDTokenClaims, error) {
60 return nil, nil
61 }
62
63 func (v *Verifier) VerifyIDToken(ctx context.Context, idToken string) (*oidc.IDTokenClaims, error) {
64 return nil, nil
65 }
66
67 type Sig struct {
68 signer jose.Signer
69 }
70
71 func (s *Sig) Signer() jose.Signer {
72 return s.signer
73 }
74
75 func (s *Sig) Health(ctx context.Context) error {
76 return nil
77 }
78
79 func (s *Sig) SignatureAlgorithm() jose.SignatureAlgorithm {
80 return jose.HS256
81 }
82
83 func ExpectStorage(a op.Authorizer, t *testing.T) {
84 mockA := a.(*MockAuthorizer)
85 mockA.EXPECT().Storage().AnyTimes().Return(NewMockStorageAny(t))
86 }