2016-06-15 00:03:31 +00:00
|
|
|
package route53
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
|
|
"github.com/aws/aws-sdk-go/service/route53"
|
2018-06-11 15:32:50 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-09-08 11:49:24 +00:00
|
|
|
"github.com/xenolf/lego/platform/config/env"
|
2016-06-15 00:03:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRoute53TTL(t *testing.T) {
|
2018-09-08 11:49:24 +00:00
|
|
|
config, err := env.Get("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_REGION", "R53_DOMAIN")
|
2016-06-15 00:03:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Skip(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
provider, err := NewDNSProvider()
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
2016-06-15 00:03:31 +00:00
|
|
|
|
2018-09-24 19:07:20 +00:00
|
|
|
r53Domain := config["R53_DOMAIN"]
|
|
|
|
|
|
|
|
err = provider.Present(r53Domain, "foo", "bar")
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
2018-05-30 17:53:04 +00:00
|
|
|
|
2018-09-24 19:07:20 +00:00
|
|
|
// we need a separate R53 client here as the one in the DNS provider is unexported.
|
|
|
|
fqdn := "_acme-challenge." + r53Domain + "."
|
2018-10-09 17:03:07 +00:00
|
|
|
sess, err := session.NewSession()
|
|
|
|
require.NoError(t, err)
|
|
|
|
svc := route53.New(sess)
|
2018-09-24 19:07:20 +00:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
errC := provider.CleanUp(r53Domain, "foo", "bar")
|
|
|
|
if errC != nil {
|
|
|
|
t.Log(errC)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-07-17 19:50:53 +00:00
|
|
|
zoneID, err := provider.getHostedZoneID(fqdn)
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2018-05-30 17:53:04 +00:00
|
|
|
|
2016-06-15 00:03:31 +00:00
|
|
|
params := &route53.ListResourceRecordSetsInput{
|
|
|
|
HostedZoneId: aws.String(zoneID),
|
|
|
|
}
|
|
|
|
resp, err := svc.ListResourceRecordSets(params)
|
2018-09-24 19:07:20 +00:00
|
|
|
require.NoError(t, err)
|
2016-06-15 00:03:31 +00:00
|
|
|
|
|
|
|
for _, v := range resp.ResourceRecordSets {
|
2018-05-30 17:53:04 +00:00
|
|
|
if aws.StringValue(v.Name) == fqdn && aws.StringValue(v.Type) == "TXT" && aws.Int64Value(v.TTL) == 10 {
|
2016-06-15 00:03:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 17:53:04 +00:00
|
|
|
|
2018-09-24 19:07:20 +00:00
|
|
|
t.Fatalf("Could not find a TXT record for _acme-challenge.%s with a TTL of 10", r53Domain)
|
2016-06-15 00:03:31 +00:00
|
|
|
}
|