lego/providers/dns/route53/route53_integration_test.go

62 lines
1.3 KiB
Go
Raw Normal View History

2019-03-11 16:56:48 +00:00
package route53
import (
"context"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
awsconfig "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/route53"
"github.com/stretchr/testify/require"
)
func TestLiveTTL(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
domain := envTest.GetDomain()
err = provider.Present(domain, "foo", "bar")
require.NoError(t, err)
2018-05-30 17:53:04 +00:00
// we need a separate R53 client here as the one in the DNS provider is unexported.
fqdn := "_acme-challenge." + domain + "."
ctx := context.Background()
cfg, err := awsconfig.LoadDefaultConfig(ctx)
2018-10-09 17:03:07 +00:00
require.NoError(t, err)
svc := route53.NewFromConfig(cfg)
defer func() {
errC := provider.CleanUp(domain, "foo", "bar")
if errC != nil {
t.Log(errC)
}
}()
zoneID, err := provider.getHostedZoneID(context.Background(), fqdn)
require.NoError(t, err)
2018-05-30 17:53:04 +00:00
params := &route53.ListResourceRecordSetsInput{
HostedZoneId: aws.String(zoneID),
}
resp, err := svc.ListResourceRecordSets(ctx, params)
require.NoError(t, err)
for _, v := range resp.ResourceRecordSets {
if deref(v.Name) == fqdn && v.Type == "TXT" && deref(v.TTL) == 10 {
return
}
}
2018-05-30 17:53:04 +00:00
t.Fatalf("Could not find a TXT record for _acme-challenge.%s with a TTL of 10", domain)
}