2019-03-11 18:56:48 +02:00
|
|
|
package lightsail
|
2018-02-18 17:27:58 +02:00
|
|
|
|
|
|
|
import (
|
2023-07-27 12:15:26 +02:00
|
|
|
"context"
|
2018-02-18 17:27:58 +02:00
|
|
|
"testing"
|
|
|
|
|
2023-07-27 12:15:26 +02: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/lightsail"
|
2024-12-05 20:49:13 +02:00
|
|
|
"github.com/go-acme/lego/v4/providers/dns/internal/ptr"
|
2018-06-11 17:32:50 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-02-18 17:27:58 +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")
|
2018-02-18 17:27:58 +02:00
|
|
|
}
|
|
|
|
|
2018-10-16 17:52:57 +02:00
|
|
|
envTest.RestoreEnv()
|
|
|
|
|
2018-02-18 17:27:58 +02:00
|
|
|
provider, err := NewDNSProvider()
|
2018-06-11 17:32:50 +02:00
|
|
|
require.NoError(t, err)
|
2018-02-18 17:27:58 +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)
|
|
|
|
|
2023-07-27 12:15:26 +02:00
|
|
|
// we need a separate Lightsail client here as the one in the DNS provider is unexported.
|
2018-10-12 19:29:18 +02:00
|
|
|
fqdn := "_acme-challenge." + domain
|
2023-07-27 12:15:26 +02:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
cfg, err := awsconfig.LoadDefaultConfig(ctx)
|
2018-07-01 02:24:20 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-07-27 12:15:26 +02:00
|
|
|
svc := lightsail.NewFromConfig(cfg)
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}()
|
2018-06-11 17:32:50 +02:00
|
|
|
|
2018-02-18 17:27:58 +02:00
|
|
|
params := &lightsail.GetDomainInput{
|
2018-10-12 19:29:18 +02:00
|
|
|
DomainName: aws.String(domain),
|
2018-02-18 17:27:58 +02:00
|
|
|
}
|
2018-06-11 17:32:50 +02:00
|
|
|
|
2023-07-27 12:15:26 +02:00
|
|
|
resp, err := svc.GetDomain(ctx, params)
|
2018-09-24 21:07:20 +02:00
|
|
|
require.NoError(t, err)
|
2018-06-11 17:32:50 +02:00
|
|
|
|
2018-02-18 17:27:58 +02:00
|
|
|
entries := resp.Domain.DomainEntries
|
|
|
|
for _, entry := range entries {
|
2024-12-05 20:49:13 +02:00
|
|
|
if ptr.Deref(entry.Type) == "TXT" && ptr.Deref(entry.Name) == fqdn {
|
2018-02-18 17:27:58 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 17:32:50 +02:00
|
|
|
|
2018-10-12 19:29:18 +02:00
|
|
|
t.Fatalf("Could not find a TXT record for _acme-challenge.%s", domain)
|
2018-02-18 17:27:58 +02:00
|
|
|
}
|