2018-03-31 16:33:48 +02:00
|
|
|
package glesys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-07-30 21:19:32 +02:00
|
|
|
"github.com/go-acme/lego/v3/platform/tester"
|
2018-09-24 21:07:20 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-03-31 16:33:48 +02:00
|
|
|
)
|
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
var envTest = tester.NewEnvTest(
|
|
|
|
"GLESYS_API_USER",
|
|
|
|
"GLESYS_API_KEY").
|
|
|
|
WithDomain("GLESYS_DOMAIN")
|
2018-10-12 19:29:18 +02:00
|
|
|
|
2018-03-31 16:33:48 +02:00
|
|
|
func TestNewDNSProvider(t *testing.T) {
|
2018-10-12 19:29:18 +02:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
envVars map[string]string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "success",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"GLESYS_API_USER": "A",
|
|
|
|
"GLESYS_API_KEY": "B",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing credentials",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"GLESYS_API_USER": "",
|
|
|
|
"GLESYS_API_KEY": "",
|
|
|
|
},
|
|
|
|
expected: "glesys: some credentials information are missing: GLESYS_API_USER,GLESYS_API_KEY",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api user",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"GLESYS_API_USER": "",
|
|
|
|
"GLESYS_API_KEY": "B",
|
|
|
|
},
|
|
|
|
expected: "glesys: some credentials information are missing: GLESYS_API_USER",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api key",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"GLESYS_API_USER": "A",
|
|
|
|
"GLESYS_API_KEY": "",
|
|
|
|
},
|
|
|
|
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 17:52:57 +02:00
|
|
|
defer envTest.RestoreEnv()
|
|
|
|
envTest.ClearEnv()
|
|
|
|
|
|
|
|
envTest.Apply(test.envVars)
|
2018-10-12 19:29:18 +02: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 16:33:48 +02:00
|
|
|
|
2018-10-12 19:29:18 +02: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 16:33:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 19:29:18 +02:00
|
|
|
func TestLivePresent(t *testing.T) {
|
2018-10-16 17:52:57 +02:00
|
|
|
if !envTest.IsLiveTest() {
|
2018-03-31 16:33:48 +02:00
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
envTest.RestoreEnv()
|
2018-03-31 16:33:48 +02:00
|
|
|
provider, err := NewDNSProvider()
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-31 16:33:48 +02:00
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
err = provider.Present(envTest.GetDomain(), "", "123d==")
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-31 16:33:48 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 19:29:18 +02:00
|
|
|
func TestLiveCleanUp(t *testing.T) {
|
2018-10-16 17:52:57 +02:00
|
|
|
if !envTest.IsLiveTest() {
|
2018-03-31 16:33:48 +02:00
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
envTest.RestoreEnv()
|
2018-03-31 16:33:48 +02:00
|
|
|
provider, err := NewDNSProvider()
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-31 16:33:48 +02:00
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-31 16:33:48 +02:00
|
|
|
}
|