2019-04-28 12:33:50 +00:00
|
|
|
package joker
|
|
|
|
|
|
|
|
import (
|
2020-10-08 14:52:50 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2019-04-28 12:33:50 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-09-02 01:20:01 +00:00
|
|
|
"github.com/go-acme/lego/v4/platform/tester"
|
2019-04-28 12:33:50 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-03-11 22:51:10 +00:00
|
|
|
const envDomain = envNamespace + "DOMAIN"
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
var envTest = tester.NewEnvTest(EnvAPIKey, EnvUsername, EnvPassword, EnvMode).
|
2020-03-11 22:51:10 +00:00
|
|
|
WithDomain(envDomain)
|
2019-04-28 12:33:50 +00:00
|
|
|
|
|
|
|
func TestNewDNSProvider(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
envVars map[string]string
|
2020-10-08 14:52:50 +00:00
|
|
|
expected interface{}
|
2019-04-28 12:33:50 +00:00
|
|
|
}{
|
|
|
|
{
|
2020-10-08 14:52:50 +00:00
|
|
|
desc: "mode DMAPI (default)",
|
2019-04-28 12:33:50 +00:00
|
|
|
envVars: map[string]string{
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvUsername: "123",
|
|
|
|
EnvPassword: "123",
|
2019-04-28 12:33:50 +00:00
|
|
|
},
|
2020-10-08 14:52:50 +00:00
|
|
|
expected: &dmapiProvider{},
|
2019-07-17 00:39:17 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-08 14:52:50 +00:00
|
|
|
desc: "mode DMAPI",
|
2019-07-17 00:39:17 +00:00
|
|
|
envVars: map[string]string{
|
2020-10-08 14:52:50 +00:00
|
|
|
EnvMode: modeDMAPI,
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvUsername: "123",
|
2020-10-08 14:52:50 +00:00
|
|
|
EnvPassword: "123",
|
2019-07-17 00:39:17 +00:00
|
|
|
},
|
2020-10-08 14:52:50 +00:00
|
|
|
expected: &dmapiProvider{},
|
2019-07-17 00:39:17 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-08 14:52:50 +00:00
|
|
|
desc: "mode SVC",
|
2019-07-17 00:39:17 +00:00
|
|
|
envVars: map[string]string{
|
2020-10-08 14:52:50 +00:00
|
|
|
EnvMode: modeSVC,
|
|
|
|
EnvUsername: "123",
|
2020-03-11 22:51:10 +00:00
|
|
|
EnvPassword: "123",
|
2019-07-17 00:39:17 +00:00
|
|
|
},
|
2020-10-08 14:52:50 +00:00
|
|
|
expected: &svcProvider{},
|
2019-04-28 12:33:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
defer envTest.RestoreEnv()
|
|
|
|
envTest.ClearEnv()
|
|
|
|
|
|
|
|
envTest.Apply(test.envVars)
|
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
fmt.Println(os.Getenv(EnvMode))
|
|
|
|
|
2019-04-28 12:33:50 +00:00
|
|
|
p, err := NewDNSProvider()
|
2020-10-08 14:52:50 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, p)
|
2019-04-28 12:33:50 +00:00
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
assert.IsType(t, test.expected, p)
|
2019-04-28 12:33:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderConfig(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2020-10-08 14:52:50 +00:00
|
|
|
desc string
|
|
|
|
mode string
|
|
|
|
expected interface{}
|
2019-04-28 12:33:50 +00:00
|
|
|
}{
|
|
|
|
{
|
2020-10-08 14:52:50 +00:00
|
|
|
desc: "mode DMAPI (default)",
|
|
|
|
expected: &dmapiProvider{},
|
2019-04-28 12:33:50 +00:00
|
|
|
},
|
2019-07-17 00:39:17 +00:00
|
|
|
{
|
2020-10-08 14:52:50 +00:00
|
|
|
desc: "mode DMAPI",
|
|
|
|
mode: modeDMAPI,
|
|
|
|
expected: &dmapiProvider{},
|
2019-07-17 00:39:17 +00:00
|
|
|
},
|
|
|
|
{
|
2020-10-08 14:52:50 +00:00
|
|
|
desc: "mode SVC",
|
|
|
|
mode: modeSVC,
|
|
|
|
expected: &svcProvider{},
|
2019-04-28 12:33:50 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
config := NewDefaultConfig()
|
2020-10-08 14:52:50 +00:00
|
|
|
config.Username = "123"
|
|
|
|
config.Password = "123"
|
|
|
|
config.APIMode = test.mode
|
2019-04-28 12:33:50 +00:00
|
|
|
|
|
|
|
p, err := NewDNSProviderConfig(config)
|
2020-10-08 14:52:50 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, p)
|
2019-04-28 12:33:50 +00:00
|
|
|
|
2020-10-08 14:52:50 +00:00
|
|
|
assert.IsType(t, test.expected, p)
|
2019-04-28 12:33:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLivePresent(t *testing.T) {
|
|
|
|
if !envTest.IsLiveTest() {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
envTest.RestoreEnv()
|
|
|
|
provider, err := NewDNSProvider()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.Present(envTest.GetDomain(), "", "123d==")
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiveCleanUp(t *testing.T) {
|
|
|
|
if !envTest.IsLiveTest() {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
envTest.RestoreEnv()
|
|
|
|
provider, err := NewDNSProvider()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|