2018-03-31 14:33:48 +00:00
|
|
|
package glesys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-07-30 19:19:32 +00:00
|
|
|
"github.com/go-acme/lego/v3/platform/tester"
|
2018-09-24 19:07:20 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-03-31 14:33:48 +00:00
|
|
|
)
|
|
|
|
|
2020-03-11 22:51:10 +00:00
|
|
|
const envDomain = envNamespace + "DOMAIN"
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
var envTest = tester.NewEnvTest(
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvAPIUser,
|
|
|
|
EnvAPIKey).
|
|
|
|
WithDomain(envDomain)
|
2018-10-12 17:29:18 +00:00
|
|
|
|
2018-03-31 14:33:48 +00:00
|
|
|
func TestNewDNSProvider(t *testing.T) {
|
2018-10-12 17:29:18 +00:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
envVars map[string]string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "success",
|
|
|
|
envVars: map[string]string{
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvAPIUser: "A",
|
|
|
|
EnvAPIKey: "B",
|
2018-10-12 17:29:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing credentials",
|
|
|
|
envVars: map[string]string{
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvAPIUser: "",
|
|
|
|
EnvAPIKey: "",
|
2018-10-12 17:29:18 +00:00
|
|
|
},
|
|
|
|
expected: "glesys: some credentials information are missing: GLESYS_API_USER,GLESYS_API_KEY",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api user",
|
|
|
|
envVars: map[string]string{
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvAPIUser: "",
|
|
|
|
EnvAPIKey: "B",
|
2018-10-12 17:29:18 +00:00
|
|
|
},
|
|
|
|
expected: "glesys: some credentials information are missing: GLESYS_API_USER",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api key",
|
|
|
|
envVars: map[string]string{
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvAPIUser: "A",
|
|
|
|
EnvAPIKey: "",
|
2018-10-12 17:29:18 +00:00
|
|
|
},
|
|
|
|
expected: "glesys: some credentials information are missing: GLESYS_API_KEY",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
2018-10-16 15:52:57 +00:00
|
|
|
defer envTest.RestoreEnv()
|
|
|
|
envTest.ClearEnv()
|
|
|
|
|
|
|
|
envTest.Apply(test.envVars)
|
2018-10-12 17:29:18 +00:00
|
|
|
|
|
|
|
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.activeRecords)
|
|
|
|
} else {
|
|
|
|
require.EqualError(t, err, test.expected)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderConfig(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
apiUser string
|
|
|
|
apiKey string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "success",
|
|
|
|
apiUser: "A",
|
|
|
|
apiKey: "B",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing credentials",
|
|
|
|
expected: "glesys: incomplete credentials provided",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api user",
|
|
|
|
apiUser: "",
|
|
|
|
apiKey: "B",
|
|
|
|
expected: "glesys: incomplete credentials provided",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api key",
|
|
|
|
apiUser: "A",
|
|
|
|
apiKey: "",
|
|
|
|
expected: "glesys: incomplete credentials provided",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = test.apiKey
|
|
|
|
config.APIUser = test.apiUser
|
|
|
|
|
|
|
|
p, err := NewDNSProviderConfig(config)
|
2018-03-31 14:33:48 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
if len(test.expected) == 0 {
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, p)
|
|
|
|
require.NotNil(t, p.config)
|
|
|
|
require.NotNil(t, p.activeRecords)
|
|
|
|
} else {
|
|
|
|
require.EqualError(t, err, test.expected)
|
|
|
|
}
|
|
|
|
})
|
2018-03-31 14:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
func TestLivePresent(t *testing.T) {
|
2018-10-16 15:52:57 +00:00
|
|
|
if !envTest.IsLiveTest() {
|
2018-03-31 14:33:48 +00:00
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
envTest.RestoreEnv()
|
2018-03-31 14:33:48 +00:00
|
|
|
provider, err := NewDNSProvider()
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2018-03-31 14:33:48 +00:00
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
err = provider.Present(envTest.GetDomain(), "", "123d==")
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2018-03-31 14:33:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
func TestLiveCleanUp(t *testing.T) {
|
2018-10-16 15:52:57 +00:00
|
|
|
if !envTest.IsLiveTest() {
|
2018-03-31 14:33:48 +00:00
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
envTest.RestoreEnv()
|
2018-03-31 14:33:48 +00:00
|
|
|
provider, err := NewDNSProvider()
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2018-03-31 14:33:48 +00:00
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2018-03-31 14:33:48 +00:00
|
|
|
}
|