-
Notifications
You must be signed in to change notification settings - Fork 35
/
main_test.go
85 lines (69 loc) · 1.8 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"os"
"testing"
dns "github.com/cert-manager/cert-manager/test/acme"
)
var (
zone = os.Getenv("TEST_ZONE_NAME")
dnsServer = getEnv("TEST_DNS_SERVER", "8.8.8.8:53")
)
func test(t *testing.T, manifestPath string) {
// 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.
fixture := dns.NewFixture(&powerDNSProviderSolver{},
dns.SetDNSServer(dnsServer),
dns.SetResolvedZone(zone),
dns.SetAllowAmbientCredentials(false),
dns.SetManifestPath(manifestPath),
dns.SetStrict(true),
)
fixture.RunConformance(t)
}
func TestNoProxyNoTLS(t *testing.T) {
test(t, "_out/testdata/no-tls")
}
func TestNoProxyNoTLSAuthHdr(t *testing.T) {
test(t, "_out/testdata/no-tls-auth-hdr")
}
func TestNoProxyTLS(t *testing.T) {
test(t, "_out/testdata/tls")
}
func TestNoProxyTLSAuthHdr(t *testing.T) {
test(t, "_out/testdata/tls-auth-hdr")
}
func TestProxyNoTLS(t *testing.T) {
test(t, "_out/testdata/no-tls-with-proxy")
}
func TestProxyTLS(t *testing.T) {
test(t, "_out/testdata/tls-with-proxy")
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func TestIsAllowedZones(t *testing.T) {
cfg := powerDNSProviderConfig{
AllowedZones: []string{"example.com.", "example.org."},
}
tests := []struct {
zone string
matched bool
}{
{"foo.example.com.", true},
{"foo.example.net.", false},
{"example.com.", true},
{"notexample.com.", false},
}
for _, tt := range tests {
t.Run(tt.zone, func(t *testing.T) {
match := cfg.IsAllowedZone(tt.zone)
if match != tt.matched {
t.Errorf("Unexpected IsAllowedZone(%s) = %t, expected %t", tt.zone, match, tt.matched)
}
})
}
}