fix(acme): avoid nilnil lint finding

Co-authored-by: techknowlogick <164197+techknowlogick@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-10-01 12:39:42 +00:00
committed by GitHub
parent 6a0e125018
commit e28e79a648
2 changed files with 16 additions and 10 deletions
+9 -5
View File
@@ -24,14 +24,14 @@ import (
"github.com/mholt/acmez/v3/acme"
)
func acmeExternalAccountBinding() (*acme.EAB, error) {
func acmeExternalAccountBinding() (acme.EAB, bool, error) {
if setting.AcmeEABKID == "" && setting.AcmeEABHMAC == "" {
return nil, nil
return acme.EAB{}, false, nil
}
if setting.AcmeEABKID == "" || setting.AcmeEABHMAC == "" {
return nil, errors.New("both ACME_EAB_KID and ACME_EAB_HMAC must be set")
return acme.EAB{}, false, errors.New("both ACME_EAB_KID and ACME_EAB_HMAC must be set")
}
return &acme.EAB{KeyID: setting.AcmeEABKID, MACKey: setting.AcmeEABHMAC}, nil
return acme.EAB{KeyID: setting.AcmeEABKID, MACKey: setting.AcmeEABHMAC}, true, nil
}
func getCARoot(path string) (*x509.CertPool, error) {
@@ -77,10 +77,14 @@ func runACME(listenAddr string, m http.Handler) error {
log.Warn("Failed to parse CA Root certificate, using default CA trust: %v", err)
}
}
externalAccount, err := acmeExternalAccountBinding()
externalAccountBinding, hasExternalAccount, err := acmeExternalAccountBinding()
if err != nil {
return err
}
var externalAccount *acme.EAB
if hasExternalAccount {
externalAccount = &externalAccountBinding
}
// FIXME: this path is not right, it uses "AppWorkPath" incorrectly, and writes the data into "AppWorkPath/https"
// Ideally it should migrate to AppDataPath write to "AppDataPath/https"
// And one more thing, no idea why we should set the global default variables here
+7 -5
View File
@@ -17,16 +17,18 @@ func TestAcmeExternalAccountBinding(t *testing.T) {
t.Cleanup(test.MockVariableValue(&setting.AcmeEABKID, ""))
t.Cleanup(test.MockVariableValue(&setting.AcmeEABHMAC, ""))
binding, err := acmeExternalAccountBinding()
binding, configured, err := acmeExternalAccountBinding()
assert.NoError(t, err)
assert.Nil(t, binding)
assert.False(t, configured)
assert.Empty(t, binding)
setting.AcmeEABKID = "kid"
_, err = acmeExternalAccountBinding()
_, _, err = acmeExternalAccountBinding()
assert.ErrorContains(t, err, "both ACME_EAB_KID and ACME_EAB_HMAC must be set")
setting.AcmeEABHMAC = "hmac"
binding, err = acmeExternalAccountBinding()
binding, configured, err = acmeExternalAccountBinding()
assert.NoError(t, err)
assert.Equal(t, &acme.EAB{KeyID: "kid", MACKey: "hmac"}, binding)
assert.True(t, configured)
assert.Equal(t, acme.EAB{KeyID: "kid", MACKey: "hmac"}, binding)
}