1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-25 11:02:56 +02:00

bunny: support delegated sub-domains (#2123)

This commit is contained in:
Jess Thrysoee 2024-02-29 22:08:03 +01:00 committed by GitHub
parent 9d0cd24533
commit a7ca3d7f1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 102 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/platform/config/env"
"github.com/miekg/dns"
"github.com/nrdcg/bunny-go"
)
@ -191,30 +190,11 @@ func getZone(fqdn string) (string, error) {
return "", err
}
zone, _, err := splitDomain(dns01.UnFqdn(authZone))
if err != nil {
return "", err
}
zone := dns01.UnFqdn(authZone)
return zone, nil
}
func splitDomain(full string) (string, string, error) {
split := dns.Split(full)
if len(split) < 2 {
return "", "", fmt.Errorf("unsupported domain: %s", full)
}
if len(split) == 2 {
return full, "", nil
}
domain := full[split[len(split)-2]:]
subDomain := full[:split[len(split)-2]-1]
return domain, subDomain, nil
}
func pointer[T string | int | int32 | int64](v T) *T { return &v }
func deref[T string | int | int32 | int64](v *T) T {

View File

@ -4,7 +4,6 @@ import (
"testing"
"github.com/go-acme/lego/v4/platform/tester"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -124,83 +123,3 @@ func TestLiveCleanUp(t *testing.T) {
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
}
func Test_splitDomain(t *testing.T) {
type expected struct {
root string
sub string
requireErr require.ErrorAssertionFunc
}
testCases := []struct {
desc string
domain string
expected expected
}{
{
desc: "empty",
domain: "",
expected: expected{
requireErr: require.Error,
},
},
{
desc: "2 levels",
domain: "example.com",
expected: expected{
root: "example.com",
sub: "",
requireErr: require.NoError,
},
},
{
desc: "3 levels",
domain: "_acme-challenge.example.com",
expected: expected{
root: "example.com",
sub: "_acme-challenge",
requireErr: require.NoError,
},
},
{
desc: "4 levels",
domain: "_acme-challenge.sub.example.com",
expected: expected{
root: "example.com",
sub: "_acme-challenge.sub",
requireErr: require.NoError,
},
},
{
desc: "5 levels",
domain: "_acme-challenge.my.sub.example.com",
expected: expected{
root: "example.com",
sub: "_acme-challenge.my.sub",
requireErr: require.NoError,
},
},
{
desc: "6 levels",
domain: "_acme-challenge.my.sub.sub.example.com",
expected: expected{
root: "example.com",
sub: "_acme-challenge.my.sub.sub",
requireErr: require.NoError,
},
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
root, sub, err := splitDomain(test.domain)
test.expected.requireErr(t, err)
assert.Equal(t, test.expected.root, root)
assert.Equal(t, test.expected.sub, sub)
})
}
}