From 30069d248c1f1090fc3b7c11b2ff04a354a5817b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 21 Sep 2026 15:47:14 +0000 Subject: [PATCH] enhance: add ACME profile setting Assisted-by: Copilot:gpt-5.6-terra Co-authored-by: techknowlogick <164197+techknowlogick@users.noreply.github.com> --- cmd/web_acme.go | 1 + modules/setting/server.go | 2 ++ modules/setting/server_test.go | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 modules/setting/server_test.go diff --git a/cmd/web_acme.go b/cmd/web_acme.go index 10a00cc4ec5..766ec56c2e4 100644 --- a/cmd/web_acme.go +++ b/cmd/web_acme.go @@ -83,6 +83,7 @@ func runACME(listenAddr string, m http.Handler) error { TrustedRoots: certPool, Email: setting.AcmeEmail, Agreed: setting.AcmeTOS, + Profile: setting.AcmeProfile, DisableHTTPChallenge: !enableHTTPChallenge, DisableTLSALPNChallenge: !enableTLSALPNChallenge, ListenHost: setting.HTTPAddr, diff --git a/modules/setting/server.go b/modules/setting/server.go index 641e18bdb4c..cb91a900e24 100644 --- a/modules/setting/server.go +++ b/modules/setting/server.go @@ -100,6 +100,7 @@ var ( AcmeLiveDirectory string AcmeEmail string AcmeURL string + AcmeProfile string AcmeCARoot string SSLMinimumVersion string SSLMaximumVersion string @@ -142,6 +143,7 @@ func loadServerFrom(rootCfg ConfigProvider) { Protocol = HTTPS if EnableAcme { AcmeURL = sec.Key("ACME_URL").MustString("") + AcmeProfile = sec.Key("ACME_PROFILE").MustString("") AcmeCARoot = sec.Key("ACME_CA_ROOT").MustString("") if sec.HasKey("ACME_ACCEPTTOS") { diff --git a/modules/setting/server_test.go b/modules/setting/server_test.go new file mode 100644 index 00000000000..cb36f9dc806 --- /dev/null +++ b/modules/setting/server_test.go @@ -0,0 +1,39 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package setting + +import ( + "testing" + + "gitea.dev/modules/test" + + "github.com/stretchr/testify/assert" +) + +func TestLoadServerFromACMEProfile(t *testing.T) { + defer test.MockVariableValue(&Protocol)() + defer test.MockVariableValue(&EnableAcme)() + defer test.MockVariableValue(&AcmeTOS)() + defer test.MockVariableValue(&AcmeURL)() + defer test.MockVariableValue(&AcmeProfile)() + defer test.MockVariableValue(&AcmeCARoot)() + defer test.MockVariableValue(&AcmeLiveDirectory)() + defer test.MockVariableValue(&AcmeEmail)() + + cfg, err := NewConfigProviderFromData(` +[server] +PROTOCOL = https +ENABLE_ACME = true +ACME_ACCEPTTOS = true +ACME_DIRECTORY = /tmp/acme +ACME_EMAIL = acme@example.com +ACME_PROFILE = shortlived +`) + assert.NoError(t, err) + + loadServerFrom(cfg) + + assert.Equal(t, HTTPS, Protocol) + assert.Equal(t, "shortlived", AcmeProfile) +}