mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 23:33:51 +01:00
Extra providers were not being properly initialized during NewProvider(), causing certificate registration and renewal scheduling to be skipped. - Add ConfigExtra type with idx field for provider indexing - Add MergeExtraConfig() for inheriting main provider settings - Add setupExtraProviders() for recursive extra provider initialization - Refactor NewProvider to return error and call setupExtraProviders() - Add provider-scoped logger with "main" or "extra[N]" name - Add batch operations: ObtainCertIfNotExistsAll(), ObtainCertAll() - Add ForceExpiryAll() with completion tracking via WaitRenewalDone() - Add RenewMode (force/ifNeeded) for controlling renewal behavior - Add PrintCertExpiriesAll() for logging all provider certificate expiries Summary of staged changes: - config.go: Added ConfigExtra type, MergeExtraConfig(), recursive validation with path uniqueness checking - provider.go: Added provider indexing, scoped logger, batch cert operations, force renewal with completion tracking, RenewMode control - setup.go: New file with setupExtraProviders() for proper extra provider initialization - setup_test.go: New tests for extra provider setup - multi_cert_test.go: New tests for multi-certificate functionality - renew.go: Updated to use new provider API with error handling - state.go: Updated to handle NewProvider error return
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package autocert_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/yusing/godoxy/internal/autocert"
|
|
"github.com/yusing/godoxy/internal/dnsproviders"
|
|
"github.com/yusing/godoxy/internal/serialization"
|
|
)
|
|
|
|
func TestEABConfigRequired(t *testing.T) {
|
|
dnsproviders.InitProviders()
|
|
|
|
tests := []struct {
|
|
name string
|
|
cfg *autocert.Config
|
|
wantErr bool
|
|
}{
|
|
{name: "Missing EABKid", cfg: &autocert.Config{EABHmac: "1234567890"}, wantErr: true},
|
|
{name: "Missing EABHmac", cfg: &autocert.Config{EABKid: "1234567890"}, wantErr: true},
|
|
{name: "Valid EAB", cfg: &autocert.Config{EABKid: "1234567890", EABHmac: "1234567890"}, wantErr: false},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
yaml := fmt.Appendf(nil, "eab_kid: %s\neab_hmac: %s", test.cfg.EABKid, test.cfg.EABHmac)
|
|
cfg := autocert.Config{}
|
|
err := serialization.UnmarshalValidateYAML(yaml, &cfg)
|
|
if (err != nil) != test.wantErr {
|
|
t.Errorf("Validate() error = %v, wantErr %v", err, test.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestExtraCertKeyPathsUnique(t *testing.T) {
|
|
t.Run("duplicate cert_path rejected", func(t *testing.T) {
|
|
cfg := &autocert.Config{
|
|
Provider: autocert.ProviderLocal,
|
|
Extra: []autocert.ConfigExtra{
|
|
{CertPath: "a.crt", KeyPath: "a.key"},
|
|
{CertPath: "a.crt", KeyPath: "b.key"},
|
|
},
|
|
}
|
|
require.Error(t, cfg.Validate())
|
|
})
|
|
|
|
t.Run("duplicate key_path rejected", func(t *testing.T) {
|
|
cfg := &autocert.Config{
|
|
Provider: autocert.ProviderLocal,
|
|
Extra: []autocert.ConfigExtra{
|
|
{CertPath: "a.crt", KeyPath: "a.key"},
|
|
{CertPath: "b.crt", KeyPath: "a.key"},
|
|
},
|
|
}
|
|
require.Error(t, cfg.Validate())
|
|
})
|
|
}
|