forked from TrueCloudLab/lego
regru: improve error handling (#1750)
This commit is contained in:
parent
b6b8e57b13
commit
1b56aa0d2f
3 changed files with 22 additions and 5 deletions
|
@ -108,7 +108,7 @@ 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",
|
||||
},
|
||||
{
|
||||
|
@ -116,10 +116,10 @@ var findXByFqdnTestCases = []struct {
|
|||
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"},
|
||||
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue