2019-03-11 15:54:35 +00:00
|
|
|
package lightsail // import "github.com/xenolf/lego/providers/dns/lightsail"
|
2018-02-18 15:27:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
|
|
"github.com/aws/aws-sdk-go/service/lightsail"
|
2018-06-11 15:32:50 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-02-18 15:27:58 +00:00
|
|
|
)
|
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
func TestLiveTTL(t *testing.T) {
|
2018-10-16 15:52:57 +00:00
|
|
|
if !envTest.IsLiveTest() {
|
|
|
|
t.Skip("skipping live test")
|
2018-02-18 15:27:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
envTest.RestoreEnv()
|
|
|
|
|
2018-02-18 15:27:58 +00:00
|
|
|
provider, err := NewDNSProvider()
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-18 15:27:58 +00:00
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
domain := envTest.GetDomain()
|
2018-09-24 19:07:20 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
err = provider.Present(domain, "foo", "bar")
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
// we need a separate Lightsail client here as the one in the DNS provider is
|
2018-02-18 15:27:58 +00:00
|
|
|
// unexported.
|
2018-10-12 17:29:18 +00:00
|
|
|
fqdn := "_acme-challenge." + domain
|
2018-07-01 00:24:20 +00:00
|
|
|
sess, err := session.NewSession()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
svc := lightsail.New(sess)
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer func() {
|
2018-10-12 17:29:18 +00:00
|
|
|
errC := provider.CleanUp(domain, "foo", "bar")
|
2018-09-24 19:07:20 +00:00
|
|
|
if errC != nil {
|
|
|
|
t.Log(errC)
|
|
|
|
}
|
|
|
|
}()
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-02-18 15:27:58 +00:00
|
|
|
params := &lightsail.GetDomainInput{
|
2018-10-12 17:29:18 +00:00
|
|
|
DomainName: aws.String(domain),
|
2018-02-18 15:27:58 +00:00
|
|
|
}
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-02-18 15:27:58 +00:00
|
|
|
resp, err := svc.GetDomain(params)
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-02-18 15:27:58 +00:00
|
|
|
entries := resp.Domain.DomainEntries
|
|
|
|
for _, entry := range entries {
|
2018-10-16 15:52:57 +00:00
|
|
|
if aws.StringValue(entry.Type) == "TXT" && aws.StringValue(entry.Name) == fqdn {
|
2018-02-18 15:27:58 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
t.Fatalf("Could not find a TXT record for _acme-challenge.%s", domain)
|
2018-02-18 15:27:58 +00:00
|
|
|
}
|