Skip to content

Commit 37412e6

Browse files
mfenniakMathieu Fenniak
authored andcommitted
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>
1 parent 2425ae7 commit 37412e6

15 files changed

Lines changed: 2123 additions & 429 deletions

.deadcode-out

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ forgejo.org/modules/zstd
222222
forgejo.org/routers/web/org
223223
MustEnableProjects
224224

225-
forgejo.org/services/auth/method
226-
OverrideAuthorizedIntegrationHTTPClient
227-
228225
forgejo.org/services/context
229226
GetPrivateContext
230227

.mockery.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
formatter: gofmt
2+
template: testify
3+
packages:
4+
forgejo.org/modules/nosql:
5+
config:
6+
filename: mocks.go # make mocks public so that external packages can use
7+
forgejo.org/services/authz:
8+
config:
9+
filename: authorization_reducer_mock.go # make mocks public so that external packages can use
10+
code.forgejo.org/go-chi/cache:
11+
interfaces:
12+
Cache:
13+
config:
14+
pkgname: cache
15+
dir: modules/cache
16+
filename: mocks.go # make mocks public, not `_test.go`, so that external packages can mock caching

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ GO_LICENSES_PACKAGE ?= github.com/google/go-licenses/v2@v2.0.1 # renovate: datas
4747
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 # renovate: datasource=go
4848
DEADCODE_PACKAGE ?= golang.org/x/tools/cmd/deadcode@v0.44.0 # renovate: datasource=go
4949
ERRORTYPE_PACKAGE ?= fillmore-labs.com/errortype@v0.0.11 # renovate: datasource=go
50-
GOMOCK_PACKAGE ?= go.uber.org/mock/mockgen@v0.6.0 # renovate: datasource=go
5150
RENOVATE_NPM_PACKAGE ?= renovate@43.141.6 # renovate: datasource=docker packageName=data.forgejo.org/renovate/renovate
51+
MOCKERY_PACKAGE ?= github.com/vektra/mockery/v3@v3.7.0 # renovate: datasource=go
5252

5353
# https://github.com/disposable-email-domains/disposable-email-domains/commits/main/
5454
DISPOSABLE_EMAILS_SHA ?= 0c27e671231d27cf66370034d7f6818037416989 # renovate: ...
@@ -245,7 +245,7 @@ help:
245245
@echo " - generate-license update license files"
246246
@echo " - generate-gitignore update gitignore files"
247247
@echo " - generate-manpage generate manpage"
248-
@echo " - generate-gomock generate gomock files"
248+
@echo " - generate-mockery generate mockery files"
249249
@echo " - generate-forgejo-api generate the forgejo API from spec"
250250
@echo " - forgejo-api-validate check if the forgejo API matches the specs"
251251
@echo " - generate-swagger generate the swagger spec from code comments"
@@ -968,8 +968,8 @@ deps-tools:
968968
$(GO) install $(XGO_PACKAGE)
969969
$(GO) install $(GO_LICENSES_PACKAGE)
970970
$(GO) install $(GOVULNCHECK_PACKAGE)
971-
$(GO) install $(GOMOCK_PACKAGE)
972971
$(GO) install $(ERRORTYPE_PACKAGE)
972+
$(GO) install $(MOCKERY_PACKAGE)
973973

974974
node_modules: package-lock.json
975975
npm install --no-save
@@ -1024,9 +1024,9 @@ generate-license:
10241024
generate-gitignore:
10251025
$(GO) run build/generate-gitignores.go
10261026

1027-
.PHONY: generate-gomock
1028-
generate-gomock:
1029-
$(GO) run $(GOMOCK_PACKAGE) -package mock -destination ./modules/queue/mock/redisuniversalclient.go forgejo.org/modules/nosql RedisClient
1027+
.PHONY: generate-mockery
1028+
generate-mockery:
1029+
$(GO) run $(MOCKERY_PACKAGE)
10301030

10311031
.PHONY: generate-images
10321032
generate-images: | node_modules

custom/conf/app.example.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,3 +2846,7 @@ LEVEL = Info
28462846
;; Default is false.
28472847
;; If a domain is allowed by ALLOWED_DOMAINS, this option will be ignored.
28482848
;ALLOW_LOCALNETWORKS = false
2849+
;
2850+
;; Remote requests are cached after being received for the cache time-to-live (TTL). Default is 10 minutes.
2851+
;; Caching uses the configured adapter in the [cache] config section.
2852+
;CACHE_TTL = 10m

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ require (
100100
github.com/yuin/goldmark v1.8.2
101101
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
102102
gitlab.com/gitlab-org/api/client-go v0.143.2
103-
go.uber.org/mock v0.6.0
104103
go.yaml.in/yaml/v3 v3.0.4
105104
golang.org/x/crypto v0.50.0
106105
golang.org/x/image v0.39.0

0 commit comments

Comments
 (0)