summaryrefslogtreecommitdiffstats
path: root/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go73
1 files changed, 49 insertions, 24 deletions
diff --git a/main_test.go b/main_test.go
index cd28aec..faadb89 100644
--- a/main_test.go
+++ b/main_test.go
@@ -1,36 +1,61 @@
+//go:build conformance
+
package main
import (
+ "crypto/rand"
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "strings"
"testing"
+ "time"
acmetest "github.com/cert-manager/cert-manager/test/acme"
-
- "github.com/cert-manager/webhook-example/example"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestRunsSuite(t *testing.T) {
- // The manifest path should contain a file named config.json that is a
- // snippet of valid configuration that should be included on the
- // ChallengeRequest passed as part of the test cases.
- //
+ zone := strings.TrimSuffix(strings.TrimSpace(os.Getenv("TEST_ZONE_NAME")), ".")
+ if zone == "" {
+ t.Fatal("TEST_ZONE_NAME must specify a Hostinger-managed DNS zone")
+ }
+ token := strings.TrimSpace(os.Getenv("HOSTINGER_API_TOKEN"))
+ if token == "" {
+ t.Fatal("HOSTINGER_API_TOKEN must be set to run the live conformance suite")
+ }
- // Uncomment the below fixture when implementing your custom DNS provider
- //fixture := acmetest.NewFixture(&customDNSProviderSolver{},
- // acmetest.SetResolvedZone(zone),
- // acmetest.SetAllowAmbientCredentials(false),
- // acmetest.SetManifestPath("testdata/my-custom-solver"),
- // acmetest.SetBinariesPath("_test/kubebuilder/bin"),
- //)
- solver := example.New("59351")
- fixture := acmetest.NewFixture(solver,
- acmetest.SetResolvedZone("example.com."),
- acmetest.SetManifestPath("testdata/my-custom-solver"),
- acmetest.SetDNSServer("127.0.0.1:59351"),
- acmetest.SetUseAuthoritative(false),
- )
- //need to uncomment and RunConformance delete runBasic and runExtended once https://github.com/cert-manager/cert-manager/pull/4835 is merged
- //fixture.RunConformance(t)
- fixture.RunBasic(t)
- fixture.RunExtended(t)
+ // The fixture applies this Secret in each test's temporary Kubernetes
+ // namespace, exercising the solver's normal credential lookup.
+ manifests := t.TempDir()
+ secret := &corev1.Secret{
+ TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Secret"},
+ ObjectMeta: metav1.ObjectMeta{Name: "hostinger-api-token"},
+ Data: map[string][]byte{"api-token": []byte(token)},
+ }
+ data, err := json.Marshal(secret)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(manifests, "secret.json"), data, 0600); err != nil {
+ t.Fatal(err)
+ }
+ cfg := customDNSProviderConfig{}
+ cfg.APIKeySecretRef.Name = secret.Name
+ cfg.APIKeySecretRef.Key = "api-token"
+ // Use a fresh DNS name to avoid cached records and overlapping test runs.
+ domain := "cert-manager-conformance-" + strings.ToLower(rand.Text()) + "." + zone
+ fixture := acmetest.NewFixture(&customDNSProviderSolver{},
+ acmetest.SetResolvedZone(zone+"."),
+ acmetest.SetResolvedFQDN("_acme-challenge."+domain+"."),
+ acmetest.SetDNSName(domain),
+ acmetest.SetAllowAmbientCredentials(false),
+ acmetest.SetConfig(cfg),
+ acmetest.SetManifestPath(manifests),
+ acmetest.SetStrict(true),
+ acmetest.SetPropagationLimit(5*time.Minute),
+ )
+ fixture.RunConformance(t)
}