diff --git a/.golangci.toml b/.golangci.toml index f0ee5e03..498387ec 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -41,6 +41,7 @@ "cyclomatic complexity (.+) of func `NewDNSChallengeProviderByName` is high (.+)", # providers/dns/dns_providers.go "string `(lego\\.wtf|manhattan)` has (\\d+) occurrences, make it a constant", #providers/dns/gcloud/googlecloud_test.go + "(dnsHelp|createRenew\\$1|createRun\\$1|run) - result 0 \\(error\\) is always nil", # cmd/ "`(tlsFeatureExtensionOID|ocspMustStapleFeature)` is a global variable", # certcrypto/crypto.go "`(defaultNameservers|recursiveNameservers|dnsTimeout|fqdnToZone|muFqdnToZone)` is a global variable", # challenge/dns01/nameserver.go "`idPeAcmeIdentifierV1` is a global variable", # challenge/tlsalpn01/tls_alpn_challenge.go diff --git a/.travis.yml b/.travis.yml index 9012dcba..3e5f26a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ before_install: - go get -u github.com/letsencrypt/pebble/... # Install linters and misspell - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.12.5 + - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.13.2 - golangci-lint --version install: diff --git a/acme/api/certificate_test.go b/acme/api/certificate_test.go index 2c5642e8..b76ec381 100644 --- a/acme/api/certificate_test.go +++ b/acme/api/certificate_test.go @@ -77,7 +77,7 @@ func TestCertificateService_Get_issuerRelUp(t *testing.T) { mux, apiURL, tearDown := tester.SetupFakeAPI() defer tearDown() - mux.HandleFunc("/certificate", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/certificate", func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Link", "<"+apiURL+`/issuer>; rel="up"`) _, err := w.Write([]byte(certResponseMock)) if err != nil { @@ -85,7 +85,7 @@ func TestCertificateService_Get_issuerRelUp(t *testing.T) { } }) - mux.HandleFunc("/issuer", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/issuer", func(w http.ResponseWriter, _ *http.Request) { p, _ := pem.Decode([]byte(issuerMock)) _, err := w.Write(p.Bytes) if err != nil { @@ -109,7 +109,7 @@ func TestCertificateService_Get_embeddedIssuer(t *testing.T) { mux, apiURL, tearDown := tester.SetupFakeAPI() defer tearDown() - mux.HandleFunc("/certificate", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/certificate", func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/acme/api/internal/nonces/nonce_manager_test.go b/acme/api/internal/nonces/nonce_manager_test.go index cc007f73..7ec11b63 100644 --- a/acme/api/internal/nonces/nonce_manager_test.go +++ b/acme/api/internal/nonces/nonce_manager_test.go @@ -12,7 +12,7 @@ import ( ) func TestNotHoldingLockWhileMakingHTTPRequests(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { time.Sleep(250 * time.Millisecond) w.Header().Add("Replay-Nonce", "12345") w.Header().Add("Retry-After", "0") diff --git a/acme/api/internal/secure/jws_test.go b/acme/api/internal/secure/jws_test.go index 48100518..8daa7737 100644 --- a/acme/api/internal/secure/jws_test.go +++ b/acme/api/internal/secure/jws_test.go @@ -13,7 +13,7 @@ import ( ) func TestNotHoldingLockWhileMakingHTTPRequests(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { time.Sleep(250 * time.Millisecond) w.Header().Add("Replay-Nonce", "12345") w.Header().Add("Retry-After", "0") diff --git a/acme/api/internal/sender/sender_test.go b/acme/api/internal/sender/sender_test.go index 34691479..0ab02257 100644 --- a/acme/api/internal/sender/sender_test.go +++ b/acme/api/internal/sender/sender_test.go @@ -12,7 +12,7 @@ import ( func TestDo_UserAgentOnAllHTTPMethod(t *testing.T) { var ua, method string - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { ua = r.Header.Get("User-Agent") method = r.Method })) diff --git a/certificate/certificates_test.go b/certificate/certificates_test.go index 6991600d..61811fa7 100644 --- a/certificate/certificates_test.go +++ b/certificate/certificates_test.go @@ -80,7 +80,7 @@ func Test_checkResponse(t *testing.T) { mux, apiURL, tearDown := tester.SetupFakeAPI() defer tearDown() - mux.HandleFunc("/certificate", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/certificate", func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -119,7 +119,7 @@ func Test_checkResponse_issuerRelUp(t *testing.T) { mux, apiURL, tearDown := tester.SetupFakeAPI() defer tearDown() - mux.HandleFunc("/certificate", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/certificate", func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Link", "<"+apiURL+`/issuer>; rel="up"`) _, err := w.Write([]byte(certResponseMock)) if err != nil { @@ -127,7 +127,7 @@ func Test_checkResponse_issuerRelUp(t *testing.T) { } }) - mux.HandleFunc("/issuer", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/issuer", func(w http.ResponseWriter, _ *http.Request) { p, _ := pem.Decode([]byte(issuerMock)) _, err := w.Write(p.Bytes) if err != nil { @@ -167,7 +167,7 @@ func Test_checkResponse_embeddedIssuer(t *testing.T) { mux, apiURL, tearDown := tester.SetupFakeAPI() defer tearDown() - mux.HandleFunc("/certificate", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/certificate", func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte(certResponseMock)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/providers/dns/azure/azure_test.go b/providers/dns/azure/azure_test.go index 21b857a1..b7adbe93 100644 --- a/providers/dns/azure/azure_test.go +++ b/providers/dns/azure/azure_test.go @@ -111,7 +111,7 @@ func TestNewDNSProviderConfig(t *testing.T) { tenantID: "C", subscriptionID: "", resourceGroup: "", - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte("foo")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/providers/dns/netcup/internal/client_test.go b/providers/dns/netcup/internal/client_test.go index db41e565..63bc93ba 100644 --- a/providers/dns/netcup/internal/client_test.go +++ b/providers/dns/netcup/internal/client_test.go @@ -184,13 +184,13 @@ func TestClient_Login_errors(t *testing.T) { }{ { desc: "HTTP error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { http.Error(rw, "error message", http.StatusInternalServerError) }, }, { desc: "API error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { response := ` { "serverrequestid":"YxTr4EzdbJ101T211zR4yzUEMVE", @@ -210,7 +210,7 @@ func TestClient_Login_errors(t *testing.T) { }, { desc: "responsedata marshaling error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { response := ` { "serverrequestid": "srv-request-id", @@ -289,13 +289,13 @@ func TestClient_Logout_errors(t *testing.T) { }{ { desc: "HTTP error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { http.Error(rw, "error message", http.StatusInternalServerError) }, }, { desc: "API error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { response := ` { "serverrequestid":"YxTr4EzdbJ101T211zR4yzUEMVE", @@ -417,13 +417,13 @@ func TestClient_GetDNSRecords_errors(t *testing.T) { }{ { desc: "HTTP error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { http.Error(rw, "error message", http.StatusInternalServerError) }, }, { desc: "API error", - handler: func(rw http.ResponseWriter, req *http.Request) { + handler: func(rw http.ResponseWriter, _ *http.Request) { response := ` { "serverrequestid":"YxTr4EzdbJ101T211zR4yzUEMVE", diff --git a/providers/dns/nifcloud/internal/client_test.go b/providers/dns/nifcloud/internal/client_test.go index 2845591e..b9cec1b1 100644 --- a/providers/dns/nifcloud/internal/client_test.go +++ b/providers/dns/nifcloud/internal/client_test.go @@ -11,7 +11,7 @@ import ( ) func runTestServer(responseBody string, statusCode int) *httptest.Server { - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(statusCode) fmt.Fprintln(w, responseBody) })) diff --git a/providers/dns/otc/mock_test.go b/providers/dns/otc/mock_test.go index 5a96c466..31778c01 100644 --- a/providers/dns/otc/mock_test.go +++ b/providers/dns/otc/mock_test.go @@ -41,7 +41,7 @@ func (m *DNSServerMock) ShutdownServer() { // HandleAuthSuccessfully Handle auth successfully func (m *DNSServerMock) HandleAuthSuccessfully() { - m.Mux.HandleFunc("/v3/auth/token", func(w http.ResponseWriter, r *http.Request) { + m.Mux.HandleFunc("/v3/auth/token", func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("X-Subject-Token", fakeOTCToken) fmt.Fprintf(w, `{ diff --git a/providers/dns/rackspace/rackspace_test.go b/providers/dns/rackspace/rackspace_test.go index fcaef794..361d5f77 100644 --- a/providers/dns/rackspace/rackspace_test.go +++ b/providers/dns/rackspace/rackspace_test.go @@ -135,7 +135,7 @@ func identityHandler(dnsEndpoint string) http.Handler { resp := strings.Replace(identityResponseMock, "https://dns.api.rackspacecloud.com/v1.0/123456", dnsEndpoint, 1) w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, resp) + fmt.Fprint(w, resp) }) } @@ -146,7 +146,7 @@ func dnsHandler() *http.ServeMux { mux.HandleFunc("/123456/domains", func(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get("name") == "example.com" { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, zoneDetailsMock) + fmt.Fprint(w, zoneDetailsMock) return } w.WriteHeader(http.StatusBadRequest) @@ -168,12 +168,12 @@ func dnsHandler() *http.ServeMux { } w.WriteHeader(http.StatusAccepted) - fmt.Fprintf(w, recordResponseMock) + fmt.Fprint(w, recordResponseMock) // Used by `findTxtRecord()` finding `record.ID` "?type=TXT&name=_acme-challenge.example.com" case http.MethodGet: if r.URL.Query().Get("type") == "TXT" && r.URL.Query().Get("name") == "_acme-challenge.example.com" { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, recordDetailsMock) + fmt.Fprint(w, recordDetailsMock) return } w.WriteHeader(http.StatusBadRequest) @@ -182,7 +182,7 @@ func dnsHandler() *http.ServeMux { case http.MethodDelete: if r.URL.Query().Get("id") == "TXT-654321" { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, recordDeleteMock) + fmt.Fprint(w, recordDeleteMock) return } w.WriteHeader(http.StatusBadRequest) diff --git a/providers/dns/stackpath/stackpath_test.go b/providers/dns/stackpath/stackpath_test.go index d3f3dd1a..050c5cae 100644 --- a/providers/dns/stackpath/stackpath_test.go +++ b/providers/dns/stackpath/stackpath_test.go @@ -157,7 +157,7 @@ func TestDNSProvider_getZoneRecords(t *testing.T) { provider, mux, tearDown := setupMockAPITest() defer tearDown() - mux.HandleFunc("/STACK_ID/zones/A/records", func(w http.ResponseWriter, req *http.Request) { + mux.HandleFunc("/STACK_ID/zones/A/records", func(w http.ResponseWriter, _ *http.Request) { content := ` { "records": [ @@ -188,7 +188,7 @@ func TestDNSProvider_getZoneRecords_apiError(t *testing.T) { provider, mux, tearDown := setupMockAPITest() defer tearDown() - mux.HandleFunc("/STACK_ID/zones/A/records", func(w http.ResponseWriter, req *http.Request) { + mux.HandleFunc("/STACK_ID/zones/A/records", func(w http.ResponseWriter, _ *http.Request) { content := ` { "code": 401, @@ -213,7 +213,7 @@ func TestDNSProvider_getZones(t *testing.T) { provider, mux, tearDown := setupMockAPITest() defer tearDown() - mux.HandleFunc("/STACK_ID/zones", func(w http.ResponseWriter, req *http.Request) { + mux.HandleFunc("/STACK_ID/zones", func(w http.ResponseWriter, _ *http.Request) { content := ` { "pageInfo": { diff --git a/providers/dns/vegadns/vegadns_test.go b/providers/dns/vegadns/vegadns_test.go index 97414f33..6de4f404 100644 --- a/providers/dns/vegadns/vegadns_test.go +++ b/providers/dns/vegadns/vegadns_test.go @@ -145,7 +145,7 @@ func muxSuccess() *http.ServeMux { mux.HandleFunc("/1.0/token", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, tokenResponseMock) + fmt.Fprint(w, tokenResponseMock) return } w.WriteHeader(http.StatusBadRequest) @@ -154,7 +154,7 @@ func muxSuccess() *http.ServeMux { mux.HandleFunc("/1.0/domains", func(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get("search") == "example.com" { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, domainsResponseMock) + fmt.Fprint(w, domainsResponseMock) return } w.WriteHeader(http.StatusNotFound) @@ -165,14 +165,14 @@ func muxSuccess() *http.ServeMux { case http.MethodGet: if r.URL.Query().Get("domain_id") == "1" { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, recordsResponseMock) + fmt.Fprint(w, recordsResponseMock) return } w.WriteHeader(http.StatusNotFound) return case http.MethodPost: w.WriteHeader(http.StatusCreated) - fmt.Fprintf(w, recordCreatedResponseMock) + fmt.Fprint(w, recordCreatedResponseMock) return } w.WriteHeader(http.StatusBadRequest) @@ -181,7 +181,7 @@ func muxSuccess() *http.ServeMux { mux.HandleFunc("/1.0/records/3", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodDelete { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, recordDeletedResponseMock) + fmt.Fprint(w, recordDeletedResponseMock) return } w.WriteHeader(http.StatusBadRequest) @@ -201,13 +201,13 @@ func muxFailToFindZone() *http.ServeMux { mux.HandleFunc("/1.0/token", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, tokenResponseMock) + fmt.Fprint(w, tokenResponseMock) return } w.WriteHeader(http.StatusBadRequest) }) - mux.HandleFunc("/1.0/domains", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/1.0/domains", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) }) @@ -220,7 +220,7 @@ func muxFailToCreateTXT() *http.ServeMux { mux.HandleFunc("/1.0/token", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, tokenResponseMock) + fmt.Fprint(w, tokenResponseMock) return } w.WriteHeader(http.StatusBadRequest) @@ -229,7 +229,7 @@ func muxFailToCreateTXT() *http.ServeMux { mux.HandleFunc("/1.0/domains", func(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get("search") == testDomain { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, domainsResponseMock) + fmt.Fprint(w, domainsResponseMock) return } w.WriteHeader(http.StatusNotFound) @@ -240,7 +240,7 @@ func muxFailToCreateTXT() *http.ServeMux { case http.MethodGet: if r.URL.Query().Get("domain_id") == "1" { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, recordsResponseMock) + fmt.Fprint(w, recordsResponseMock) return } w.WriteHeader(http.StatusNotFound) @@ -261,7 +261,7 @@ func muxFailToGetRecordID() *http.ServeMux { mux.HandleFunc("/1.0/token", func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, tokenResponseMock) + fmt.Fprint(w, tokenResponseMock) return } w.WriteHeader(http.StatusBadRequest) @@ -270,7 +270,7 @@ func muxFailToGetRecordID() *http.ServeMux { mux.HandleFunc("/1.0/domains", func(w http.ResponseWriter, r *http.Request) { if r.URL.Query().Get("search") == testDomain { w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, domainsResponseMock) + fmt.Fprint(w, domainsResponseMock) return } w.WriteHeader(http.StatusNotFound) diff --git a/registration/registar_test.go b/registration/registar_test.go index 221d8c25..d011d6d0 100644 --- a/registration/registar_test.go +++ b/registration/registar_test.go @@ -17,7 +17,7 @@ func TestRegistrar_ResolveAccountByKey(t *testing.T) { mux, apiURL, tearDown := tester.SetupFakeAPI() defer tearDown() - mux.HandleFunc("/account", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/account", func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Location", apiURL+"/account_recovery") _, err := w.Write([]byte("{}")) if err != nil { @@ -25,7 +25,7 @@ func TestRegistrar_ResolveAccountByKey(t *testing.T) { } }) - mux.HandleFunc("/account_recovery", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/account_recovery", func(w http.ResponseWriter, _ *http.Request) { err := tester.WriteJSONResponse(w, acme.Account{ Status: "valid", })