diff --git a/providers/dns/liquidweb/liquidweb.go b/providers/dns/liquidweb/liquidweb.go index 6549c08d93..8dcd5eeb1e 100644 --- a/providers/dns/liquidweb/liquidweb.go +++ b/providers/dns/liquidweb/liquidweb.go @@ -16,22 +16,21 @@ import ( "github.com/liquidweb/liquidweb-go/network" ) -const DefaultBaseURL = "https://api.liquidweb.com" +const defaultBaseURL = "https://api.liquidweb.com" // Environment variables names. const ( - EnvPrefix = "LWAPI_" - envLegacyPrefix = "LIQUID_WEB_" - - EnvURL = "URL" - EnvUsername = "USERNAME" - EnvPassword = "PASSWORD" - - EnvZone = "ZONE" - EnvTTL = "TTL" - EnvPropagationTimeout = "PROPAGATION_TIMEOUT" - EnvPollingInterval = "POLLING_INTERVAL" - EnvHTTPTimeout = "HTTP_TIMEOUT" + envNamespace = "LIQUID_WEB_" + + EnvURL = envNamespace + "URL" + EnvUsername = envNamespace + "USERNAME" + EnvPassword = envNamespace + "PASSWORD" + + EnvZone = envNamespace + "ZONE" + EnvTTL = envNamespace + "TTL" + EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT" + EnvPollingInterval = envNamespace + "POLLING_INTERVAL" + EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT" ) // Config is used to configure the creation of the DNSProvider. @@ -46,6 +45,17 @@ type Config struct { HTTPTimeout time.Duration } +// NewDefaultConfig returns a default configuration for the DNSProvider. +func NewDefaultConfig() *Config { + return &Config{ + BaseURL: defaultBaseURL, + TTL: env.GetOrDefaultInt(EnvTTL, 300), + PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute), + PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second), + HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 1*time.Minute), + } +} + // DNSProvider implements the challenge.Provider interface. type DNSProvider struct { config *Config @@ -54,47 +64,32 @@ type DNSProvider struct { recordIDsMu sync.Mutex } -func getStringEnv(varName, defVal string) string { - defVal = env.GetOrDefaultString(envLegacyPrefix+varName, defVal) - defVal = env.GetOrDefaultString(EnvPrefix+varName, defVal) - return defVal -} +// NewDNSProvider returns a DNSProvider instance configured for Liquid Web. +func NewDNSProvider() (*DNSProvider, error) { + values, err := env.Get(EnvUsername, EnvPassword) + if err != nil { + return nil, fmt.Errorf("liquidweb: %w", err) + } -func getIntEnv(varName string, defVal int) int { - defVal = env.GetOrDefaultInt(envLegacyPrefix+varName, defVal) - defVal = env.GetOrDefaultInt(EnvPrefix+varName, defVal) - return defVal -} + config := NewDefaultConfig() + config.BaseURL = env.GetOrFile(EnvURL) + config.Username = values[EnvUsername] + config.Password = values[EnvPassword] + config.Zone = env.GetOrDefaultString(EnvZone, "") -func getSecondEnv(varName string, defVal time.Duration) time.Duration { - defVal = env.GetOrDefaultSecond(envLegacyPrefix+varName, defVal) - defVal = env.GetOrDefaultSecond(EnvPrefix+varName, defVal) - return defVal + return NewDNSProviderConfig(config) } -// NewDNSProvider returns a DNSProvider instance configured for Liquid Web. -func NewDNSProvider() (*DNSProvider, error) { - config := &Config{ - Username: getStringEnv(EnvUsername, ""), - Password: getStringEnv(EnvPassword, ""), - BaseURL: getStringEnv(EnvURL, DefaultBaseURL), - Zone: getStringEnv(EnvZone, ""), - TTL: getIntEnv(EnvTTL, 300), - PropagationTimeout: getSecondEnv(EnvPropagationTimeout, 2*time.Minute), - PollingInterval: getSecondEnv(EnvPollingInterval, 2*time.Second), - HTTPTimeout: getSecondEnv(EnvHTTPTimeout, 1*time.Minute), +// NewDNSProviderConfig return a DNSProvider instance configured for Liquid Web. +func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { + if config == nil { + return nil, errors.New("liquidweb: the configuration of the DNS provider is nil") } - switch { - case config.Username == "" && config.Password == "": - return nil, errors.New("liquidweb: username and password are missing, set LWAPI_USERNAME and LWAPI_PASSWORD") - case config.Username == "": - return nil, errors.New("liquidweb: username is missing, set LWAPI_USERNAME") - case config.Password == "": - return nil, errors.New("liquidweb: password is missing, set LWAPI_PASSWORD") + if config.BaseURL == "" { + config.BaseURL = defaultBaseURL } - // Initialize LW client. client, err := lw.NewAPI(config.Username, config.Password, config.BaseURL, int(config.HTTPTimeout.Seconds())) if err != nil { return nil, fmt.Errorf("liquidweb: could not create Liquid Web API client: %w", err) @@ -127,11 +122,11 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { if params.Zone == "" { bestZone, err := d.findZone(params.Name) - if err == nil { - params.Zone = bestZone - } else { + if err != nil { return err } + + params.Zone = bestZone } dnsEntry, err := d.client.NetworkDNS.Create(params) @@ -169,8 +164,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return nil } -func (d *DNSProvider) findZone(fqdn string) (string, error) { - fqdn = dns01.UnFqdn(fqdn) +func (d *DNSProvider) findZone(domain string) (string, error) { zones, err := d.client.NetworkDNSZone.ListAll() if err != nil { return "", fmt.Errorf("failed to retrieve zones for account: %w", err) @@ -178,7 +172,7 @@ func (d *DNSProvider) findZone(fqdn string) (string, error) { // filter the zones on the account to only ones that match for id := 0; id < len(zones.Items); { - if !strings.HasSuffix(fqdn, zones.Items[id].Name) { + if !strings.HasSuffix(domain, zones.Items[id].Name) { zones.Items = append(zones.Items[:id], zones.Items[id+1:]...) } else { id++ @@ -186,7 +180,7 @@ func (d *DNSProvider) findZone(fqdn string) (string, error) { } if len(zones.Items) < 1 { - return "", fmt.Errorf("no valid zone in account for certificate %s", fqdn) + return "", fmt.Errorf("no valid zone in account for certificate %s", domain) } // filter the zones on the account to only ones that @@ -194,8 +188,8 @@ func (d *DNSProvider) findZone(fqdn string) (string, error) { return len(zones.Items[i].Name) > len(zones.Items[j].Name) }) - // powerdns _only_ looks for records on the longest matching subdomain zone - // aka, for test.sub.example.com if sub.example.com exists, it will look there - // it will not look atexample.com even if it also exists + // powerdns _only_ looks for records on the longest matching subdomain zone aka, + // for test.sub.example.com if sub.example.com exists, + // it will look there it will not look atexample.com even if it also exists return zones.Items[0].Name, nil } diff --git a/providers/dns/liquidweb/liquidweb.toml b/providers/dns/liquidweb/liquidweb.toml index c9116912e7..3fc53b8e83 100644 --- a/providers/dns/liquidweb/liquidweb.toml +++ b/providers/dns/liquidweb/liquidweb.toml @@ -5,22 +5,22 @@ Code = "liquidweb" Since = "v3.1.0" Example = ''' -LWAPI_USERNAME=someuser \ -LWAPI_PASSWORD=somepass \ +LIQUID_WEB_USERNAME=someuser \ +LIQUID_WEB_PASSWORD=somepass \ lego --email you@example.com --dns liquidweb --domains my.example.org run ''' [Configuration] [Configuration.Credentials] - LWAPI_USERNAME = "Liquid Web API Username" - LWAPI_PASSWORD = "Liquid Web API Password" + LIQUID_WEB_USERNAME = "Liquid Web API Username" + LIQUID_WEB_PASSWORD = "Liquid Web API Password" [Configuration.Additional] - LWAPI_ZONE = "DNS Zone" - LWAPI_URL = "Liquid Web API endpoint" - LWAPI_TTL = "The TTL of the TXT record used for the DNS challenge" - LWAPI_POLLING_INTERVAL = "Time between DNS propagation check" - LWAPI_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" - LWAPI_HTTP_TIMEOUT = "Maximum waiting time for the DNS records to be created (not verified)" + LIQUID_WEB_ZONE = "DNS Zone" + LIQUID_WEB_URL = "Liquid Web API endpoint" + LIQUID_WEB_TTL = "The TTL of the TXT record used for the DNS challenge" + LIQUID_WEB_POLLING_INTERVAL = "Time between DNS propagation check" + LIQUID_WEB_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" + LIQUID_WEB_HTTP_TIMEOUT = "Maximum waiting time for the DNS records to be created (not verified)" [Links] API = "https://api.liquidweb.com/docs/" diff --git a/providers/dns/liquidweb/liquidweb_integration_test.go b/providers/dns/liquidweb/liquidweb_integration_test.go new file mode 100644 index 0000000000..c1883bd45f --- /dev/null +++ b/providers/dns/liquidweb/liquidweb_integration_test.go @@ -0,0 +1,255 @@ +package liquidweb + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/liquidweb/liquidweb-go/network" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func setupTest(t *testing.T) (*DNSProvider, *http.ServeMux) { + t.Helper() + + mux := http.NewServeMux() + server := httptest.NewServer(mux) + t.Cleanup(server.Close) + + config := NewDefaultConfig() + config.Username = "blars" + config.Password = "tacoman" + config.BaseURL = server.URL + config.Zone = "tacoman.com" + + provider, err := NewDNSProviderConfig(config) + require.NoError(t, err) + + return provider, mux +} + +// func TestDNSProvider_Present(t *testing.T) { +// provider, mux := setupTest(t) +// +// mux.HandleFunc("/v1/Network/DNS/Record/create", func(w http.ResponseWriter, r *http.Request) { +// assert.Equal(t, http.MethodPost, r.Method) +// +// username, password, ok := r.BasicAuth() +// assert.Equal(t, "blars", username) +// assert.Equal(t, "tacoman", password) +// assert.True(t, ok) +// +// reqBody, err := io.ReadAll(r.Body) +// if err != nil { +// http.Error(w, err.Error(), http.StatusInternalServerError) +// return +// } +// +// expectedReqBody := ` +// { +// "params": { +// "name": "_acme-challenge.tacoman.com", +// "rdata": "\"47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU\"", +// "ttl": 300, +// "type": "TXT", +// "zone": "tacoman.com" +// } +// }` +// assert.JSONEq(t, expectedReqBody, string(reqBody)) +// +// w.WriteHeader(http.StatusOK) +// _, err = fmt.Fprintf(w, `{ +// "type": "TXT", +// "name": "_acme-challenge.tacoman.com", +// "rdata": "\"47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU\"", +// "ttl": 300, +// "id": 1234567, +// "prio": null +// }`) +// if err != nil { +// http.Error(w, err.Error(), http.StatusInternalServerError) +// return +// } +// }) +// +// err := provider.Present("tacoman.com", "", "") +// require.NoError(t, err) +// } +// +// func TestDNSProvider_CleanUp(t *testing.T) { +// provider, mux := setupTest(t) +// +// mux.HandleFunc("/v1/Network/DNS/Record/delete", func(w http.ResponseWriter, r *http.Request) { +// assert.Equal(t, http.MethodPost, r.Method) +// +// username, password, ok := r.BasicAuth() +// assert.Equal(t, "blars", username) +// assert.Equal(t, "tacoman", password) +// assert.True(t, ok) +// +// _, err := fmt.Fprintf(w, `{"deleted": "123"}`) +// if err != nil { +// http.Error(w, err.Error(), http.StatusInternalServerError) +// return +// } +// }) +// +// provider.recordIDs["123"] = 1234567 +// +// err := provider.CleanUp("tacoman.com.", "123", "") +// require.NoError(t, err, "fail to remove TXT record") +// } + +func TestDNSProvider_Present(t *testing.T) { + envTest.Apply(map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + EnvURL: mockAPIServer(t), + EnvZone: "tacoman.com", // this needs to be removed from test? + }) + + defer envTest.ClearEnv() + + provider, err := NewDNSProvider() + require.NoError(t, err) + + err = provider.Present("tacoman.com", "", "") + require.NoError(t, err) +} + +func TestDNSProvider_CleanUp(t *testing.T) { + envTest.Apply(map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + EnvURL: mockAPIServer(t, network.DNSRecord{ + Name: "_acme-challenge.tacoman.com", + RData: "123d==", + Type: "TXT", + TTL: 300, + ID: 1234567, + ZoneID: 42, + }), + EnvZone: "tacoman.com", // this needs to be removed from test? + }) + + defer envTest.ClearEnv() + + provider, err := NewDNSProvider() + require.NoError(t, err) + + provider.recordIDs["123d=="] = 1234567 + + err = provider.CleanUp("tacoman.com.", "123d==", "") + require.NoError(t, err, "fail to remove TXT record") +} + +// FIXME +func TestIntegration(t *testing.T) { + testCases := []struct { + desc string + envVars map[string]string + initRecs []network.DNSRecord + domain string + token string + keyauth string + present bool + cleanup bool + expPresentErr string + expCleanupErr string + }{ + { + desc: "expected successful", + envVars: map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + }, + domain: "tacoman.com", + token: "123", + keyauth: "456", + present: true, + cleanup: true, + }, + { + desc: "other successful", + envVars: map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + }, + domain: "banana.com", + token: "123", + keyauth: "456", + present: true, + cleanup: true, + }, + { + desc: "zone not on account", + envVars: map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + }, + domain: "huckleberry.com", + token: "123", + keyauth: "456", + present: true, + cleanup: false, + expPresentErr: "no valid zone in account for certificate _acme-challenge.huckleberry.com", + }, + { + desc: "ssl for domain", + envVars: map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + }, + domain: "sundae.cherry.com", + token: "5847953", + keyauth: "34872934", + present: true, + cleanup: true, + expPresentErr: "", + }, + { + desc: "complicated domain", + envVars: map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + }, + domain: "always.money.stand.banana.com", + token: "5847953", + keyauth: "there is always money in the banana stand", + present: true, + cleanup: true, + expPresentErr: "", + }, + } + + for _, test := range testCases { + test := test + t.Run(test.desc, func(t *testing.T) { + test.envVars[EnvURL] = mockAPIServer(t, test.initRecs...) + envTest.ClearEnv() + envTest.Apply(test.envVars) + + provider, err := NewDNSProvider() + require.NoError(t, err) + + if test.present { + err = provider.Present(test.domain, test.token, test.keyauth) + if test.expPresentErr == "" { + assert.NoError(t, err) + } else { + assert.Equal(t, test.expPresentErr, err.Error()) + } + } + + if test.cleanup { + err = provider.CleanUp(test.domain, test.token, test.keyauth) + if test.expCleanupErr == "" { + assert.NoError(t, err) + } else { + assert.Equal(t, test.expCleanupErr, err.Error()) + } + } + }) + } +} diff --git a/providers/dns/liquidweb/liquidweb_test.go b/providers/dns/liquidweb/liquidweb_test.go index 674b5fa68b..db2cce2173 100644 --- a/providers/dns/liquidweb/liquidweb_test.go +++ b/providers/dns/liquidweb/liquidweb_test.go @@ -5,23 +5,64 @@ import ( "time" "github.com/go-acme/lego/v4/platform/tester" - "github.com/liquidweb/liquidweb-go/network" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -const envDomain = EnvPrefix + "DOMAIN" +const envDomain = envNamespace + "DOMAIN" + +var envTest = tester.NewEnvTest( + EnvURL, + EnvUsername, + EnvPassword, + EnvZone). + WithDomain(envDomain) func TestNewDNSProvider(t *testing.T) { - envTest := tester.NewEnvTest( - EnvPrefix+EnvURL, - EnvPrefix+EnvUsername, - EnvPrefix+EnvPassword, - EnvPrefix+EnvZone). - WithDomain(envDomain) - defer envTest.ClearEnv() + testCases := []struct { + desc string + envVars map[string]string + expected string + }{ + { + desc: "minimum-success", + envVars: map[string]string{ + EnvUsername: "blars", + EnvPassword: "tacoman", + }, + }, + { + desc: "set-everything", + envVars: map[string]string{ + EnvURL: "https://storm.com", + EnvUsername: "blars", + EnvPassword: "tacoman", + EnvZone: "blars.com", + }, + }, + { + desc: "missing credentials", + envVars: map[string]string{}, + expected: "liquidweb: some credentials information are missing: LIQUID_WEB_USERNAME,LIQUID_WEB_PASSWORD", + }, + { + desc: "missing username", + envVars: map[string]string{ + EnvPassword: "tacoman", + EnvZone: "blars.com", + }, + expected: "liquidweb: some credentials information are missing: LIQUID_WEB_USERNAME", + }, + { + desc: "missing password", + envVars: map[string]string{ + EnvUsername: "blars", + EnvZone: "blars.com", + }, + expected: "liquidweb: some credentials information are missing: LIQUID_WEB_PASSWORD", + }, + } - for _, test := range testNewDNSProviderTestdata() { + for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { defer envTest.RestoreEnv() envTest.ClearEnv() @@ -43,70 +84,66 @@ func TestNewDNSProvider(t *testing.T) { } } -func TestDNSProvider_Present(t *testing.T) { - envTest := tester.NewEnvTest( - EnvPrefix+EnvURL, - EnvPrefix+EnvUsername, - EnvPrefix+EnvPassword, - EnvPrefix+EnvZone). - WithDomain(envDomain) - - envTest.Apply(map[string]string{ - EnvPrefix + EnvUsername: "blars", - EnvPrefix + EnvPassword: "tacoman", - EnvPrefix + EnvURL: mockAPIServer(t), - EnvPrefix + EnvZone: "tacoman.com", // this needs to be removed from test? - }) - - defer envTest.ClearEnv() - - provider, err := NewDNSProvider() - require.NoError(t, err) - - err = provider.Present("tacoman.com", "", "") - require.NoError(t, err) -} - -func TestDNSProvider_CleanUp(t *testing.T) { - envTest := tester.NewEnvTest( - EnvPrefix+EnvURL, - EnvPrefix+EnvUsername, - EnvPrefix+EnvPassword, - EnvPrefix+EnvZone). - WithDomain(envDomain) - - envTest.Apply(map[string]string{ - EnvPrefix + EnvUsername: "blars", - EnvPrefix + EnvPassword: "tacoman", - EnvPrefix + EnvURL: mockAPIServer(t, network.DNSRecord{ - Name: "_acme-challenge.tacoman.com", - RData: "123d==", - Type: "TXT", - TTL: 300, - ID: 1234567, - ZoneID: 42, - }), - EnvPrefix + EnvZone: "tacoman.com", // this needs to be removed from test? - }) - - defer envTest.ClearEnv() +func TestNewDNSProviderConfig(t *testing.T) { + testCases := []struct { + desc string + username string + password string + zone string + expected string + }{ + { + desc: "success", + username: "acme", + password: "secret", + zone: "example.com", + }, + { + desc: "missing credentials", + username: "", + password: "", + zone: "", + expected: "liquidweb: could not create Liquid Web API client: provided username is empty", + }, + { + desc: "missing username", + username: "", + password: "secret", + zone: "example.com", + expected: "liquidweb: could not create Liquid Web API client: provided username is empty", + }, + { + desc: "missing password", + username: "acme", + password: "", + zone: "example.com", + expected: "liquidweb: could not create Liquid Web API client: provided password is empty", + }, + } - provider, err := NewDNSProvider() - require.NoError(t, err) + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + config := NewDefaultConfig() + config.Username = test.username + config.Password = test.password + config.Zone = test.zone - provider.recordIDs["123d=="] = 1234567 + p, err := NewDNSProviderConfig(config) - err = provider.CleanUp("tacoman.com.", "123d==", "") - require.NoError(t, err, "fail to remove TXT record") + if test.expected == "" { + 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 TestLivePresent(t *testing.T) { - envTest := tester.NewEnvTest( - EnvPrefix+EnvURL, - EnvPrefix+EnvUsername, - EnvPrefix+EnvPassword, - EnvPrefix+EnvZone). - WithDomain(envDomain) defer envTest.ClearEnv() if !envTest.IsLiveTest() { @@ -123,13 +160,6 @@ func TestLivePresent(t *testing.T) { } func TestLiveCleanUp(t *testing.T) { - envTest := tester.NewEnvTest( - EnvPrefix+EnvURL, - EnvPrefix+EnvUsername, - EnvPrefix+EnvPassword, - EnvPrefix+EnvZone). - WithDomain(envDomain) - defer envTest.ClearEnv() if !envTest.IsLiveTest() { @@ -146,41 +176,3 @@ func TestLiveCleanUp(t *testing.T) { err = provider.CleanUp(envTest.GetDomain(), "", "123d==") require.NoError(t, err) } - -func TestIntegration(t *testing.T) { - envTest := tester.NewEnvTest( - "LWAPI_USERNAME", - "LWAPI_PASSWORD", - "LWAPI_URL") - - for testName, td := range testIntegrationTestdata() { - t.Run(testName, func(t *testing.T) { - td := td - - td.envVars["LWAPI_URL"] = mockAPIServer(t, td.initRecs...) - envTest.ClearEnv() - envTest.Apply(td.envVars) - - provider, err := NewDNSProvider() - require.NoError(t, err) - - if td.present { - err = provider.Present(td.domain, td.token, td.keyauth) - if td.expPresentErr == "" { - assert.NoError(t, err) - } else { - assert.Equal(t, td.expPresentErr, err.Error()) - } - } - - if td.cleanup { - err = provider.CleanUp(td.domain, td.token, td.keyauth) - if td.expCleanupErr == "" { - assert.NoError(t, err) - } else { - assert.Equal(t, td.expCleanupErr, err.Error()) - } - } - }) - } -} diff --git a/providers/dns/liquidweb/liquidweb_testdata_test.go b/providers/dns/liquidweb/servermock_data_test.go similarity index 53% rename from providers/dns/liquidweb/liquidweb_testdata_test.go rename to providers/dns/liquidweb/servermock_data_test.go index 1a2a3425fe..99493b3301 100644 --- a/providers/dns/liquidweb/liquidweb_testdata_test.go +++ b/providers/dns/liquidweb/servermock_data_test.go @@ -132,136 +132,3 @@ func makeMockZones() (map[int]network.DNSZoneList, map[string]int) { } return mockZones, mockAPIServerZones } - -func testNewDNSProviderTestdata() []struct { - desc string - envVars map[string]string - expected string -} { - return []struct { - desc string - envVars map[string]string - expected string - }{ - { - desc: "minimum-success", - envVars: map[string]string{ - EnvPrefix + EnvUsername: "blars", - EnvPrefix + EnvPassword: "tacoman", - }, - }, - { - desc: "set-everything", - envVars: map[string]string{ - EnvPrefix + EnvURL: "https://storm.com", - EnvPrefix + EnvUsername: "blars", - EnvPrefix + EnvPassword: "tacoman", - EnvPrefix + EnvZone: "blars.com", - }, - }, - { - desc: "missing credentials", - envVars: map[string]string{}, - expected: "liquidweb: username and password are missing, set LWAPI_USERNAME and LWAPI_PASSWORD", - }, - { - desc: "missing username", - envVars: map[string]string{ - EnvPrefix + EnvPassword: "tacoman", - EnvPrefix + EnvZone: "blars.com", - }, - expected: "liquidweb: username is missing, set LWAPI_USERNAME", - }, - { - desc: "missing password", - envVars: map[string]string{ - EnvPrefix + EnvUsername: "blars", - EnvPrefix + EnvZone: "blars.com", - }, - expected: "liquidweb: password is missing, set LWAPI_PASSWORD", - }, - } -} - -func testIntegrationTestdata() map[string]struct { - envVars map[string]string - initRecs []network.DNSRecord - domain string - token string - keyauth string - present bool - cleanup bool - expPresentErr string - expCleanupErr string -} { - return map[string]struct { - envVars map[string]string - initRecs []network.DNSRecord - domain string - token string - keyauth string - present bool - cleanup bool - expPresentErr string - expCleanupErr string - }{ - "expected successful": { - envVars: map[string]string{ - "LWAPI_USERNAME": "blars", - "LWAPI_PASSWORD": "tacoman", - }, - domain: "tacoman.com", - token: "123", - keyauth: "456", - present: true, - cleanup: true, - }, - "other successful": { - envVars: map[string]string{ - "LWAPI_USERNAME": "blars", - "LWAPI_PASSWORD": "tacoman", - }, - domain: "banana.com", - token: "123", - keyauth: "456", - present: true, - cleanup: true, - }, - "zone not on account": { - envVars: map[string]string{ - "LWAPI_USERNAME": "blars", - "LWAPI_PASSWORD": "tacoman", - }, - domain: "huckleberry.com", - token: "123", - keyauth: "456", - present: true, - cleanup: false, - expPresentErr: "no valid zone in account for certificate _acme-challenge.huckleberry.com", - }, - "ssl for domain": { - envVars: map[string]string{ - "LWAPI_USERNAME": "blars", - "LWAPI_PASSWORD": "tacoman", - }, - domain: "sundae.cherry.com", - token: "5847953", - keyauth: "34872934", - present: true, - cleanup: true, - expPresentErr: "", - }, - "complicated domain": { - envVars: map[string]string{ - "LWAPI_USERNAME": "blars", - "LWAPI_PASSWORD": "tacoman", - }, - domain: "always.money.stand.banana.com", - token: "5847953", - keyauth: "theres always money in the banana stand", - present: true, - cleanup: true, - expPresentErr: "", - }, - } -} diff --git a/providers/dns/liquidweb/apiServer_test.go b/providers/dns/liquidweb/servermock_test.go similarity index 100% rename from providers/dns/liquidweb/apiServer_test.go rename to providers/dns/liquidweb/servermock_test.go