Skip to content

Commit

Permalink
regru: improve error handling (go-acme#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Nov 10, 2022
1 parent b6b8e57 commit 1b56aa0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 deletions challenge/dns01/nameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ var findXByFqdnTestCases = []struct {
desc: "NXDOMAIN",
fqdn: "test.lego.zz.",
zone: "lego.zz.",
nameservers: []string{"1.1.1.1:53"},
nameservers: []string{"8.8.8.8:53"},
expectedError: "could not find the start of authority for test.lego.zz.: NXDOMAIN",
},
{
desc: "several non existent nameservers",
fqdn: "mail.google.com.",
zone: "google.com.",
primaryNs: "ns1.google.com.",
nameservers: []string{":7053", ":8053", "1.1.1.1:53"},
nameservers: []string{":7053", ":8053", "8.8.8.8:53"},
},
{
desc: "only non existent nameservers",
desc: "only non-existent nameservers",
fqdn: "mail.google.com.",
zone: "google.com.",
nameservers: []string{":7053", ":8053", ":9053"},
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestFindZoneByFqdnCustom(t *testing.T) {
}
}

func TestFindPrimayNsByFqdnCustom(t *testing.T) {
func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
for _, test := range findXByFqdnTestCases {
t.Run(test.desc, func(t *testing.T) {
ClearFqdnCache()
Expand Down
13 changes: 12 additions & 1 deletion providers/dns/regru/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ func (c Client) do(request interface{}, fragments ...string) (*APIResponse, erro
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode/100 != 2 {
return nil, fmt.Errorf("API error, status code: %d", resp.StatusCode)
all, errB := io.ReadAll(resp.Body)
if errB != nil {
return nil, fmt.Errorf("API error, status code: %d", resp.StatusCode)
}

var apiResp APIResponse
errB = json.Unmarshal(all, &apiResp)
if errB != nil {
return nil, fmt.Errorf("API error, status code: %d, %s", resp.StatusCode, string(all))
}

return nil, fmt.Errorf("%w, status code: %d", apiResp, resp.StatusCode)
}

all, err := io.ReadAll(resp.Body)
Expand Down
6 changes: 6 additions & 0 deletions providers/dns/regru/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const (
)

func TestRemoveRecord(t *testing.T) {
// TODO(ldez): remove skip when the reg.ru API will be fixed.
t.Skip("there is a bug with the reg.ru API: INTERNAL_API_ERROR: Внутренняя ошибка, status code: 503")

client := NewClient(officialTestUser, officialTestPassword)

err := client.RemoveTxtRecord("test.ru", "_acme-challenge", "txttxttxt")
Expand Down Expand Up @@ -60,6 +63,9 @@ func TestRemoveRecord_errors(t *testing.T) {
}

func TestAddTXTRecord(t *testing.T) {
// TODO(ldez): remove skip when the reg.ru API will be fixed.
t.Skip("there is a bug with the reg.ru API: INTERNAL_API_ERROR: Внутренняя ошибка, status code: 503")

client := NewClient(officialTestUser, officialTestPassword)

err := client.AddTXTRecord("test.ru", "_acme-challenge", "txttxttxt")
Expand Down

0 comments on commit 1b56aa0

Please sign in to comment.