From bcfce0809a5ca2c76b878886656a2531558facc5 Mon Sep 17 00:00:00 2001 From: Simone Carletti Date: Tue, 26 Jan 2016 12:25:51 +0100 Subject: [PATCH] DNSimpleProvider: Check valid credentials --- acme/dns_challenge_dnsimple.go | 12 +++++++++++- acme/dns_challenge_dnsimple_test.go | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/acme/dns_challenge_dnsimple.go b/acme/dns_challenge_dnsimple.go index 4cd862a8..754cce63 100644 --- a/acme/dns_challenge_dnsimple.go +++ b/acme/dns_challenge_dnsimple.go @@ -1,6 +1,8 @@ package acme import ( + "fmt" + "github.com/weppos/go-dnsimple/dnsimple" ) @@ -12,7 +14,15 @@ type DNSProviderDNSimple struct { // NewDNSProviderDNSimple returns a DNSProviderDNSimple instance with a configured dnsimple client. // Authentication is either done using the passed credentials. func NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleApiKey string) (*DNSProviderDNSimple, error) { - return nil, nil + if dnsimpleEmail == "" || dnsimpleApiKey == "" { + return nil, fmt.Errorf("DNSimple credentials missing") + } + + c := &DNSProviderDNSimple{ + client: dnsimple.NewClient(dnsimpleApiKey, dnsimpleEmail), + } + + return c, nil } // Present creates a TXT record to fulfil the dns-01 challenge. diff --git a/acme/dns_challenge_dnsimple_test.go b/acme/dns_challenge_dnsimple_test.go index 9e7e4d9b..6fa1b76f 100644 --- a/acme/dns_challenge_dnsimple_test.go +++ b/acme/dns_challenge_dnsimple_test.go @@ -6,8 +6,12 @@ import ( "github.com/stretchr/testify/assert" ) - func TestNewDNSProviderDNSimpleValid(t *testing.T) { _, err := NewDNSProviderDNSimple("example@example.com", "123") assert.NoError(t, err) } + +func TestNewDNSProviderDNSimpleMissingCredErr(t *testing.T) { + _, err := NewDNSProviderDNSimple("", "") + assert.EqualError(t, err, "DNSimple credentials missing") +}