2019-03-11 18:56:48 +02:00
|
|
|
package route53
|
2016-06-15 02:03:31 +02: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/route53"
|
2018-06-11 17:32:50 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-06-15 02:03:31 +02:00
|
|
|
)
|
|
|
|
|
2018-10-12 19:29:18 +02:00
|
|
|
func TestLiveTTL(t *testing.T) {
|
2018-10-16 17:52:57 +02:00
|
|
|
if !envTest.IsLiveTest() {
|
|
|
|
t.Skip("skipping live test")
|
2016-06-15 02:03:31 +02:00
|
|
|
}
|
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
envTest.RestoreEnv()
|
|
|
|
|
2016-06-15 02:03:31 +02:00
|
|
|
provider, err := NewDNSProvider()
|
2018-06-11 17:32:50 +02:00
|
|
|
require.NoError(t, err)
|
2016-06-15 02:03:31 +02:00
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
domain := envTest.GetDomain()
|
2018-09-24 21:07:20 +02:00
|
|
|
|
2018-10-12 19:29:18 +02:00
|
|
|
err = provider.Present(domain, "foo", "bar")
|
2018-06-11 17:32:50 +02:00
|
|
|
require.NoError(t, err)
|
2018-05-30 19:53:04 +02:00
|
|
|
|
2018-09-24 21:07:20 +02:00
|
|
|
// we need a separate R53 client here as the one in the DNS provider is unexported.
|
2018-10-12 19:29:18 +02:00
|
|
|
fqdn := "_acme-challenge." + domain + "."
|
2018-10-09 19:03:07 +02:00
|
|
|
sess, err := session.NewSession()
|
|
|
|
require.NoError(t, err)
|
|
|
|
svc := route53.New(sess)
|
2018-09-24 21:07:20 +02:00
|
|
|
|
|
|
|
defer func() {
|
2018-10-12 19:29:18 +02:00
|
|
|
errC := provider.CleanUp(domain, "foo", "bar")
|
2018-09-24 21:07:20 +02:00
|
|
|
if errC != nil {
|
|
|
|
t.Log(errC)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-07-17 21:50:53 +02:00
|
|
|
zoneID, err := provider.getHostedZoneID(fqdn)
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2018-05-30 19:53:04 +02:00
|
|
|
|
2016-06-15 02:03:31 +02:00
|
|
|
params := &route53.ListResourceRecordSetsInput{
|
|
|
|
HostedZoneId: aws.String(zoneID),
|
|
|
|
}
|
|
|
|
resp, err := svc.ListResourceRecordSets(params)
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2016-06-15 02:03:31 +02:00
|
|
|
|
|
|
|
for _, v := range resp.ResourceRecordSets {
|
2018-05-30 19:53:04 +02:00
|
|
|
if aws.StringValue(v.Name) == fqdn && aws.StringValue(v.Type) == "TXT" && aws.Int64Value(v.TTL) == 10 {
|
2016-06-15 02:03:31 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 19:53:04 +02:00
|
|
|
|
2018-10-12 19:29:18 +02:00
|
|
|
t.Fatalf("Could not find a TXT record for _acme-challenge.%s with a TTL of 10", domain)
|
2016-06-15 02:03:31 +02:00
|
|
|
}
|