File: authorizer.mock.impl.go

package info (click to toggle)
golang-github-zitadel-oidc 3.44.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,520 kB
  • sloc: makefile: 5
file content (86 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package mock

import (
	"context"
	"testing"

	jose "github.com/go-jose/go-jose/v4"
	"github.com/golang/mock/gomock"
	"github.com/zitadel/schema"

	"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))
}