From 2de6e0b0c89fd6a383e78185c7253bf27d276ebc Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 3 Nov 2021 20:39:12 +0100 Subject: [PATCH] chore: update linter (#1524) --- .github/workflows/main.yml | 2 +- .golangci.toml | 8 ++++++++ acme/api/certificate_test.go | 3 +++ acme/api/order_test.go | 1 + certificate/certificates_test.go | 7 +++++++ challenge/dns01/dns_challenge_manual.go | 2 +- challenge/dns01/dns_challenge_manual_test.go | 2 +- internal/dnsdocs/generator.go | 2 +- providers/dns/azure/azure_test.go | 1 + providers/dns/constellix/constellix.go | 8 ++++---- providers/dns/desec/desec.go | 4 ++-- providers/dns/digitalocean/digitalocean_test.go | 2 ++ providers/dns/dnspod/dnspod.go | 2 +- providers/dns/domeneshop/internal/client_test.go | 5 +++++ providers/dns/dreamhost/dreamhost_test.go | 3 +++ providers/dns/easydns/easydns_test.go | 4 ++++ providers/dns/gcore/internal/client_test.go | 1 + providers/dns/hostingde/hostingde.go | 2 +- providers/dns/httpreq/httpreq_test.go | 4 ++-- providers/dns/infomaniak/internal/client_test.go | 3 +++ providers/dns/joker/internal/svc/client_test.go | 2 ++ providers/dns/linode/linode_test.go | 1 + providers/dns/liquidweb/liquidweb_test.go | 1 + providers/dns/luadns/internal/client_test.go | 3 +++ providers/dns/netcup/internal/client_test.go | 16 ++++++++++++++++ providers/dns/nicmanager/internal/client.go | 7 +++---- providers/dns/nifcloud/internal/client.go | 2 +- providers/dns/otc/otc.go | 2 +- providers/dns/scaleway/scaleway.go | 4 ++-- providers/dns/yandex/internal/client_test.go | 10 ++++++++++ providers/dns/zoneee/zoneee_test.go | 8 +++++--- 31 files changed, 97 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8d2d417e..bc15c65a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest env: GO_VERSION: 1.17 - GOLANGCI_LINT_VERSION: v1.42.0 + GOLANGCI_LINT_VERSION: v1.43.0 HUGO_VERSION: 0.54.0 SEIHON_VERSION: v0.8.3 CGO_ENABLED: 0 diff --git a/.golangci.toml b/.golangci.toml index 2d984281..ab2a4edc 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -41,6 +41,9 @@ "octalLiteral", "ptrToRefParam", "appendAssign", + "ruleguard", + "httpNoBody", + "exposedSyncMutex", ] [linters] @@ -70,6 +73,11 @@ "makezero", # not relevant "ifshort", # not relevant "forbidigo", # not relevant + "varnamelen", # not relevant + "nilnil", # not relevant + "ireturn", # not relevant + "contextcheck", # too many false-positive + "tenv", # we already have a test "framework" to handle env vars "noctx", "forcetypeassert", "tagliatelle", diff --git a/acme/api/certificate_test.go b/acme/api/certificate_test.go index 0d8911b8..9776cccc 100644 --- a/acme/api/certificate_test.go +++ b/acme/api/certificate_test.go @@ -81,6 +81,7 @@ func TestCertificateService_Get_issuerRelUp(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -89,6 +90,7 @@ func TestCertificateService_Get_issuerRelUp(t *testing.T) { _, err := w.Write(p.Bytes) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -111,6 +113,7 @@ func TestCertificateService_Get_embeddedIssuer(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/acme/api/order_test.go b/acme/api/order_test.go index 9f93b047..06e59589 100644 --- a/acme/api/order_test.go +++ b/acme/api/order_test.go @@ -31,6 +31,7 @@ func TestOrderService_New(t *testing.T) { body, err := readSignedBody(r, privateKey) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + return } order := acme.Order{} diff --git a/certificate/certificates_test.go b/certificate/certificates_test.go index 73d7b430..2ffa311d 100644 --- a/certificate/certificates_test.go +++ b/certificate/certificates_test.go @@ -160,6 +160,7 @@ func Test_checkResponse(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -201,6 +202,7 @@ func Test_checkResponse_issuerRelUp(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -209,6 +211,7 @@ func Test_checkResponse_issuerRelUp(t *testing.T) { _, err := w.Write(p.Bytes) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -249,6 +252,7 @@ func Test_checkResponse_embeddedIssuer(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -291,6 +295,7 @@ func Test_checkResponse_alternate(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -298,6 +303,7 @@ func Test_checkResponse_alternate(t *testing.T) { _, err := w.Write([]byte(certResponseMock2)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -341,6 +347,7 @@ func Test_Get(t *testing.T) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/challenge/dns01/dns_challenge_manual.go b/challenge/dns01/dns_challenge_manual.go index b2f5d41f..ced3ab58 100644 --- a/challenge/dns01/dns_challenge_manual.go +++ b/challenge/dns01/dns_challenge_manual.go @@ -8,7 +8,7 @@ import ( ) const ( - dnsTemplate = `%s %d IN TXT "%s"` + dnsTemplate = `%s %d IN TXT %q` ) // DNSProviderManual is an implementation of the ChallengeProvider interface. diff --git a/challenge/dns01/dns_challenge_manual_test.go b/challenge/dns01/dns_challenge_manual_test.go index 8802c35a..1360aec2 100644 --- a/challenge/dns01/dns_challenge_manual_test.go +++ b/challenge/dns01/dns_challenge_manual_test.go @@ -36,7 +36,7 @@ func TestDNSProviderManual(t *testing.T) { assert.NoError(t, err) defer func() { _ = os.Remove(file.Name()) }() - _, err = io.WriteString(file, test.input) + _, err = file.WriteString(test.input) assert.NoError(t, err) _, err = file.Seek(0, io.SeekStart) diff --git a/internal/dnsdocs/generator.go b/internal/dnsdocs/generator.go index a7aa2728..812b87ee 100644 --- a/internal/dnsdocs/generator.go +++ b/internal/dnsdocs/generator.go @@ -125,7 +125,7 @@ func generateDocumentation(m Model) error { } func generateCLIHelp(models *Providers) error { - filename := filepath.Join(cliOutput) + filename := filepath.Clean(cliOutput) file, err := os.Create(filename) if err != nil { diff --git a/providers/dns/azure/azure_test.go b/providers/dns/azure/azure_test.go index 5fcbd94b..2fa04d99 100644 --- a/providers/dns/azure/azure_test.go +++ b/providers/dns/azure/azure_test.go @@ -118,6 +118,7 @@ func TestNewDNSProviderConfig(t *testing.T) { _, err := w.Write([]byte("foo")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, }, diff --git a/providers/dns/constellix/constellix.go b/providers/dns/constellix/constellix.go index 51fd8e65..8e972ba9 100644 --- a/providers/dns/constellix/constellix.go +++ b/providers/dns/constellix/constellix.go @@ -193,7 +193,7 @@ func (d *DNSProvider) createRecord(dom internal.Domain, fqdn, recordName, value Name: recordName, TTL: d.config.TTL, RoundRobin: []internal.RecordValue{ - {Value: fmt.Sprintf(`"%s"`, value)}, + {Value: fmt.Sprintf(`%q`, value)}, }, } @@ -218,7 +218,7 @@ func (d *DNSProvider) appendRecordValue(dom internal.Domain, recordID int64, val request := internal.RecordRequest{ Name: record.Name, TTL: record.TTL, - RoundRobin: append(record.RoundRobin, internal.RecordValue{Value: fmt.Sprintf(`"%s"`, value)}), + RoundRobin: append(record.RoundRobin, internal.RecordValue{Value: fmt.Sprintf(`%q`, value)}), } _, err = d.client.TxtRecords.Update(dom.ID, record.ID, request) @@ -236,7 +236,7 @@ func (d *DNSProvider) removeRecordValue(dom internal.Domain, record *internal.Re } for _, val := range record.Value { - if val.Value != fmt.Sprintf(`"%s"`, value) { + if val.Value != fmt.Sprintf(`%q`, value) { request.RoundRobin = append(request.RoundRobin, val) } } @@ -255,7 +255,7 @@ func containsValue(record *internal.Record, value string) bool { } for _, val := range record.Value { - if val.Value == fmt.Sprintf(`"%s"`, value) { + if val.Value == fmt.Sprintf(`%q`, value) { return true } } diff --git a/providers/dns/desec/desec.go b/providers/dns/desec/desec.go index 38a257d4..2d133ea0 100644 --- a/providers/dns/desec/desec.go +++ b/providers/dns/desec/desec.go @@ -102,7 +102,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Present(domain, token, keyAuth string) error { ctx := context.Background() fqdn, value := dns01.GetRecord(domain, keyAuth) - quotedValue := fmt.Sprintf(`"%s"`, value) + quotedValue := fmt.Sprintf(`%q`, value) authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { @@ -167,7 +167,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { records := make([]string, 0) for _, record := range rrSet.Records { - if record != fmt.Sprintf(`"%s"`, value) { + if record != fmt.Sprintf(`%q`, value) { records = append(records, record) } } diff --git a/providers/dns/digitalocean/digitalocean_test.go b/providers/dns/digitalocean/digitalocean_test.go index b46998f2..7cdc9638 100644 --- a/providers/dns/digitalocean/digitalocean_test.go +++ b/providers/dns/digitalocean/digitalocean_test.go @@ -121,6 +121,7 @@ func TestDNSProvider_Present(t *testing.T) { reqBody, err := io.ReadAll(r.Body) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } expectedReqBody := `{"type":"TXT","name":"_acme-challenge.example.com.","data":"w6uP8Tcg6K2QR905Rms8iXTlksL6OD1KOWBxTK7wxPI","ttl":30}` @@ -140,6 +141,7 @@ func TestDNSProvider_Present(t *testing.T) { }`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/dnspod/dnspod.go b/providers/dns/dnspod/dnspod.go index fa6b5f7e..4c7ec7d5 100644 --- a/providers/dns/dnspod/dnspod.go +++ b/providers/dns/dnspod/dnspod.go @@ -153,7 +153,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, string, error) { return "", "", fmt.Errorf("zone %s not found in dnspod for domain %s", authZone, domain) } - return fmt.Sprintf("%v", hostedZone.ID), hostedZone.Name, nil + return hostedZone.ID.String(), hostedZone.Name, nil } func (d *DNSProvider) newTxtRecord(zone, fqdn, value string, ttl int) *dnspod.Record { diff --git a/providers/dns/domeneshop/internal/client_test.go b/providers/dns/domeneshop/internal/client_test.go index 3d709b57..569ca403 100644 --- a/providers/dns/domeneshop/internal/client_test.go +++ b/providers/dns/domeneshop/internal/client_test.go @@ -36,6 +36,7 @@ func TestClient_CreateTXTRecord(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic dG9rZW46c2VjcmV0" { http.Error(rw, "invalid method: "+req.Method, http.StatusUnauthorized) + return } _, _ = rw.Write([]byte(`{"id": 1}`)) @@ -57,6 +58,7 @@ func TestClient_DeleteTXTRecord(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic dG9rZW46c2VjcmV0" { http.Error(rw, "invalid method: "+req.Method, http.StatusUnauthorized) + return } _, _ = rw.Write([]byte(`[ @@ -79,6 +81,7 @@ func TestClient_DeleteTXTRecord(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic dG9rZW46c2VjcmV0" { http.Error(rw, "invalid method: "+req.Method, http.StatusUnauthorized) + return } }) @@ -98,6 +101,7 @@ func TestClient_getDNSRecordByHostData(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic dG9rZW46c2VjcmV0" { http.Error(rw, "invalid method: "+req.Method, http.StatusUnauthorized) + return } _, _ = rw.Write([]byte(`[ @@ -137,6 +141,7 @@ func TestClient_GetDomainByName(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic dG9rZW46c2VjcmV0" { http.Error(rw, "invalid method: "+req.Method, http.StatusUnauthorized) + return } _, _ = rw.Write([]byte(`[ diff --git a/providers/dns/dreamhost/dreamhost_test.go b/providers/dns/dreamhost/dreamhost_test.go index 6d58a35e..796d4fe5 100644 --- a/providers/dns/dreamhost/dreamhost_test.go +++ b/providers/dns/dreamhost/dreamhost_test.go @@ -131,6 +131,7 @@ func TestDNSProvider_Present(t *testing.T) { _, err := fmt.Fprintf(w, `{"data":"record_added","result":"success"}`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -147,6 +148,7 @@ func TestDNSProvider_PresentFailed(t *testing.T) { _, err := fmt.Fprintf(w, `{"data":"record_already_exists_remove_first","result":"error"}`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -171,6 +173,7 @@ func TestDNSProvider_Cleanup(t *testing.T) { _, err := fmt.Fprintf(w, `{"data":"record_removed","result":"success"}`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/easydns/easydns_test.go b/providers/dns/easydns/easydns_test.go index 60a94461..f67c7406 100644 --- a/providers/dns/easydns/easydns_test.go +++ b/providers/dns/easydns/easydns_test.go @@ -154,6 +154,7 @@ func TestDNSProvider_Present(t *testing.T) { reqBody, err := io.ReadAll(r.Body) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } expectedReqBody := `{"domain":"example.com","host":"_acme-challenge","ttl":"120","prio":"0","type":"TXT","rdata":"pW9ZKG0xz_PCriK-nCMOjADy9eJcgGWIzkkj2fN4uZM"} @@ -178,6 +179,7 @@ func TestDNSProvider_Present(t *testing.T) { }`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -212,6 +214,7 @@ func TestDNSProvider_Cleanup_WhenRecordIdSet_DeletesTxtRecord(t *testing.T) { }`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) @@ -238,6 +241,7 @@ func TestDNSProvider_Cleanup_WhenHttpError_ReturnsError(t *testing.T) { _, err := fmt.Fprint(w, errorMessage) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/gcore/internal/client_test.go b/providers/dns/gcore/internal/client_test.go index 24a253c9..86872260 100644 --- a/providers/dns/gcore/internal/client_test.go +++ b/providers/dns/gcore/internal/client_test.go @@ -251,6 +251,7 @@ func handleAddRRSet(expected []Records) http.HandlerFunc { if !reflect.DeepEqual(body.Records, expected) { http.Error(rw, "wrong resource records", http.StatusInternalServerError) + return } } } diff --git a/providers/dns/hostingde/hostingde.go b/providers/dns/hostingde/hostingde.go index f4f03beb..685b5d87 100644 --- a/providers/dns/hostingde/hostingde.go +++ b/providers/dns/hostingde/hostingde.go @@ -134,7 +134,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { } for _, record := range resp.Response.Records { - if record.Name == dns01.UnFqdn(fqdn) && record.Content == fmt.Sprintf(`"%s"`, value) { + if record.Name == dns01.UnFqdn(fqdn) && record.Content == fmt.Sprintf(`%q`, value) { d.recordIDsMu.Lock() d.recordIDs[fqdn] = record.ID d.recordIDsMu.Unlock() diff --git a/providers/dns/httpreq/httpreq_test.go b/providers/dns/httpreq/httpreq_test.go index c3f4b2a0..99c56371 100644 --- a/providers/dns/httpreq/httpreq_test.go +++ b/providers/dns/httpreq/httpreq_test.go @@ -141,7 +141,7 @@ func TestNewDNSProvider_Present(t *testing.T) { handler: func(rw http.ResponseWriter, req *http.Request) { username, password, ok := req.BasicAuth() if username != "bar" || password != "foo" || !ok { - rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm="%s"`, "Please enter your username and password.")) + rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm=%q`, "Please enter your username and password.")) http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } @@ -219,7 +219,7 @@ func TestNewDNSProvider_Cleanup(t *testing.T) { handler: func(rw http.ResponseWriter, req *http.Request) { username, password, ok := req.BasicAuth() if username != "bar" || password != "foo" || !ok { - rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm="%s"`, "Please enter your username and password.")) + rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm=%q`, "Please enter your username and password.")) http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } diff --git a/providers/dns/infomaniak/internal/client_test.go b/providers/dns/infomaniak/internal/client_test.go index 87ae3858..a6034025 100644 --- a/providers/dns/infomaniak/internal/client_test.go +++ b/providers/dns/infomaniak/internal/client_test.go @@ -52,6 +52,7 @@ func TestClient_CreateDNSRecord(t *testing.T) { _, err = rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) @@ -119,6 +120,7 @@ func TestClient_GetDomainByName(t *testing.T) { _, err := rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) @@ -146,6 +148,7 @@ func TestClient_DeleteDNSRecord(t *testing.T) { _, err := rw.Write([]byte((`{"result":"success"}`))) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/joker/internal/svc/client_test.go b/providers/dns/joker/internal/svc/client_test.go index 4ee037e5..b75139a2 100644 --- a/providers/dns/joker/internal/svc/client_test.go +++ b/providers/dns/joker/internal/svc/client_test.go @@ -31,6 +31,7 @@ func TestClient_Send(t *testing.T) { _, err := rw.Write([]byte("OK: 1 inserted, 0 deleted")) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) @@ -66,6 +67,7 @@ func TestClient_Send_empty(t *testing.T) { _, err := rw.Write([]byte("OK: 1 inserted, 0 deleted")) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/linode/linode_test.go b/providers/dns/linode/linode_test.go index 0d003890..cb149bb6 100644 --- a/providers/dns/linode/linode_test.go +++ b/providers/dns/linode/linode_test.go @@ -52,6 +52,7 @@ func setupTest(t *testing.T, responses MockResponseMap) string { _, err = w.Write(rawResponse) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/liquidweb/liquidweb_test.go b/providers/dns/liquidweb/liquidweb_test.go index 100a98d1..17c02252 100644 --- a/providers/dns/liquidweb/liquidweb_test.go +++ b/providers/dns/liquidweb/liquidweb_test.go @@ -213,6 +213,7 @@ func TestDNSProvider_Present(t *testing.T) { }`) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }) diff --git a/providers/dns/luadns/internal/client_test.go b/providers/dns/luadns/internal/client_test.go index 04f9abc5..f3cc4642 100644 --- a/providers/dns/luadns/internal/client_test.go +++ b/providers/dns/luadns/internal/client_test.go @@ -29,6 +29,7 @@ func TestClient_ListZones(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic bWU6c2VjcmV0QQ==" { http.Error(rw, fmt.Sprintf("invalid authentication: %s", auth), http.StatusUnauthorized) + return } file, err := os.Open("./fixtures/list_zones.json") @@ -93,6 +94,7 @@ func TestClient_CreateRecord(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic bWU6c2VjcmV0Qg==" { http.Error(rw, fmt.Sprintf("invalid authentication: %s", auth), http.StatusUnauthorized) + return } file, err := os.Open("./fixtures/create_record.json") @@ -150,6 +152,7 @@ func TestClient_DeleteRecord(t *testing.T) { auth := req.Header.Get("Authorization") if auth != "Basic bWU6c2VjcmV0Qw==" { http.Error(rw, fmt.Sprintf("invalid authentication: %s", auth), http.StatusUnauthorized) + return } file, err := os.Open("./fixtures/delete_record.json") diff --git a/providers/dns/netcup/internal/client_test.go b/providers/dns/netcup/internal/client_test.go index 87dc1815..18747793 100644 --- a/providers/dns/netcup/internal/client_test.go +++ b/providers/dns/netcup/internal/client_test.go @@ -146,10 +146,12 @@ func TestClient_Login(t *testing.T) { raw, err := io.ReadAll(req.Body) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } if string(raw) != `{"action":"login","param":{"customernumber":"a","apikey":"b","apipassword":"c"}}` { http.Error(rw, fmt.Sprintf("invalid request body: %s", string(raw)), http.StatusBadRequest) + return } response := ` @@ -169,6 +171,7 @@ func TestClient_Login(t *testing.T) { _, err = rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) @@ -206,6 +209,7 @@ func TestClient_Login_errors(t *testing.T) { _, err := rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }, }, @@ -226,6 +230,7 @@ func TestClient_Login_errors(t *testing.T) { _, err := rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }, }, @@ -254,10 +259,12 @@ func TestClient_Logout(t *testing.T) { raw, err := io.ReadAll(req.Body) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } if string(raw) != `{"action":"logout","param":{"customernumber":"a","apikey":"b","apisessionid":"session-id"}}` { http.Error(rw, fmt.Sprintf("invalid request body: %s", string(raw)), http.StatusBadRequest) + return } response := ` @@ -274,6 +281,7 @@ func TestClient_Logout(t *testing.T) { _, err = rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) @@ -309,6 +317,7 @@ func TestClient_Logout_errors(t *testing.T) { _, err := rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }, }, @@ -336,10 +345,12 @@ func TestClient_GetDNSRecords(t *testing.T) { raw, err := io.ReadAll(req.Body) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } if string(raw) != `{"action":"infoDnsRecords","param":{"domainname":"example.com","customernumber":"a","apikey":"b","apisessionid":"api-session-id"}}` { http.Error(rw, fmt.Sprintf("invalid request body: %s", string(raw)), http.StatusBadRequest) + return } response := ` @@ -378,6 +389,7 @@ func TestClient_GetDNSRecords(t *testing.T) { _, err = rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }) @@ -435,6 +447,7 @@ func TestClient_GetDNSRecords_errors(t *testing.T) { _, err := rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }, }, @@ -444,10 +457,12 @@ func TestClient_GetDNSRecords_errors(t *testing.T) { raw, err := io.ReadAll(req.Body) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } if string(raw) != `{"action":"infoDnsRecords","param":{"domainname":"example.com","customernumber":"a","apikey":"b","apisessionid":"api-session-id"}}` { http.Error(rw, fmt.Sprintf("invalid request body: %s", string(raw)), http.StatusBadRequest) + return } response := ` @@ -464,6 +479,7 @@ func TestClient_GetDNSRecords_errors(t *testing.T) { _, err = rw.Write([]byte(response)) if err != nil { http.Error(rw, err.Error(), http.StatusInternalServerError) + return } }, }, diff --git a/providers/dns/nicmanager/internal/client.go b/providers/dns/nicmanager/internal/client.go index 31e35fb2..246a8ee4 100644 --- a/providers/dns/nicmanager/internal/client.go +++ b/providers/dns/nicmanager/internal/client.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "path" @@ -83,7 +82,7 @@ func (c Client) GetZone(name string) (*Zone, error) { defer func() { _ = resp.Body.Close() }() if resp.StatusCode >= http.StatusBadRequest { - b, _ := ioutil.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) msg := APIError{StatusCode: resp.StatusCode} if err = json.Unmarshal(b, &msg); err != nil { @@ -111,7 +110,7 @@ func (c Client) AddRecord(zone string, req RecordCreateUpdate) error { defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusAccepted { - b, _ := ioutil.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) msg := APIError{StatusCode: resp.StatusCode} if err = json.Unmarshal(b, &msg); err != nil { @@ -133,7 +132,7 @@ func (c Client) DeleteRecord(zone string, record int) error { defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusAccepted { - b, _ := ioutil.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) msg := APIError{StatusCode: resp.StatusCode} if err = json.Unmarshal(b, &msg); err != nil { diff --git a/providers/dns/nifcloud/internal/client.go b/providers/dns/nifcloud/internal/client.go index 0c21208a..24ad195a 100644 --- a/providers/dns/nifcloud/internal/client.go +++ b/providers/dns/nifcloud/internal/client.go @@ -114,7 +114,7 @@ func (c *Client) ChangeResourceRecordSets(hostedZoneID string, input ChangeResou requestURL := fmt.Sprintf("%s/%s/hostedzone/%s/rrset", c.BaseURL, apiVersion, hostedZoneID) body := &bytes.Buffer{} - body.Write([]byte(xml.Header)) + body.WriteString(xml.Header) err := xml.NewEncoder(body).Encode(input) if err != nil { return nil, err diff --git a/providers/dns/otc/otc.go b/providers/dns/otc/otc.go index 43d5378b..38cf2cb1 100644 --- a/providers/dns/otc/otc.go +++ b/providers/dns/otc/otc.go @@ -146,7 +146,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { Description: "Added TXT record for ACME dns-01 challenge using lego client", Type: "TXT", TTL: d.config.TTL, - Records: []string{fmt.Sprintf("\"%s\"", value)}, + Records: []string{fmt.Sprintf("%q", value)}, } _, err = d.sendRequest(http.MethodPost, resource, r1) diff --git a/providers/dns/scaleway/scaleway.go b/providers/dns/scaleway/scaleway.go index 4c42225d..8c45ec90 100644 --- a/providers/dns/scaleway/scaleway.go +++ b/providers/dns/scaleway/scaleway.go @@ -114,7 +114,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { fqdn, value := dns01.GetRecord(domain, keyAuth) records := []*scwdomain.Record{{ - Data: fmt.Sprintf(`"%s"`, value), + Data: fmt.Sprintf(`%q`, value), Name: fqdn, TTL: uint32(d.config.TTL), Type: scwdomain.RecordTypeTXT, @@ -144,7 +144,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { recordIdentifier := &scwdomain.RecordIdentifier{ Name: fqdn, Type: scwdomain.RecordTypeTXT, - Data: scw.StringPtr(fmt.Sprintf(`"%s"`, value)), + Data: scw.StringPtr(fmt.Sprintf(`%q`, value)), } req := &scwdomain.UpdateDNSZoneRecordsRequest{ diff --git a/providers/dns/yandex/internal/client_test.go b/providers/dns/yandex/internal/client_test.go index 9dca11b9..7b7bb589 100644 --- a/providers/dns/yandex/internal/client_test.go +++ b/providers/dns/yandex/internal/client_test.go @@ -42,6 +42,7 @@ func TestAddRecord(t *testing.T) { err := r.ParseForm() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + return } assert.Equal(t, `content=txtTXTtxtTXTtxtTXT&domain=example.com&subdomain=foo&ttl=300&type=TXT`, r.PostForm.Encode()) @@ -63,6 +64,7 @@ func TestAddRecord(t *testing.T) { err = json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, data: Record{ @@ -82,6 +84,7 @@ func TestAddRecord(t *testing.T) { err := r.ParseForm() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + return } assert.Equal(t, `content=txtTXTtxtTXTtxtTXT&domain=example.com&subdomain=foo&ttl=300&type=TXT`, r.PostForm.Encode()) @@ -95,6 +98,7 @@ func TestAddRecord(t *testing.T) { err = json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, data: Record{ @@ -142,6 +146,7 @@ func TestRemoveRecord(t *testing.T) { err := r.ParseForm() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + return } assert.Equal(t, `domain=example.com&record_id=6`, r.PostForm.Encode()) @@ -155,6 +160,7 @@ func TestRemoveRecord(t *testing.T) { err = json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, data: Record{ @@ -171,6 +177,7 @@ func TestRemoveRecord(t *testing.T) { err := r.ParseForm() if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + return } assert.Equal(t, `domain=example.com&record_id=6`, r.PostForm.Encode()) @@ -185,6 +192,7 @@ func TestRemoveRecord(t *testing.T) { err = json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, data: Record{ @@ -256,6 +264,7 @@ func TestGetRecords(t *testing.T) { err := json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, domain: "example.com", @@ -277,6 +286,7 @@ func TestGetRecords(t *testing.T) { err := json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) + return } }, domain: "example.com", diff --git a/providers/dns/zoneee/zoneee_test.go b/providers/dns/zoneee/zoneee_test.go index fa5133a8..cc67fac7 100644 --- a/providers/dns/zoneee/zoneee_test.go +++ b/providers/dns/zoneee/zoneee_test.go @@ -336,11 +336,12 @@ func mustParse(rawURL string) *url.URL { func mockHandlerCreateRecord(rw http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { http.Error(rw, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) + return } username, apiKey, ok := req.BasicAuth() if username != "bar" || apiKey != "foo" || !ok { - rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm="%s"`, "Please enter your username and API key.")) + rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm=%q`, "Please enter your username and API key.")) http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } @@ -373,11 +374,12 @@ func mockHandlerGetRecords(records []txtRecord) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { if req.Method != http.MethodGet { http.Error(rw, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) + return } username, apiKey, ok := req.BasicAuth() if username != "bar" || apiKey != "foo" || !ok { - rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm="%s"`, "Please enter your username and API key.")) + rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm=%q`, "Please enter your username and API key.")) http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } @@ -409,7 +411,7 @@ func mockHandlerDeleteRecord(rw http.ResponseWriter, req *http.Request) { username, apiKey, ok := req.BasicAuth() if username != "bar" || apiKey != "foo" || !ok { - rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm="%s"`, "Please enter your username and API key.")) + rw.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm=%q`, "Please enter your username and API key.")) http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return }