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>
This commit is contained in:
committed by
Mathieu Fenniak
parent
2425ae7725
commit
37412e6a00
Vendored
+497
@@ -0,0 +1,497 @@
|
||||
// Code generated by mockery; DO NOT EDIT.
|
||||
// github.com/vektra/mockery
|
||||
// template: testify
|
||||
|
||||
package cache
|
||||
|
||||
import (
|
||||
"code.forgejo.org/go-chi/cache"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// NewMockCache creates a new instance of MockCache. 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 NewMockCache(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
},
|
||||
) *MockCache {
|
||||
mock := &MockCache{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
|
||||
// MockCache is an autogenerated mock type for the Cache type
|
||||
type MockCache struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type MockCache_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *MockCache) EXPECT() *MockCache_Expecter {
|
||||
return &MockCache_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// Decr provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Decr(key string) error {
|
||||
ret := _mock.Called(key)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Decr")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = returnFunc(key)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Decr_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Decr'
|
||||
type MockCache_Decr_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Decr is a helper method to define mock.On call
|
||||
// - key string
|
||||
func (_e *MockCache_Expecter) Decr(key any) *MockCache_Decr_Call {
|
||||
return &MockCache_Decr_Call{Call: _e.mock.On("Decr", key)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Decr_Call) Run(run func(key string)) *MockCache_Decr_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 string
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Decr_Call) Return(err error) *MockCache_Decr_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Decr_Call) RunAndReturn(run func(key string) error) *MockCache_Decr_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Delete provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Delete(key string) error {
|
||||
ret := _mock.Called(key)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Delete")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = returnFunc(key)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete'
|
||||
type MockCache_Delete_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Delete is a helper method to define mock.On call
|
||||
// - key string
|
||||
func (_e *MockCache_Expecter) Delete(key any) *MockCache_Delete_Call {
|
||||
return &MockCache_Delete_Call{Call: _e.mock.On("Delete", key)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Delete_Call) Run(run func(key string)) *MockCache_Delete_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 string
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Delete_Call) Return(err error) *MockCache_Delete_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Delete_Call) RunAndReturn(run func(key string) error) *MockCache_Delete_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Flush provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Flush() error {
|
||||
ret := _mock.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Flush")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = returnFunc()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Flush_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Flush'
|
||||
type MockCache_Flush_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Flush is a helper method to define mock.On call
|
||||
func (_e *MockCache_Expecter) Flush() *MockCache_Flush_Call {
|
||||
return &MockCache_Flush_Call{Call: _e.mock.On("Flush")}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Flush_Call) Run(run func()) *MockCache_Flush_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Flush_Call) Return(err error) *MockCache_Flush_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Flush_Call) RunAndReturn(run func() error) *MockCache_Flush_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Get provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Get(key string) any {
|
||||
ret := _mock.Called(key)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Get")
|
||||
}
|
||||
|
||||
var r0 any
|
||||
if returnFunc, ok := ret.Get(0).(func(string) any); ok {
|
||||
r0 = returnFunc(key)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(any)
|
||||
}
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get'
|
||||
type MockCache_Get_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Get is a helper method to define mock.On call
|
||||
// - key string
|
||||
func (_e *MockCache_Expecter) Get(key any) *MockCache_Get_Call {
|
||||
return &MockCache_Get_Call{Call: _e.mock.On("Get", key)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Get_Call) Run(run func(key string)) *MockCache_Get_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 string
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Get_Call) Return(v any) *MockCache_Get_Call {
|
||||
_c.Call.Return(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Get_Call) RunAndReturn(run func(key string) any) *MockCache_Get_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Incr provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Incr(key string) error {
|
||||
ret := _mock.Called(key)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Incr")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = returnFunc(key)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Incr_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Incr'
|
||||
type MockCache_Incr_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Incr is a helper method to define mock.On call
|
||||
// - key string
|
||||
func (_e *MockCache_Expecter) Incr(key any) *MockCache_Incr_Call {
|
||||
return &MockCache_Incr_Call{Call: _e.mock.On("Incr", key)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Incr_Call) Run(run func(key string)) *MockCache_Incr_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 string
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Incr_Call) Return(err error) *MockCache_Incr_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Incr_Call) RunAndReturn(run func(key string) error) *MockCache_Incr_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// IsExist provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) IsExist(key string) bool {
|
||||
ret := _mock.Called(key)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for IsExist")
|
||||
}
|
||||
|
||||
var r0 bool
|
||||
if returnFunc, ok := ret.Get(0).(func(string) bool); ok {
|
||||
r0 = returnFunc(key)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_IsExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExist'
|
||||
type MockCache_IsExist_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// IsExist is a helper method to define mock.On call
|
||||
// - key string
|
||||
func (_e *MockCache_Expecter) IsExist(key any) *MockCache_IsExist_Call {
|
||||
return &MockCache_IsExist_Call{Call: _e.mock.On("IsExist", key)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_IsExist_Call) Run(run func(key string)) *MockCache_IsExist_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 string
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_IsExist_Call) Return(b bool) *MockCache_IsExist_Call {
|
||||
_c.Call.Return(b)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_IsExist_Call) RunAndReturn(run func(key string) bool) *MockCache_IsExist_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Ping provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Ping() error {
|
||||
ret := _mock.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Ping")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = returnFunc()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Ping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Ping'
|
||||
type MockCache_Ping_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Ping is a helper method to define mock.On call
|
||||
func (_e *MockCache_Expecter) Ping() *MockCache_Ping_Call {
|
||||
return &MockCache_Ping_Call{Call: _e.mock.On("Ping")}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Ping_Call) Run(run func()) *MockCache_Ping_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Ping_Call) Return(err error) *MockCache_Ping_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Ping_Call) RunAndReturn(run func() error) *MockCache_Ping_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Put provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) Put(key string, val any, timeout int64) error {
|
||||
ret := _mock.Called(key, val, timeout)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Put")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func(string, any, int64) error); ok {
|
||||
r0 = returnFunc(key, val, timeout)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put'
|
||||
type MockCache_Put_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Put is a helper method to define mock.On call
|
||||
// - key string
|
||||
// - val any
|
||||
// - timeout int64
|
||||
func (_e *MockCache_Expecter) Put(key, val, timeout any) *MockCache_Put_Call {
|
||||
return &MockCache_Put_Call{Call: _e.mock.On("Put", key, val, timeout)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_Put_Call) Run(run func(key string, val any, timeout int64)) *MockCache_Put_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 string
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(string)
|
||||
}
|
||||
var arg1 any
|
||||
if args[1] != nil {
|
||||
arg1 = args[1].(any)
|
||||
}
|
||||
var arg2 int64
|
||||
if args[2] != nil {
|
||||
arg2 = args[2].(int64)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Put_Call) Return(err error) *MockCache_Put_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_Put_Call) RunAndReturn(run func(key string, val any, timeout int64) error) *MockCache_Put_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// StartAndGC provides a mock function for the type MockCache
|
||||
func (_mock *MockCache) StartAndGC(opt cache.Options) error {
|
||||
ret := _mock.Called(opt)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for StartAndGC")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if returnFunc, ok := ret.Get(0).(func(cache.Options) error); ok {
|
||||
r0 = returnFunc(opt)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockCache_StartAndGC_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StartAndGC'
|
||||
type MockCache_StartAndGC_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// StartAndGC is a helper method to define mock.On call
|
||||
// - opt cache.Options
|
||||
func (_e *MockCache_Expecter) StartAndGC(opt any) *MockCache_StartAndGC_Call {
|
||||
return &MockCache_StartAndGC_Call{Call: _e.mock.On("StartAndGC", opt)}
|
||||
}
|
||||
|
||||
func (_c *MockCache_StartAndGC_Call) Run(run func(opt cache.Options)) *MockCache_StartAndGC_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 cache.Options
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(cache.Options)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_StartAndGC_Call) Return(err error) *MockCache_StartAndGC_Call {
|
||||
_c.Call.Return(err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockCache_StartAndGC_Call) RunAndReturn(run func(opt cache.Options) error) *MockCache_StartAndGC_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
@@ -30,6 +30,8 @@ type Manager struct {
|
||||
// RedisClient is a subset of redis.UniversalClient, it exposes less methods
|
||||
// to avoid generating machine code for unused methods. New method definitions
|
||||
// should be copied from the definitions in the Redis library github.com/redis/go-redis.
|
||||
//
|
||||
//mockery:generate: true
|
||||
type RedisClient interface {
|
||||
// redis.GenericCmdable
|
||||
Del(ctx context.Context, keys ...string) *redis.IntCmd
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,18 +7,17 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"forgejo.org/modules/queue/mock"
|
||||
"forgejo.org/modules/nosql"
|
||||
queue_mock "forgejo.org/modules/queue/mock"
|
||||
"forgejo.org/modules/setting"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
type baseRedisUnitTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
mockController *gomock.Controller
|
||||
}
|
||||
|
||||
func TestBaseRedis(t *testing.T) {
|
||||
@@ -26,7 +25,6 @@ func TestBaseRedis(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *baseRedisUnitTestSuite) SetupSuite() {
|
||||
suite.mockController = gomock.NewController(suite.T())
|
||||
}
|
||||
|
||||
func (suite *baseRedisUnitTestSuite) TestBasic() {
|
||||
@@ -71,39 +69,47 @@ func (suite *baseRedisUnitTestSuite) TestBasic() {
|
||||
}
|
||||
|
||||
// Configure expectations.
|
||||
mockRedisStore := mock.NewInMemoryMockRedis()
|
||||
redisClient := mock.NewMockRedisClient(suite.mockController)
|
||||
mockRedisStore := queue_mock.NewInMemoryMockRedis()
|
||||
redisClient := nosql.NewMockRedisClient(suite.T())
|
||||
|
||||
redisClient.EXPECT().
|
||||
Ping(gomock.Any()).
|
||||
Times(1).
|
||||
Return(&redis.StatusCmd{})
|
||||
Ping(mock.Anything).
|
||||
Return(&redis.StatusCmd{}).
|
||||
Times(1)
|
||||
redisClient.EXPECT().
|
||||
LLen(gomock.Any(), testCase.QueueName).
|
||||
Times(1).
|
||||
DoAndReturn(mockRedisStore.LLen)
|
||||
LLen(mock.Anything, testCase.QueueName).
|
||||
RunAndReturn(mockRedisStore.LLen).
|
||||
Times(1)
|
||||
redisClient.EXPECT().
|
||||
LPop(gomock.Any(), testCase.QueueName).
|
||||
Times(1).
|
||||
DoAndReturn(mockRedisStore.LPop)
|
||||
LPop(mock.Anything, testCase.QueueName).
|
||||
RunAndReturn(mockRedisStore.LPop).
|
||||
Times(1)
|
||||
redisClient.EXPECT().
|
||||
RPush(gomock.Any(), testCase.QueueName, gomock.Any()).
|
||||
Times(1).
|
||||
DoAndReturn(mockRedisStore.RPush)
|
||||
RPush(mock.Anything, testCase.QueueName, mock.Anything).
|
||||
RunAndReturn(func(ctx context.Context, key string, values ...any) *redis.IntCmd {
|
||||
return mockRedisStore.RPush(ctx, key, values[0].([]byte))
|
||||
}).
|
||||
Times(1)
|
||||
|
||||
if testCase.Unique {
|
||||
redisClient.EXPECT().
|
||||
SAdd(gomock.Any(), testCase.QueueName+"_unique", gomock.Any()).
|
||||
Times(1).
|
||||
DoAndReturn(mockRedisStore.SAdd)
|
||||
SAdd(mock.Anything, testCase.QueueName+"_unique", mock.Anything).
|
||||
RunAndReturn(func(ctx context.Context, key string, members ...any) *redis.IntCmd {
|
||||
return mockRedisStore.SAdd(ctx, key, members[0].([]byte))
|
||||
}).
|
||||
Times(1)
|
||||
redisClient.EXPECT().
|
||||
SRem(gomock.Any(), testCase.QueueName+"_unique", gomock.Any()).
|
||||
Times(1).
|
||||
DoAndReturn(mockRedisStore.SRem)
|
||||
SRem(mock.Anything, testCase.QueueName+"_unique", mock.Anything).
|
||||
RunAndReturn(func(ctx context.Context, key string, members ...any) *redis.IntCmd {
|
||||
return mockRedisStore.SRem(ctx, key, members[0].([]byte))
|
||||
}).
|
||||
Times(1)
|
||||
redisClient.EXPECT().
|
||||
SIsMember(gomock.Any(), testCase.QueueName+"_unique", gomock.Any()).
|
||||
Times(2).
|
||||
DoAndReturn(mockRedisStore.SIsMember)
|
||||
SIsMember(mock.Anything, testCase.QueueName+"_unique", mock.Anything).
|
||||
RunAndReturn(func(ctx context.Context, key string, member any) *redis.BoolCmd {
|
||||
return mockRedisStore.SIsMember(ctx, key, member.([]byte))
|
||||
}).
|
||||
Times(2)
|
||||
}
|
||||
|
||||
client, err := newBaseRedisGeneric(
|
||||
|
||||
@@ -1,344 +0,0 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: forgejo.org/modules/nosql (interfaces: RedisClient)
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -package mock -destination ./modules/queue/mock/redisuniversalclient.go forgejo.org/modules/nosql RedisClient
|
||||
//
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
time "time"
|
||||
|
||||
redis "github.com/redis/go-redis/v9"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockRedisClient is a mock of RedisClient interface.
|
||||
type MockRedisClient struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockRedisClientMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockRedisClientMockRecorder is the mock recorder for MockRedisClient.
|
||||
type MockRedisClientMockRecorder struct {
|
||||
mock *MockRedisClient
|
||||
}
|
||||
|
||||
// NewMockRedisClient creates a new mock instance.
|
||||
func NewMockRedisClient(ctrl *gomock.Controller) *MockRedisClient {
|
||||
mock := &MockRedisClient{ctrl: ctrl}
|
||||
mock.recorder = &MockRedisClientMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockRedisClient) EXPECT() *MockRedisClientMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Close mocks base method.
|
||||
func (m *MockRedisClient) Close() error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Close")
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Close indicates an expected call of Close.
|
||||
func (mr *MockRedisClientMockRecorder) Close() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockRedisClient)(nil).Close))
|
||||
}
|
||||
|
||||
// DBSize mocks base method.
|
||||
func (m *MockRedisClient) DBSize(ctx context.Context) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DBSize", ctx)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DBSize indicates an expected call of DBSize.
|
||||
func (mr *MockRedisClientMockRecorder) DBSize(ctx any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DBSize", reflect.TypeOf((*MockRedisClient)(nil).DBSize), ctx)
|
||||
}
|
||||
|
||||
// Decr mocks base method.
|
||||
func (m *MockRedisClient) Decr(ctx context.Context, key string) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Decr", ctx, key)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Decr indicates an expected call of Decr.
|
||||
func (mr *MockRedisClientMockRecorder) Decr(ctx, key any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Decr", reflect.TypeOf((*MockRedisClient)(nil).Decr), ctx, key)
|
||||
}
|
||||
|
||||
// Del mocks base method.
|
||||
func (m *MockRedisClient) Del(ctx context.Context, keys ...string) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx}
|
||||
for _, a := range keys {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "Del", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Del indicates an expected call of Del.
|
||||
func (mr *MockRedisClientMockRecorder) Del(ctx any, keys ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx}, keys...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Del", reflect.TypeOf((*MockRedisClient)(nil).Del), varargs...)
|
||||
}
|
||||
|
||||
// Exists mocks base method.
|
||||
func (m *MockRedisClient) Exists(ctx context.Context, keys ...string) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx}
|
||||
for _, a := range keys {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "Exists", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Exists indicates an expected call of Exists.
|
||||
func (mr *MockRedisClientMockRecorder) Exists(ctx any, keys ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx}, keys...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exists", reflect.TypeOf((*MockRedisClient)(nil).Exists), varargs...)
|
||||
}
|
||||
|
||||
// FlushDB mocks base method.
|
||||
func (m *MockRedisClient) FlushDB(ctx context.Context) *redis.StatusCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "FlushDB", ctx)
|
||||
ret0, _ := ret[0].(*redis.StatusCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// FlushDB indicates an expected call of FlushDB.
|
||||
func (mr *MockRedisClientMockRecorder) FlushDB(ctx any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlushDB", reflect.TypeOf((*MockRedisClient)(nil).FlushDB), ctx)
|
||||
}
|
||||
|
||||
// Get mocks base method.
|
||||
func (m *MockRedisClient) Get(ctx context.Context, key string) *redis.StringCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Get", ctx, key)
|
||||
ret0, _ := ret[0].(*redis.StringCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Get indicates an expected call of Get.
|
||||
func (mr *MockRedisClientMockRecorder) Get(ctx, key any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRedisClient)(nil).Get), ctx, key)
|
||||
}
|
||||
|
||||
// HDel mocks base method.
|
||||
func (m *MockRedisClient) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, key}
|
||||
for _, a := range fields {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "HDel", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// HDel indicates an expected call of HDel.
|
||||
func (mr *MockRedisClientMockRecorder) HDel(ctx, key any, fields ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, key}, fields...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HDel", reflect.TypeOf((*MockRedisClient)(nil).HDel), varargs...)
|
||||
}
|
||||
|
||||
// HKeys mocks base method.
|
||||
func (m *MockRedisClient) HKeys(ctx context.Context, key string) *redis.StringSliceCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "HKeys", ctx, key)
|
||||
ret0, _ := ret[0].(*redis.StringSliceCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// HKeys indicates an expected call of HKeys.
|
||||
func (mr *MockRedisClientMockRecorder) HKeys(ctx, key any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HKeys", reflect.TypeOf((*MockRedisClient)(nil).HKeys), ctx, key)
|
||||
}
|
||||
|
||||
// HSet mocks base method.
|
||||
func (m *MockRedisClient) HSet(ctx context.Context, key string, values ...any) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, key}
|
||||
for _, a := range values {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "HSet", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// HSet indicates an expected call of HSet.
|
||||
func (mr *MockRedisClientMockRecorder) HSet(ctx, key any, values ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, key}, values...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HSet", reflect.TypeOf((*MockRedisClient)(nil).HSet), varargs...)
|
||||
}
|
||||
|
||||
// Incr mocks base method.
|
||||
func (m *MockRedisClient) Incr(ctx context.Context, key string) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Incr", ctx, key)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Incr indicates an expected call of Incr.
|
||||
func (mr *MockRedisClientMockRecorder) Incr(ctx, key any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Incr", reflect.TypeOf((*MockRedisClient)(nil).Incr), ctx, key)
|
||||
}
|
||||
|
||||
// LLen mocks base method.
|
||||
func (m *MockRedisClient) LLen(ctx context.Context, key string) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "LLen", ctx, key)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// LLen indicates an expected call of LLen.
|
||||
func (mr *MockRedisClientMockRecorder) LLen(ctx, key any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LLen", reflect.TypeOf((*MockRedisClient)(nil).LLen), ctx, key)
|
||||
}
|
||||
|
||||
// LPop mocks base method.
|
||||
func (m *MockRedisClient) LPop(ctx context.Context, key string) *redis.StringCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "LPop", ctx, key)
|
||||
ret0, _ := ret[0].(*redis.StringCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// LPop indicates an expected call of LPop.
|
||||
func (mr *MockRedisClientMockRecorder) LPop(ctx, key any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LPop", reflect.TypeOf((*MockRedisClient)(nil).LPop), ctx, key)
|
||||
}
|
||||
|
||||
// Ping mocks base method.
|
||||
func (m *MockRedisClient) Ping(ctx context.Context) *redis.StatusCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Ping", ctx)
|
||||
ret0, _ := ret[0].(*redis.StatusCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Ping indicates an expected call of Ping.
|
||||
func (mr *MockRedisClientMockRecorder) Ping(ctx any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ping", reflect.TypeOf((*MockRedisClient)(nil).Ping), ctx)
|
||||
}
|
||||
|
||||
// RPush mocks base method.
|
||||
func (m *MockRedisClient) RPush(ctx context.Context, key string, values ...any) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, key}
|
||||
for _, a := range values {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "RPush", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// RPush indicates an expected call of RPush.
|
||||
func (mr *MockRedisClientMockRecorder) RPush(ctx, key any, values ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, key}, values...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RPush", reflect.TypeOf((*MockRedisClient)(nil).RPush), varargs...)
|
||||
}
|
||||
|
||||
// SAdd mocks base method.
|
||||
func (m *MockRedisClient) SAdd(ctx context.Context, key string, members ...any) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, key}
|
||||
for _, a := range members {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "SAdd", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SAdd indicates an expected call of SAdd.
|
||||
func (mr *MockRedisClientMockRecorder) SAdd(ctx, key any, members ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, key}, members...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SAdd", reflect.TypeOf((*MockRedisClient)(nil).SAdd), varargs...)
|
||||
}
|
||||
|
||||
// SIsMember mocks base method.
|
||||
func (m *MockRedisClient) SIsMember(ctx context.Context, key string, member any) *redis.BoolCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SIsMember", ctx, key, member)
|
||||
ret0, _ := ret[0].(*redis.BoolCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SIsMember indicates an expected call of SIsMember.
|
||||
func (mr *MockRedisClientMockRecorder) SIsMember(ctx, key, member any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SIsMember", reflect.TypeOf((*MockRedisClient)(nil).SIsMember), ctx, key, member)
|
||||
}
|
||||
|
||||
// SRem mocks base method.
|
||||
func (m *MockRedisClient) SRem(ctx context.Context, key string, members ...any) *redis.IntCmd {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, key}
|
||||
for _, a := range members {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "SRem", varargs...)
|
||||
ret0, _ := ret[0].(*redis.IntCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SRem indicates an expected call of SRem.
|
||||
func (mr *MockRedisClientMockRecorder) SRem(ctx, key any, members ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, key}, members...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SRem", reflect.TypeOf((*MockRedisClient)(nil).SRem), varargs...)
|
||||
}
|
||||
|
||||
// Set mocks base method.
|
||||
func (m *MockRedisClient) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Set", ctx, key, value, expiration)
|
||||
ret0, _ := ret[0].(*redis.StatusCmd)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Set indicates an expected call of Set.
|
||||
func (mr *MockRedisClientMockRecorder) Set(ctx, key, value, expiration any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockRedisClient)(nil).Set), ctx, key, value, expiration)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ var AuthorizedIntegration = struct {
|
||||
BlockedDomains string
|
||||
AllowLocalNetworks bool
|
||||
RequestTimeout time.Duration
|
||||
CacheTTL time.Duration
|
||||
}{}
|
||||
|
||||
func loadAuthorizedIntegrationFrom(rootCfg ConfigProvider) {
|
||||
@@ -18,4 +19,5 @@ func loadAuthorizedIntegrationFrom(rootCfg ConfigProvider) {
|
||||
AuthorizedIntegration.BlockedDomains = sec.Key("BLOCKED_DOMAINS").MustString("")
|
||||
AuthorizedIntegration.AllowLocalNetworks = sec.Key("ALLOW_LOCALNETWORKS").MustBool(false)
|
||||
AuthorizedIntegration.RequestTimeout = sec.Key("REQUEST_TIMEOUT").MustDuration(10 * time.Second)
|
||||
AuthorizedIntegration.CacheTTL = sec.Key("CACHE_TTL").MustDuration(10 * time.Minute)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user