lego/providers/dns/netcup/netcup_test.go
Ludovic Fernandez 42941ccea6
Refactor the core of the lib (#700)
- Packages
- Isolate code used by the CLI into the package `cmd`
- (experimental) Add e2e tests for HTTP01, TLS-ALPN-01 and DNS-01, use [Pebble](https://github.com/letsencrypt/pebble) and [challtestsrv](https://github.com/letsencrypt/boulder/tree/master/test/challtestsrv) 
- Support non-ascii domain name (punnycode)
- Check all challenges in a predictable order
- No more global exported variables
- Archive revoked certificates
- Fixes revocation for subdomains and non-ascii domains
- Disable pending authorizations
- use pointer for RemoteError/ProblemDetails
- Poll authz URL instead of challenge URL
- The ability for a DNS provider to solve the challenge sequentially
- Check all nameservers in a predictable order
- Option to disable the complete propagation Requirement
- CLI, support for renew with CSR
- CLI, add SAN on renew
- Add command to list certificates.
- Logs every iteration of waiting for the propagation
- update DNSimple client
- update github.com/miekg/dns
2018-12-06 22:50:17 +01:00

185 lines
4 KiB
Go

package netcup
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/xenolf/lego/challenge/dns01"
"github.com/xenolf/lego/platform/tester"
)
var envTest = tester.NewEnvTest(
"NETCUP_CUSTOMER_NUMBER",
"NETCUP_API_KEY",
"NETCUP_API_PASSWORD").
WithDomain("NETCUP_DOMAIN")
func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
desc string
envVars map[string]string
expected string
}{
{
desc: "success",
envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "A",
"NETCUP_API_KEY": "B",
"NETCUP_API_PASSWORD": "C",
},
},
{
desc: "missing credentials",
envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "",
"NETCUP_API_KEY": "",
"NETCUP_API_PASSWORD": "",
},
expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER,NETCUP_API_KEY,NETCUP_API_PASSWORD",
},
{
desc: "missing customer number",
envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "",
"NETCUP_API_KEY": "B",
"NETCUP_API_PASSWORD": "C",
},
expected: "netcup: some credentials information are missing: NETCUP_CUSTOMER_NUMBER",
},
{
desc: "missing API key",
envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "A",
"NETCUP_API_KEY": "",
"NETCUP_API_PASSWORD": "C",
},
expected: "netcup: some credentials information are missing: NETCUP_API_KEY",
},
{
desc: "missing api password",
envVars: map[string]string{
"NETCUP_CUSTOMER_NUMBER": "A",
"NETCUP_API_KEY": "B",
"NETCUP_API_PASSWORD": "",
},
expected: "netcup: some credentials information are missing: NETCUP_API_PASSWORD",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
defer envTest.RestoreEnv()
envTest.ClearEnv()
envTest.Apply(test.envVars)
p, err := NewDNSProvider()
if len(test.expected) == 0 {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
require.NotNil(t, p.client)
} else {
require.EqualError(t, err, test.expected)
}
})
}
}
func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
desc string
customer string
key string
password string
expected string
}{
{
desc: "success",
customer: "A",
key: "B",
password: "C",
},
{
desc: "missing credentials",
expected: "netcup: credentials missing",
},
{
desc: "missing customer",
customer: "",
key: "B",
password: "C",
expected: "netcup: credentials missing",
},
{
desc: "missing key",
customer: "A",
key: "",
password: "C",
expected: "netcup: credentials missing",
},
{
desc: "missing password",
customer: "A",
key: "B",
password: "",
expected: "netcup: credentials missing",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
config.Customer = test.customer
config.Key = test.key
config.Password = test.password
p, err := NewDNSProviderConfig(config)
if len(test.expected) == 0 {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
require.NotNil(t, p.client)
} else {
require.EqualError(t, err, test.expected)
}
})
}
}
func TestLivePresentAndCleanup(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
p, err := NewDNSProvider()
require.NoError(t, err)
fqdn, _ := dns01.GetRecord(envTest.GetDomain(), "123d==")
zone, err := dns01.FindZoneByFqdn(fqdn)
require.NoError(t, err, "error finding DNSZone")
zone = dns01.UnFqdn(zone)
testCases := []string{
zone,
"sub." + zone,
"*." + zone,
"*.sub." + zone,
}
for _, test := range testCases {
t.Run(fmt.Sprintf("domain(%s)", test), func(t *testing.T) {
err = p.Present(test, "987d", "123d==")
require.NoError(t, err)
err = p.CleanUp(test, "987d", "123d==")
require.NoError(t, err, "Did not clean up! Please remove record yourself.")
})
}
}