2019-03-11 16:56:48 +00:00
|
|
|
package route53
|
2016-06-15 00:03:31 +00:00
|
|
|
|
|
|
|
import (
|
2023-07-27 10:15:26 +00:00
|
|
|
"context"
|
2016-06-15 00:03:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-07-27 10:15:26 +00:00
|
|
|
"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"
|
2018-06-11 15:32:50 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-06-15 00:03:31 +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")
|
2016-06-15 00:03:31 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 15:52:57 +00:00
|
|
|
envTest.RestoreEnv()
|
|
|
|
|
2016-06-15 00:03:31 +00:00
|
|
|
provider, err := NewDNSProvider()
|
2018-06-11 15:32:50 +00:00
|
|
|
require.NoError(t, err)
|
2016-06-15 00:03:31 +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-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.
|
2018-10-12 17:29:18 +00:00
|
|
|
fqdn := "_acme-challenge." + domain + "."
|
2023-07-27 10:15:26 +00:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
cfg, err := awsconfig.LoadDefaultConfig(ctx)
|
2018-10-09 17:03:07 +00:00
|
|
|
require.NoError(t, err)
|
2023-07-27 10:15:26 +00:00
|
|
|
|
|
|
|
svc := route53.NewFromConfig(cfg)
|
2018-09-24 19:07:20 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-07-27 10:15:26 +00:00
|
|
|
zoneID, err := provider.getHostedZoneID(context.Background(), 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),
|
|
|
|
}
|
2023-07-27 10:15:26 +00:00
|
|
|
resp, err := svc.ListResourceRecordSets(ctx, 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 {
|
2023-07-27 10:15:26 +00:00
|
|
|
if deref(v.Name) == fqdn && v.Type == "TXT" && deref(v.TTL) == 10 {
|
2016-06-15 00:03:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 17:53:04 +00:00
|
|
|
|
2018-10-12 17:29:18 +00:00
|
|
|
t.Fatalf("Could not find a TXT record for _acme-challenge.%s with a TTL of 10", domain)
|
2016-06-15 00:03:31 +00:00
|
|
|
}
|