jojo/services/authz/authorization_reducer_mock.go
Mathieu Fenniak 37412e6a00 feat: cache OIDC metadata & JWKS when read by authorized integration (#12275)
Enhances authorized integrations (#12261) with a cache of the remote OpenID Connect descriptor file and JSON Web Key Set (JWKS), improving runtime performance and reducing intermittent reliability risks.  By default a 10 minute cache is used, configurable through `[authorized_integration].CACHE_TTL`.

To mock the cache for testing, mockery code generation is added, and a previous manually generated mock for `AuthorizationReducer` was replaced with the code generation.

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. All work and communication must conform to Forgejo's [AI Agreement](https://codeberg.org/forgejo/governance/src/branch/main/AIAgreement.md). There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests for Go changes

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I ran...
  - [x] `make pr-go` before pushing

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.
- [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change.
    - Authorized integrations are not yet exposed to end-users.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12275
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2026-04-28 02:13:06 +02:00

205 lines
6.6 KiB
Go

// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
// template: testify
package authz
import (
"context"
"forgejo.org/models/perm"
"forgejo.org/models/repo"
mock "github.com/stretchr/testify/mock"
"xorm.io/builder"
)
// NewMockAuthorizationReducer creates a new instance of MockAuthorizationReducer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockAuthorizationReducer(t interface {
mock.TestingT
Cleanup(func())
},
) *MockAuthorizationReducer {
mock := &MockAuthorizationReducer{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// MockAuthorizationReducer is an autogenerated mock type for the AuthorizationReducer type
type MockAuthorizationReducer struct {
mock.Mock
}
type MockAuthorizationReducer_Expecter struct {
mock *mock.Mock
}
func (_m *MockAuthorizationReducer) EXPECT() *MockAuthorizationReducer_Expecter {
return &MockAuthorizationReducer_Expecter{mock: &_m.Mock}
}
// AllowAdminOverride provides a mock function for the type MockAuthorizationReducer
func (_mock *MockAuthorizationReducer) AllowAdminOverride() bool {
ret := _mock.Called()
if len(ret) == 0 {
panic("no return value specified for AllowAdminOverride")
}
var r0 bool
if returnFunc, ok := ret.Get(0).(func() bool); ok {
r0 = returnFunc()
} else {
r0 = ret.Get(0).(bool)
}
return r0
}
// MockAuthorizationReducer_AllowAdminOverride_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowAdminOverride'
type MockAuthorizationReducer_AllowAdminOverride_Call struct {
*mock.Call
}
// AllowAdminOverride is a helper method to define mock.On call
func (_e *MockAuthorizationReducer_Expecter) AllowAdminOverride() *MockAuthorizationReducer_AllowAdminOverride_Call {
return &MockAuthorizationReducer_AllowAdminOverride_Call{Call: _e.mock.On("AllowAdminOverride")}
}
func (_c *MockAuthorizationReducer_AllowAdminOverride_Call) Run(run func()) *MockAuthorizationReducer_AllowAdminOverride_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockAuthorizationReducer_AllowAdminOverride_Call) Return(b bool) *MockAuthorizationReducer_AllowAdminOverride_Call {
_c.Call.Return(b)
return _c
}
func (_c *MockAuthorizationReducer_AllowAdminOverride_Call) RunAndReturn(run func() bool) *MockAuthorizationReducer_AllowAdminOverride_Call {
_c.Call.Return(run)
return _c
}
// ReduceRepoAccess provides a mock function for the type MockAuthorizationReducer
func (_mock *MockAuthorizationReducer) ReduceRepoAccess(ctx context.Context, repo1 *repo.Repository, accessMode perm.AccessMode) (perm.AccessMode, error) {
ret := _mock.Called(ctx, repo1, accessMode)
if len(ret) == 0 {
panic("no return value specified for ReduceRepoAccess")
}
var r0 perm.AccessMode
var r1 error
if returnFunc, ok := ret.Get(0).(func(context.Context, *repo.Repository, perm.AccessMode) (perm.AccessMode, error)); ok {
return returnFunc(ctx, repo1, accessMode)
}
if returnFunc, ok := ret.Get(0).(func(context.Context, *repo.Repository, perm.AccessMode) perm.AccessMode); ok {
r0 = returnFunc(ctx, repo1, accessMode)
} else {
r0 = ret.Get(0).(perm.AccessMode)
}
if returnFunc, ok := ret.Get(1).(func(context.Context, *repo.Repository, perm.AccessMode) error); ok {
r1 = returnFunc(ctx, repo1, accessMode)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockAuthorizationReducer_ReduceRepoAccess_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReduceRepoAccess'
type MockAuthorizationReducer_ReduceRepoAccess_Call struct {
*mock.Call
}
// ReduceRepoAccess is a helper method to define mock.On call
// - ctx context.Context
// - repo1 *repo.Repository
// - accessMode perm.AccessMode
func (_e *MockAuthorizationReducer_Expecter) ReduceRepoAccess(ctx, repo1, accessMode any) *MockAuthorizationReducer_ReduceRepoAccess_Call {
return &MockAuthorizationReducer_ReduceRepoAccess_Call{Call: _e.mock.On("ReduceRepoAccess", ctx, repo1, accessMode)}
}
func (_c *MockAuthorizationReducer_ReduceRepoAccess_Call) Run(run func(ctx context.Context, repo1 *repo.Repository, accessMode perm.AccessMode)) *MockAuthorizationReducer_ReduceRepoAccess_Call {
_c.Call.Run(func(args mock.Arguments) {
var arg0 context.Context
if args[0] != nil {
arg0 = args[0].(context.Context)
}
var arg1 *repo.Repository
if args[1] != nil {
arg1 = args[1].(*repo.Repository)
}
var arg2 perm.AccessMode
if args[2] != nil {
arg2 = args[2].(perm.AccessMode)
}
run(
arg0,
arg1,
arg2,
)
})
return _c
}
func (_c *MockAuthorizationReducer_ReduceRepoAccess_Call) Return(accessMode1 perm.AccessMode, err error) *MockAuthorizationReducer_ReduceRepoAccess_Call {
_c.Call.Return(accessMode1, err)
return _c
}
func (_c *MockAuthorizationReducer_ReduceRepoAccess_Call) RunAndReturn(run func(ctx context.Context, repo1 *repo.Repository, accessMode perm.AccessMode) (perm.AccessMode, error)) *MockAuthorizationReducer_ReduceRepoAccess_Call {
_c.Call.Return(run)
return _c
}
// RepoReadAccessFilter provides a mock function for the type MockAuthorizationReducer
func (_mock *MockAuthorizationReducer) RepoReadAccessFilter() builder.Cond {
ret := _mock.Called()
if len(ret) == 0 {
panic("no return value specified for RepoReadAccessFilter")
}
var r0 builder.Cond
if returnFunc, ok := ret.Get(0).(func() builder.Cond); ok {
r0 = returnFunc()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(builder.Cond)
}
}
return r0
}
// MockAuthorizationReducer_RepoReadAccessFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RepoReadAccessFilter'
type MockAuthorizationReducer_RepoReadAccessFilter_Call struct {
*mock.Call
}
// RepoReadAccessFilter is a helper method to define mock.On call
func (_e *MockAuthorizationReducer_Expecter) RepoReadAccessFilter() *MockAuthorizationReducer_RepoReadAccessFilter_Call {
return &MockAuthorizationReducer_RepoReadAccessFilter_Call{Call: _e.mock.On("RepoReadAccessFilter")}
}
func (_c *MockAuthorizationReducer_RepoReadAccessFilter_Call) Run(run func()) *MockAuthorizationReducer_RepoReadAccessFilter_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockAuthorizationReducer_RepoReadAccessFilter_Call) Return(cond builder.Cond) *MockAuthorizationReducer_RepoReadAccessFilter_Call {
_c.Call.Return(cond)
return _c
}
func (_c *MockAuthorizationReducer_RepoReadAccessFilter_Call) RunAndReturn(run func() builder.Cond) *MockAuthorizationReducer_RepoReadAccessFilter_Call {
_c.Call.Return(run)
return _c
}