2016-06-16 19:11:19 +00:00
|
|
|
package ovh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2018-06-11 15:32:50 +00:00
|
|
|
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")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2016-06-16 19:11:19 +00:00
|
|
|
_, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
|
|
|
defer restoreEnv()
|
|
|
|
|
2018-06-11 15:32:50 +00:00
|
|
|
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",
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing OVH_APPLICATION_KEY",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
|
|
|
"OVH_APPLICATION_KEY": "",
|
|
|
|
"OVH_APPLICATION_SECRET": "5678",
|
|
|
|
"OVH_CONSUMER_KEY": "abcde",
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing OVH_APPLICATION_SECRET",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
|
|
|
"OVH_APPLICATION_KEY": "1234",
|
|
|
|
"OVH_APPLICATION_SECRET": "",
|
|
|
|
"OVH_CONSUMER_KEY": "abcde",
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "missing OVH_CONSUMER_KEY",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "ovh-eu",
|
|
|
|
"OVH_APPLICATION_KEY": "1234",
|
|
|
|
"OVH_APPLICATION_SECRET": "5678",
|
|
|
|
"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
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "all missing",
|
|
|
|
envVars: map[string]string{
|
|
|
|
"OVH_ENDPOINT": "",
|
|
|
|
"OVH_APPLICATION_KEY": "",
|
|
|
|
"OVH_APPLICATION_SECRET": "",
|
|
|
|
"OVH_CONSUMER_KEY": "",
|
|
|
|
},
|
2018-09-15 17:07:24 +00:00
|
|
|
expected: "ovh: some credentials information are missing: OVH_ENDPOINT,OVH_APPLICATION_KEY,OVH_APPLICATION_SECRET,OVH_CONSUMER_KEY",
|
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 {
|
|
|
|
test := test
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
2016-06-16 19:11:19 +00:00
|
|
|
|
2018-06-11 15:32:50 +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()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.Present(domain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiveCleanUp(t *testing.T) {
|
|
|
|
if !liveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 1)
|
|
|
|
|
|
|
|
provider, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(domain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|