forked from TrueCloudLab/lego
8e9c5ac3e6
* Adding output of which envvars are missing in Cloudflare dns provider * go fmt, duh * Fixing & adding test(s) * Adding azure missing env vars checking * Fixing test * Doh, fixing up expected output
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package cloudflare
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
cflareLiveTest bool
|
|
cflareEmail string
|
|
cflareAPIKey string
|
|
cflareDomain string
|
|
)
|
|
|
|
func init() {
|
|
cflareEmail = os.Getenv("CLOUDFLARE_EMAIL")
|
|
cflareAPIKey = os.Getenv("CLOUDFLARE_API_KEY")
|
|
cflareDomain = os.Getenv("CLOUDFLARE_DOMAIN")
|
|
if len(cflareEmail) > 0 && len(cflareAPIKey) > 0 && len(cflareDomain) > 0 {
|
|
cflareLiveTest = true
|
|
}
|
|
}
|
|
|
|
func restoreCloudFlareEnv() {
|
|
os.Setenv("CLOUDFLARE_EMAIL", cflareEmail)
|
|
os.Setenv("CLOUDFLARE_API_KEY", cflareAPIKey)
|
|
}
|
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
|
os.Setenv("CLOUDFLARE_EMAIL", "")
|
|
os.Setenv("CLOUDFLARE_API_KEY", "")
|
|
_, err := NewDNSProviderCredentials("123", "123")
|
|
assert.NoError(t, err)
|
|
restoreCloudFlareEnv()
|
|
}
|
|
|
|
func TestNewDNSProviderValidEnv(t *testing.T) {
|
|
os.Setenv("CLOUDFLARE_EMAIL", "test@example.com")
|
|
os.Setenv("CLOUDFLARE_API_KEY", "123")
|
|
_, err := NewDNSProvider()
|
|
assert.NoError(t, err)
|
|
restoreCloudFlareEnv()
|
|
}
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
|
os.Setenv("CLOUDFLARE_EMAIL", "")
|
|
os.Setenv("CLOUDFLARE_API_KEY", "")
|
|
_, err := NewDNSProvider()
|
|
assert.EqualError(t, err, "CloudFlare credentials missing: CLOUDFLARE_EMAIL,CLOUDFLARE_API_KEY")
|
|
restoreCloudFlareEnv()
|
|
}
|
|
|
|
func TestNewDNSProviderMissingCredErrSingle(t *testing.T){
|
|
os.Setenv("CLOUDFLARE_EMAIL", "awesome@possum.com")
|
|
_, err:= NewDNSProvider()
|
|
assert.EqualError(t, err, "CloudFlare credentials missing: CLOUDFLARE_API_KEY")
|
|
restoreCloudFlareEnv()
|
|
}
|
|
|
|
func TestCloudFlarePresent(t *testing.T) {
|
|
if !cflareLiveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
provider, err := NewDNSProviderCredentials(cflareEmail, cflareAPIKey)
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.Present(cflareDomain, "", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestCloudFlareCleanUp(t *testing.T) {
|
|
if !cflareLiveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
time.Sleep(time.Second * 2)
|
|
|
|
provider, err := NewDNSProviderCredentials(cflareEmail, cflareAPIKey)
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.CleanUp(cflareDomain, "", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|