2019-03-11 16:56:48 +00:00
|
|
|
package ovh
|
2016-06-16 19:11:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
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"
|
2016-06-16 19:11:19 +00:00
|
|
|
)
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
var envTest = tester.NewEnvTest(
|
|
|
|
"OVH_ENDPOINT",
|
|
|
|
"OVH_APPLICATION_KEY",
|
|
|
|
"OVH_APPLICATION_SECRET",
|
|
|
|
"OVH_CONSUMER_KEY").
|
|
|
|
WithDomain("OVH_DOMAIN")
|
2016-06-16 19:11:19 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
func TestNewDNSProvider(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
envVars map[string]string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
2018-10-12 17:29:18 +00:00
|
|
|
desc: "success",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
|
|
|
"OVH_APPLICATION_KEY": "B",
|
|
|
|
"OVH_APPLICATION_SECRET": "C",
|
|
|
|
"OVH_CONSUMER_KEY": "D",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing credentials",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "",
|
|
|
|
"OVH_APPLICATION_KEY": "",
|
|
|
|
"OVH_APPLICATION_SECRET": "",
|
|
|
|
"OVH_CONSUMER_KEY": "",
|
|
|
|
},
|
|
|
|
expected: "ovh: some credentials information are missing: OVH_ENDPOINT,OVH_APPLICATION_KEY,OVH_APPLICATION_SECRET,OVH_CONSUMER_KEY",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing endpoint",
|
2018-06-11 15:32:50 +00:00
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "",
|
2018-10-12 17:29:18 +00:00
|
|
|
"OVH_APPLICATION_KEY": "B",
|
|
|
|
"OVH_APPLICATION_SECRET": "C",
|
|
|
|
"OVH_CONSUMER_KEY": "D",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
2018-09-15 17:07:24 +00:00
|
|
|
expected: "ovh: some credentials information are missing: OVH_ENDPOINT",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
|
|
|
{
|
2018-10-12 17:29:18 +00:00
|
|
|
desc: "missing invalid endpoint",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "foobar",
|
|
|
|
"OVH_APPLICATION_KEY": "B",
|
|
|
|
"OVH_APPLICATION_SECRET": "C",
|
|
|
|
"OVH_CONSUMER_KEY": "D",
|
|
|
|
},
|
|
|
|
expected: "ovh: unknown endpoint 'foobar', consider checking 'Endpoints' list of using an URL",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing application key",
|
2018-06-11 15:32:50 +00:00
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
|
|
|
"OVH_APPLICATION_KEY": "",
|
2018-10-12 17:29:18 +00:00
|
|
|
"OVH_APPLICATION_SECRET": "C",
|
|
|
|
"OVH_CONSUMER_KEY": "D",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
2018-09-15 17:07:24 +00:00
|
|
|
expected: "ovh: some credentials information are missing: OVH_APPLICATION_KEY",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
|
|
|
{
|
2018-10-12 17:29:18 +00:00
|
|
|
desc: "missing application secret",
|
2018-06-11 15:32:50 +00:00
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
2018-10-12 17:29:18 +00:00
|
|
|
"OVH_APPLICATION_KEY": "B",
|
2018-06-11 15:32:50 +00:00
|
|
|
"OVH_APPLICATION_SECRET": "",
|
2018-10-12 17:29:18 +00:00
|
|
|
"OVH_CONSUMER_KEY": "D",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
2018-09-15 17:07:24 +00:00
|
|
|
expected: "ovh: some credentials information are missing: OVH_APPLICATION_SECRET",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
|
|
|
{
|
2018-10-12 17:29:18 +00:00
|
|
|
desc: "missing consumer key",
|
2018-06-11 15:32:50 +00:00
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
2018-10-12 17:29:18 +00:00
|
|
|
"OVH_APPLICATION_KEY": "B",
|
|
|
|
"OVH_APPLICATION_SECRET": "C",
|
2018-06-11 15:32:50 +00:00
|
|
|
"OVH_CONSUMER_KEY": "",
|
|
|
|
},
|
2018-09-15 17:07:24 +00:00
|
|
|
expected: "ovh: some credentials information are missing: OVH_CONSUMER_KEY",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
2018-10-12 17:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.client)
|
|
|
|
require.NotNil(t, p.recordIDs)
|
|
|
|
} else {
|
|
|
|
require.EqualError(t, err, test.expected)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderConfig(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
apiEndpoint string
|
|
|
|
applicationKey string
|
|
|
|
applicationSecret string
|
|
|
|
consumerKey string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "success",
|
|
|
|
apiEndpoint: "ovh-eu",
|
|
|
|
applicationKey: "B",
|
|
|
|
applicationSecret: "C",
|
|
|
|
consumerKey: "D",
|
|
|
|
},
|
2018-06-11 15:32:50 +00:00
|
|
|
{
|
2018-10-12 17:29:18 +00:00
|
|
|
desc: "missing credentials",
|
|
|
|
expected: "ovh: credentials missing",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing api endpoint",
|
|
|
|
apiEndpoint: "",
|
|
|
|
applicationKey: "B",
|
|
|
|
applicationSecret: "C",
|
|
|
|
consumerKey: "D",
|
|
|
|
expected: "ovh: credentials missing",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing invalid api endpoint",
|
|
|
|
apiEndpoint: "foobar",
|
|
|
|
applicationKey: "B",
|
|
|
|
applicationSecret: "C",
|
|
|
|
consumerKey: "D",
|
|
|
|
expected: "ovh: unknown endpoint 'foobar', consider checking 'Endpoints' list of using an URL",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing application key",
|
|
|
|
apiEndpoint: "ovh-eu",
|
|
|
|
applicationKey: "",
|
|
|
|
applicationSecret: "C",
|
|
|
|
consumerKey: "D",
|
|
|
|
expected: "ovh: credentials missing",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing application secret",
|
|
|
|
apiEndpoint: "ovh-eu",
|
|
|
|
applicationKey: "B",
|
|
|
|
applicationSecret: "",
|
|
|
|
consumerKey: "D",
|
|
|
|
expected: "ovh: credentials missing",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing consumer key",
|
|
|
|
apiEndpoint: "ovh-eu",
|
|
|
|
applicationKey: "B",
|
|
|
|
applicationSecret: "C",
|
|
|
|
consumerKey: "",
|
|
|
|
expected: "ovh: credentials missing",
|
2018-06-11 15:32:50 +00:00
|
|
|
},
|
|
|
|
}
|
2016-06-16 19:11:19 +00:00
|
|
|
|
2018-06-11 15:32:50 +00:00
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
2018-10-12 17:29:18 +00:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIEndpoint = test.apiEndpoint
|
|
|
|
config.ApplicationKey = test.applicationKey
|
|
|
|
config.ApplicationSecret = test.applicationSecret
|
|
|
|
config.ConsumerKey = test.consumerKey
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
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)
|
|
|
|
require.NotNil(t, p.recordIDs)
|
|
|
|
} else {
|
|
|
|
require.EqualError(t, err, test.expected)
|
|
|
|
}
|
2018-06-11 15:32:50 +00:00
|
|
|
})
|
|
|
|
}
|
2016-06-16 19:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLivePresent(t *testing.T) {
|
2018-10-16 15:52:57 +00:00
|
|
|
if !envTest.IsLiveTest() {
|
2016-06-16 19:11:19 +00:00
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
envTest.RestoreEnv()
|
2016-06-16 19:11:19 +00:00
|
|
|
provider, err := NewDNSProvider()
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2016-06-16 19:11:19 +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)
|
2016-06-16 19:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiveCleanUp(t *testing.T) {
|
2018-10-16 15:52:57 +00:00
|
|
|
if !envTest.IsLiveTest() {
|
2016-06-16 19:11:19 +00:00
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
envTest.RestoreEnv()
|
2016-06-16 19:11:19 +00:00
|
|
|
provider, err := NewDNSProvider()
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2016-06-16 19:11:19 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
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)
|
2016-06-16 19:11:19 +00:00
|
|
|
}
|