2018-02-18 15:27:58 +00:00
|
|
|
package lightsail
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"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
|
|
|
)
|
|
|
|
|
|
|
|
func TestLightsailTTL(t *testing.T) {
|
|
|
|
m, err := testGetAndPreCheck()
|
|
|
|
if err != nil {
|
|
|
|
t.Skip(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
provider, err := NewDNSProvider()
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-18 15:27:58 +00:00
|
|
|
|
2018-09-24 19:07:20 +00:00
|
|
|
lightsailDomain := m["lightsailDomain"]
|
|
|
|
|
|
|
|
err = provider.Present(lightsailDomain, "foo", "bar")
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-02-18 15:27:58 +00:00
|
|
|
// we need a separate Lightshail client here as the one in the DNS provider is
|
|
|
|
// unexported.
|
2018-09-24 19:07:20 +00:00
|
|
|
fqdn := "_acme-challenge." + lightsailDomain
|
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() {
|
|
|
|
errC := provider.CleanUp(lightsailDomain, "foo", "bar")
|
|
|
|
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-09-24 19:07:20 +00:00
|
|
|
DomainName: aws.String(lightsailDomain),
|
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 {
|
|
|
|
if *entry.Type == "TXT" && *entry.Name == fqdn {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-09-24 19:07:20 +00:00
|
|
|
t.Fatalf("Could not find a TXT record for _acme-challenge.%s", lightsailDomain)
|
2018-02-18 15:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testGetAndPreCheck() (map[string]string, error) {
|
|
|
|
m := map[string]string{
|
|
|
|
"lightsailKey": os.Getenv("AWS_ACCESS_KEY_ID"),
|
|
|
|
"lightsailSecret": os.Getenv("AWS_SECRET_ACCESS_KEY"),
|
|
|
|
"lightsailDomain": os.Getenv("DNS_ZONE"),
|
|
|
|
}
|
|
|
|
for _, v := range m {
|
|
|
|
if v == "" {
|
|
|
|
return nil, fmt.Errorf("AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and R53_DOMAIN are needed to run this test")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m, nil
|
|
|
|
}
|