jojo/services/auth/method/mocks_test.go
Mathieu Fenniak 7fc236c589 feat: allow Forgejo Actions to be used an Authorized Integration in-memory with internal issuer (#12364)
Allow JWTs that are generated by Forgejo Actions to be validated within Forgejo in-memory.  Without any special support for this internal access situation, these problems would occur:

1. Forgejo would need to make an HTTP request to itself to get the valid public key for the JWT, in order to validate its signature.  This is a waste of resources, and introduces a self-DoS risk.
2. Forgejo would need to be available via TLS in order for Actions to make service calls to Forgejo with that JWT, due to the TLS requirement for public key fetching.  This would be a blocker for writing end-to-end tests for Forgejo, but also would affect users who do not host Forgejo with TLS.
3. Authorized Integrations would need to be saved with the `issuer` URL of Forgejo.  If Forgejo's own `setting.AppURL` changed, all the persisted records in the database would become incorrect.

## 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.
  - [x] 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.
- [x] 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.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12364
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
2026-05-01 17:42:34 +02:00

129 lines
3.6 KiB
Go

// Code generated by mockery; DO NOT EDIT.
// github.com/vektra/mockery
// template: testify
package method
import (
"forgejo.org/modules/jwtx"
mock "github.com/stretchr/testify/mock"
)
// NewMockInternalIssuer creates a new instance of MockInternalIssuer. 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 NewMockInternalIssuer(t interface {
mock.TestingT
Cleanup(func())
},
) *MockInternalIssuer {
mock := &MockInternalIssuer{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// MockInternalIssuer is an autogenerated mock type for the InternalIssuer type
type MockInternalIssuer struct {
mock.Mock
}
type MockInternalIssuer_Expecter struct {
mock *mock.Mock
}
func (_m *MockInternalIssuer) EXPECT() *MockInternalIssuer_Expecter {
return &MockInternalIssuer_Expecter{mock: &_m.Mock}
}
// IssuerPlaceholder provides a mock function for the type MockInternalIssuer
func (_mock *MockInternalIssuer) IssuerPlaceholder() string {
ret := _mock.Called()
if len(ret) == 0 {
panic("no return value specified for IssuerPlaceholder")
}
var r0 string
if returnFunc, ok := ret.Get(0).(func() string); ok {
r0 = returnFunc()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// MockInternalIssuer_IssuerPlaceholder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IssuerPlaceholder'
type MockInternalIssuer_IssuerPlaceholder_Call struct {
*mock.Call
}
// IssuerPlaceholder is a helper method to define mock.On call
func (_e *MockInternalIssuer_Expecter) IssuerPlaceholder() *MockInternalIssuer_IssuerPlaceholder_Call {
return &MockInternalIssuer_IssuerPlaceholder_Call{Call: _e.mock.On("IssuerPlaceholder")}
}
func (_c *MockInternalIssuer_IssuerPlaceholder_Call) Run(run func()) *MockInternalIssuer_IssuerPlaceholder_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInternalIssuer_IssuerPlaceholder_Call) Return(s string) *MockInternalIssuer_IssuerPlaceholder_Call {
_c.Call.Return(s)
return _c
}
func (_c *MockInternalIssuer_IssuerPlaceholder_Call) RunAndReturn(run func() string) *MockInternalIssuer_IssuerPlaceholder_Call {
_c.Call.Return(run)
return _c
}
// SigningKey provides a mock function for the type MockInternalIssuer
func (_mock *MockInternalIssuer) SigningKey() jwtx.SigningKey {
ret := _mock.Called()
if len(ret) == 0 {
panic("no return value specified for SigningKey")
}
var r0 jwtx.SigningKey
if returnFunc, ok := ret.Get(0).(func() jwtx.SigningKey); ok {
r0 = returnFunc()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(jwtx.SigningKey)
}
}
return r0
}
// MockInternalIssuer_SigningKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SigningKey'
type MockInternalIssuer_SigningKey_Call struct {
*mock.Call
}
// SigningKey is a helper method to define mock.On call
func (_e *MockInternalIssuer_Expecter) SigningKey() *MockInternalIssuer_SigningKey_Call {
return &MockInternalIssuer_SigningKey_Call{Call: _e.mock.On("SigningKey")}
}
func (_c *MockInternalIssuer_SigningKey_Call) Run(run func()) *MockInternalIssuer_SigningKey_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockInternalIssuer_SigningKey_Call) Return(signingKey jwtx.SigningKey) *MockInternalIssuer_SigningKey_Call {
_c.Call.Return(signingKey)
return _c
}
func (_c *MockInternalIssuer_SigningKey_Call) RunAndReturn(run func() jwtx.SigningKey) *MockInternalIssuer_SigningKey_Call {
_c.Call.Return(run)
return _c
}