lego/providers/dns/ovh/ovh_test.go

146 lines
3.5 KiB
Go
Raw Normal View History

2016-06-16 19:11:19 +00:00
package ovh
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2016-06-16 19:11:19 +00:00
)
var (
2016-06-24 18:23:28 +00:00
liveTest bool
apiEndpoint string
applicationKey string
2016-06-16 19:11:19 +00:00
applicationSecret string
2016-06-24 18:23:28 +00:00
consumerKey string
domain string
2016-06-16 19:11:19 +00:00
)
func init() {
apiEndpoint = os.Getenv("OVH_ENDPOINT")
applicationKey = os.Getenv("OVH_APPLICATION_KEY")
applicationSecret = os.Getenv("OVH_APPLICATION_SECRET")
consumerKey = os.Getenv("OVH_CONSUMER_KEY")
liveTest = len(apiEndpoint) > 0 && len(applicationKey) > 0 && len(applicationSecret) > 0 && len(consumerKey) > 0
}
func restoreEnv() {
os.Setenv("OVH_ENDPOINT", apiEndpoint)
os.Setenv("OVH_APPLICATION_KEY", applicationKey)
os.Setenv("OVH_APPLICATION_SECRET", applicationSecret)
os.Setenv("OVH_CONSUMER_KEY", consumerKey)
}
func TestNewDNSProviderValidEnv(t *testing.T) {
defer restoreEnv()
2016-06-16 19:11:19 +00:00
os.Setenv("OVH_ENDPOINT", "ovh-eu")
os.Setenv("OVH_APPLICATION_KEY", "1234")
os.Setenv("OVH_APPLICATION_SECRET", "5678")
os.Setenv("OVH_CONSUMER_KEY", "abcde")
2016-06-16 19:11:19 +00:00
_, err := NewDNSProvider()
require.NoError(t, err)
2016-06-16 19:11:19 +00:00
}
func TestNewDNSProviderMissingCredErr(t *testing.T) {
defer restoreEnv()
testCases := []struct {
desc string
envVars map[string]string
expected string
}{
{
desc: "missing OVH_ENDPOINT",
envVars: map[string]string{
"OVH_ENDPOINT": "",
"OVH_APPLICATION_KEY": "1234",
"OVH_APPLICATION_SECRET": "5678",
"OVH_CONSUMER_KEY": "abcde",
},
expected: "ovh: some credentials information are missing: OVH_ENDPOINT",
},
{
desc: "missing OVH_APPLICATION_KEY",
envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu",
"OVH_APPLICATION_KEY": "",
"OVH_APPLICATION_SECRET": "5678",
"OVH_CONSUMER_KEY": "abcde",
},
expected: "ovh: some credentials information are missing: OVH_APPLICATION_KEY",
},
{
desc: "missing OVH_APPLICATION_SECRET",
envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu",
"OVH_APPLICATION_KEY": "1234",
"OVH_APPLICATION_SECRET": "",
"OVH_CONSUMER_KEY": "abcde",
},
expected: "ovh: some credentials information are missing: OVH_APPLICATION_SECRET",
},
{
desc: "missing OVH_CONSUMER_KEY",
envVars: map[string]string{
"OVH_ENDPOINT": "ovh-eu",
"OVH_APPLICATION_KEY": "1234",
"OVH_APPLICATION_SECRET": "5678",
"OVH_CONSUMER_KEY": "",
},
expected: "ovh: some credentials information are missing: OVH_CONSUMER_KEY",
},
{
desc: "all missing",
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",
},
}
2016-06-16 19:11:19 +00:00
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
2016-06-16 19:11:19 +00:00
for key, value := range test.envVars {
os.Setenv(key, value)
}
_, err := NewDNSProvider()
assert.EqualError(t, err, test.expected)
})
}
2016-06-16 19:11:19 +00:00
}
func TestLivePresent(t *testing.T) {
if !liveTest {
t.Skip("skipping live test")
}
provider, err := NewDNSProvider()
require.NoError(t, err)
2016-06-16 19:11:19 +00:00
err = provider.Present(domain, "", "123d==")
require.NoError(t, err)
2016-06-16 19:11:19 +00:00
}
func TestLiveCleanUp(t *testing.T) {
if !liveTest {
t.Skip("skipping live test")
}
time.Sleep(time.Second * 1)
provider, err := NewDNSProvider()
require.NoError(t, err)
2016-06-16 19:11:19 +00:00
err = provider.CleanUp(domain, "", "123d==")
require.NoError(t, err)
2016-06-16 19:11:19 +00:00
}