chore: update linter (#2046)

This commit is contained in:
Ludovic Fernandez 2023-10-31 14:08:50 +01:00 committed by GitHub
parent 4f242c93e6
commit d51b5e408b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 127 additions and 116 deletions

View file

@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.54.1
GOLANGCI_LINT_VERSION: v1.55.1
HUGO_VERSION: '0.117.0'
CGO_ENABLED: 0
LEGO_E2E_TESTS: CI

View file

@ -88,6 +88,19 @@ linters-settings:
disabled: true
- name: unreachable-code
- name: redefines-builtin-id
testifylint:
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- float-compare
- len
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper
linters:
enable-all: true

View file

@ -4,7 +4,6 @@ import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -28,7 +27,7 @@ func Test_obtainError_Join(t *testing.T) {
err := failures.Join()
to := &TomatoError{}
assert.ErrorAs(t, err, &to)
require.ErrorAs(t, err, &to)
}
func Test_obtainError_Join_multiple_domains(t *testing.T) {
@ -40,16 +39,16 @@ func Test_obtainError_Join_multiple_domains(t *testing.T) {
err := failures.Join()
to := &TomatoError{}
assert.ErrorAs(t, err, &to)
require.ErrorAs(t, err, &to)
ca := &CarrotError{}
assert.ErrorAs(t, err, &ca)
require.ErrorAs(t, err, &ca)
}
func Test_obtainError_Join_no_error(t *testing.T) {
failures := newObtainError()
assert.NoError(t, failures.Join())
require.NoError(t, failures.Join())
}
func Test_obtainError_Join_same_domain(t *testing.T) {
@ -66,5 +65,5 @@ func Test_obtainError_Join_same_domain(t *testing.T) {
}
ca := &CarrotError{}
assert.ErrorAs(t, err, &ca)
require.ErrorAs(t, err, &ca)
}

View file

@ -5,7 +5,6 @@ import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -32,14 +31,14 @@ func TestDNSProviderManual(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
file, err := os.CreateTemp("", "lego_test")
assert.NoError(t, err)
require.NoError(t, err)
defer func() { _ = os.Remove(file.Name()) }()
_, err = file.WriteString(test.input)
assert.NoError(t, err)
require.NoError(t, err)
_, err = file.Seek(0, io.SeekStart)
assert.NoError(t, err)
require.NoError(t, err)
os.Stdin = file

View file

@ -141,7 +141,7 @@ func TestChallengeIPaddress(t *testing.T) {
assert.Len(t, connState.PeerCertificates, 1, "Expected the challenge server to return exactly one certificate")
remoteCert := connState.PeerCertificates[0]
assert.Len(t, remoteCert.DNSNames, 0, "Expected the challenge certificate to have no DNSNames entry in context of challenge for IP")
assert.Empty(t, remoteCert.DNSNames, "Expected the challenge certificate to have no DNSNames entry in context of challenge for IP")
assert.Len(t, remoteCert.IPAddresses, 1, "Expected the challenge certificate to have exactly one IPAddresses entry")
assert.True(t, net.ParseIP("127.0.0.1").Equal(remoteCert.IPAddresses[0]), "challenge certificate IPAddress ")
assert.NotEmpty(t, remoteCert.Extensions, "Expected the challenge certificate to contain extensions")

View file

@ -1635,17 +1635,17 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()
ew.writeln(`Credentials:`)
ew.writeln(` - "LIQUID_WEB_PASSWORD": Liquid Web API Password`)
ew.writeln(` - "LIQUID_WEB_USERNAME": Liquid Web API Username`)
ew.writeln(` - "LWAPI_PASSWORD": Liquid Web API Password`)
ew.writeln(` - "LWAPI_USERNAME": Liquid Web API Username`)
ew.writeln()
ew.writeln(`Additional Configuration:`)
ew.writeln(` - "LIQUID_WEB_HTTP_TIMEOUT": Maximum waiting time for the DNS records to be created (not verified)`)
ew.writeln(` - "LIQUID_WEB_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "LIQUID_WEB_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "LIQUID_WEB_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "LIQUID_WEB_URL": Liquid Web API endpoint`)
ew.writeln(` - "LIQUID_WEB_ZONE": DNS Zone`)
ew.writeln(` - "LWAPI_HTTP_TIMEOUT": Maximum waiting time for the DNS records to be created (not verified)`)
ew.writeln(` - "LWAPI_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "LWAPI_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "LWAPI_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "LWAPI_URL": Liquid Web API endpoint`)
ew.writeln(` - "LWAPI_ZONE": DNS Zone`)
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/liquidweb`)

View file

@ -26,8 +26,8 @@ Configuration for [Liquid Web](https://liquidweb.com).
Here is an example bash command using the Liquid Web provider:
```bash
LIQUID_WEB_USERNAME=someuser \
LIQUID_WEB_PASSWORD=somepass \
LWAPI_USERNAME=someuser \
LWAPI_PASSWORD=somepass \
lego --email you@example.com --dns liquidweb --domains my.example.org run
```
@ -38,8 +38,8 @@ lego --email you@example.com --dns liquidweb --domains my.example.org run
| Environment Variable Name | Description |
|-----------------------|-------------|
| `LIQUID_WEB_PASSWORD` | Liquid Web API Password |
| `LIQUID_WEB_USERNAME` | Liquid Web API Username |
| `LWAPI_PASSWORD` | Liquid Web API Password |
| `LWAPI_USERNAME` | Liquid Web API Username |
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
@ -49,12 +49,12 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
| Environment Variable Name | Description |
|--------------------------------|-------------|
| `LIQUID_WEB_HTTP_TIMEOUT` | Maximum waiting time for the DNS records to be created (not verified) |
| `LIQUID_WEB_POLLING_INTERVAL` | Time between DNS propagation check |
| `LIQUID_WEB_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `LIQUID_WEB_TTL` | The TTL of the TXT record used for the DNS challenge |
| `LIQUID_WEB_URL` | Liquid Web API endpoint |
| `LIQUID_WEB_ZONE` | DNS Zone |
| `LWAPI_HTTP_TIMEOUT` | Maximum waiting time for the DNS records to be created (not verified) |
| `LWAPI_POLLING_INTERVAL` | Time between DNS propagation check |
| `LWAPI_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `LWAPI_TTL` | The TTL of the TXT record used for the DNS challenge |
| `LWAPI_URL` | Liquid Web API endpoint |
| `LWAPI_ZONE` | DNS Zone |
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).

View file

@ -28,10 +28,10 @@ const (
type acmeDNSClient interface {
// UpdateTXTRecord updates the provided account's TXT record
// to the given value or returns an error.
UpdateTXTRecord(goacmedns.Account, string) error
UpdateTXTRecord(account goacmedns.Account, value string) error
// RegisterAccount registers and returns a new account
// with the given allowFrom restriction or returns an error.
RegisterAccount([]string) (goacmedns.Account, error)
RegisterAccount(allowFrom []string) (goacmedns.Account, error)
}
// DNSProvider implements the challenge.Provider interface.

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"
)
@ -133,10 +132,10 @@ func TestLivePresent(t *testing.T) {
envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}
func TestLiveCleanUp(t *testing.T) {
@ -146,8 +145,8 @@ func TestLiveCleanUp(t *testing.T) {
envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}

View file

@ -11,6 +11,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
@ -58,7 +59,7 @@ func (c *Client) ListRecords(ctx context.Context, account, dnsZone string) (*Lis
}
for len(result.Response.RR) < result.Response.Total[0] {
query.Add("first", fmt.Sprint(result.Response.Last[0]+1))
query.Add("first", strconv.Itoa(result.Response.Last[0]+1))
tmp := &Response[*ListRecordsResponse]{}
err := c.do(ctx, query, tmp)
@ -76,7 +77,7 @@ func (c *Client) ListRecords(ctx context.Context, account, dnsZone string) (*Lis
// AddRecord adds a DNS record.
// https://portal.brandit.com/apidocv3#addDNSRR
func (c *Client) AddRecord(ctx context.Context, domainName, account, newRecordID string, record Record) (*AddRecord, error) {
value := strings.Join([]string{record.Name, fmt.Sprint(record.TTL), "IN", record.Type, record.Content}, " ")
value := strings.Join([]string{record.Name, strconv.Itoa(record.TTL), "IN", record.Type, record.Content}, " ")
query := url.Values{}
query.Add("command", "addDNSRR")

View file

@ -6,7 +6,6 @@ import (
"github.com/go-acme/lego/v4/platform/tester"
"github.com/go-acme/lego/v4/providers/dns/checkdomain/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -110,10 +109,10 @@ func TestLivePresent(t *testing.T) {
envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}
func TestLiveCleanUp(t *testing.T) {
@ -123,8 +122,8 @@ func TestLiveCleanUp(t *testing.T) {
envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}

View file

@ -29,12 +29,12 @@ func TestKnownDNSProviderError(t *testing.T) {
envTest.ClearEnv()
provider, err := NewDNSChallengeProviderByName("exec")
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, provider)
}
func TestUnknownDNSProvider(t *testing.T) {
provider, err := NewDNSChallengeProviderByName("foobar")
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, provider)
}

View file

@ -121,12 +121,12 @@ func TestDNSProvider_Present(t *testing.T) {
assert.Equal(t, http.MethodGet, r.Method, "method")
q := r.URL.Query()
assert.Equal(t, q.Get("key"), fakeAPIKey)
assert.Equal(t, q.Get("cmd"), "dns-add_record")
assert.Equal(t, q.Get("format"), "json")
assert.Equal(t, q.Get("record"), "_acme-challenge.example.com")
assert.Equal(t, q.Get("value"), fakeKeyAuth)
assert.Equal(t, q.Get("comment"), "Managed+By+lego")
assert.Equal(t, fakeAPIKey, q.Get("key"))
assert.Equal(t, "dns-add_record", q.Get("cmd"))
assert.Equal(t, "json", q.Get("format"))
assert.Equal(t, "_acme-challenge.example.com", q.Get("record"))
assert.Equal(t, fakeKeyAuth, q.Get("value"))
assert.Equal(t, "Managed+By+lego", q.Get("comment"))
_, err := fmt.Fprintf(w, `{"data":"record_added","result":"success"}`)
if err != nil {
@ -163,12 +163,12 @@ func TestDNSProvider_Cleanup(t *testing.T) {
assert.Equal(t, http.MethodGet, r.Method, "method")
q := r.URL.Query()
assert.Equal(t, q.Get("key"), fakeAPIKey, "key mismatch")
assert.Equal(t, q.Get("cmd"), "dns-remove_record", "cmd mismatch")
assert.Equal(t, q.Get("format"), "json")
assert.Equal(t, q.Get("record"), "_acme-challenge.example.com")
assert.Equal(t, q.Get("value"), fakeKeyAuth, "value mismatch")
assert.Equal(t, q.Get("comment"), "Managed+By+lego")
assert.Equal(t, fakeAPIKey, q.Get("key"), "key mismatch")
assert.Equal(t, "dns-remove_record", q.Get("cmd"), "cmd mismatch")
assert.Equal(t, "json", q.Get("format"))
assert.Equal(t, "_acme-challenge.example.com", q.Get("record"))
assert.Equal(t, fakeKeyAuth, q.Get("value"), "value mismatch")
assert.Equal(t, "Managed+By+lego", q.Get("comment"))
_, err := fmt.Fprintf(w, `{"data":"record_removed","result":"success"}`)
if err != nil {

View file

@ -78,9 +78,9 @@ func TestLiveTTL(t *testing.T) {
}
t.Run(fmt.Sprintf("testing record set %d", i), func(t *testing.T) {
assert.Equal(t, rrset.Name, fqdn)
assert.Equal(t, rrset.Type, "TXT")
assert.Equal(t, rrset.TTL, dns01.DefaultTTL)
assert.Equal(t, fqdn, rrset.Name)
assert.Equal(t, "TXT", rrset.Type)
assert.Equal(t, dns01.DefaultTTL, rrset.TTL)
})
}
}

View file

@ -94,7 +94,7 @@ func TestClient_GetDNSRecords_error(t *testing.T) {
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
_, err := client.GetDNSRecords(context.Background(), "example.com")
assert.Error(t, err)
require.Error(t, err)
}
func TestClient_CreateHostRecord(t *testing.T) {
@ -135,7 +135,7 @@ func TestClient_CreateHostRecord_error(t *testing.T) {
}
_, err := client.CreateHostRecord(context.Background(), "example.com", record)
assert.Error(t, err)
require.Error(t, err)
}
func TestClient_RemoveHostRecord(t *testing.T) {
@ -160,7 +160,7 @@ func TestClient_RemoveHostRecord_error(t *testing.T) {
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
_, err := client.RemoveHostRecord(context.Background(), "example.com", "abc123")
assert.Error(t, err)
require.Error(t, err)
}
func testHandler(method string, statusCode int, filename string) http.HandlerFunc {

View file

@ -391,7 +391,6 @@ func TestLivePresent(t *testing.T) {
}
envTest.RestoreEnv()
provider, err := NewDNSProviderCredentials(envTest.GetValue(EnvProject))
require.NoError(t, err)

View file

@ -78,7 +78,7 @@ func TestClient_ListRecords_error(t *testing.T) {
records, err := client.ListRecords(context.Background(), 123)
assert.EqualError(t, err, "request failed with status code 401: API error: 400 - error description - field that the error occurred in")
require.EqualError(t, err, "request failed with status code 401: API error: 400 - error description - field that the error occurred in")
assert.Nil(t, records)
}

View file

@ -226,8 +226,8 @@ func Test_RemoveTxtEntryFromZone(t *testing.T) {
t.Parallel()
zone, modified := RemoveTxtEntryFromZone(test.input, "_acme-challenge")
assert.Equal(t, zone, test.expected)
assert.Equal(t, modified, test.modified)
assert.Equal(t, test.expected, zone)
assert.Equal(t, test.modified, modified)
})
}
}
@ -258,7 +258,7 @@ func Test_AddTxtEntryToZone(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
zone := AddTxtEntryToZone(test.input, "_acme-challenge", "test", 120)
assert.Equal(t, zone, test.expected)
assert.Equal(t, test.expected, zone)
})
}
}
@ -299,7 +299,7 @@ func Test_fixTxtLines(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
line := fixTxtLines(test.input)
assert.Equal(t, line, test.expected)
assert.Equal(t, test.expected, line)
})
}
}

View file

@ -265,7 +265,6 @@ func TestLivePresent(t *testing.T) {
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)

View file

@ -239,7 +239,7 @@ func TestClient_rpcCall_404(t *testing.T) {
client.BaseURL = server.URL + "/"
err := client.rpcCall(context.Background(), call, &responseString{})
assert.EqualError(t, err, "unexpected status code: [status code: 404] body: <?xml version='1.0' encoding='UTF-8'?>")
require.EqualError(t, err, "unexpected status code: [status code: 404] body: <?xml version='1.0' encoding='UTF-8'?>")
}
func TestClient_rpcCall_RPCError(t *testing.T) {
@ -270,7 +270,7 @@ func TestClient_rpcCall_RPCError(t *testing.T) {
client.BaseURL = server.URL + "/"
err := client.rpcCall(context.Background(), call, &responseString{})
assert.EqualError(t, err, "RPC Error: (201) Method signature error: 42")
require.EqualError(t, err, "RPC Error: (201) Method signature error: 42")
}
func TestUnmarshallFaultyRecordObject(t *testing.T) {

View file

@ -128,7 +128,7 @@ func TestLivePresent(t *testing.T) {
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}
func TestLiveCleanUp(t *testing.T) {
@ -143,5 +143,5 @@ func TestLiveCleanUp(t *testing.T) {
time.Sleep(2 * time.Second)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}

View file

@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
@ -73,7 +74,7 @@ func (c *Client) SetHosts(ctx context.Context, sld, tld string, hosts []Record)
addParam("TLD", tld),
func(values url.Values) {
for i, h := range hosts {
ind := fmt.Sprintf("%d", i+1)
ind := strconv.Itoa(i + 1)
values.Add("HostName"+ind, h.Name)
values.Add("RecordType"+ind, h.Type)
values.Add("Address"+ind, h.Address)

View file

@ -112,7 +112,6 @@ func TestLivePresent(t *testing.T) {
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)

View file

@ -356,7 +356,7 @@ func TestClient_UpdateDNSRecord_Live(t *testing.T) {
info := dns01.GetChallengeInfo(envTest.GetDomain(), "123d==")
zone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
require.NoError(t, err, fmt.Errorf("error finding DNSZone, %w", err))
require.NotErrorIs(t, err, fmt.Errorf("error finding DNSZone, %w", err))
hostname := strings.Replace(info.EffectiveFQDN, "."+zone, "", 1)

View file

@ -10,6 +10,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const fakeOTCToken = "62244bc21da68d03ebac94e6636ff01f"
@ -143,7 +144,7 @@ func (m *DNSServerMock) HandleListRecordsetsSuccessfully() {
assert.Equal(m.t, "application/json", r.Header.Get("Content-Type"))
raw, err := io.ReadAll(r.Body)
assert.Nil(m.t, err)
require.NoError(m.t, err)
exceptedString := `{
"name": "_acme-challenge.example.com.",
"description": "Added TXT record for ACME dns-01 challenge using lego client",

View file

@ -63,18 +63,18 @@ func (s *OTCSuite) TestLoginEnv() {
provider, err := NewDNSProvider()
s.Require().NoError(err)
s.Equal(provider.config.DomainName, "unittest1")
s.Equal(provider.config.UserName, "unittest2")
s.Equal(provider.config.Password, "unittest3")
s.Equal(provider.config.ProjectName, "unittest4")
s.Equal(provider.config.IdentityEndpoint, "unittest5")
s.Equal("unittest1", provider.config.DomainName)
s.Equal("unittest2", provider.config.UserName)
s.Equal("unittest3", provider.config.Password)
s.Equal("unittest4", provider.config.ProjectName)
s.Equal("unittest5", provider.config.IdentityEndpoint)
os.Setenv(EnvIdentityEndpoint, "")
provider, err = NewDNSProvider()
s.Require().NoError(err)
s.Equal(provider.config.IdentityEndpoint, "https://iam.eu-de.otc.t-systems.com:443/v3/auth/tokens")
s.Equal("https://iam.eu-de.otc.t-systems.com:443/v3/auth/tokens", provider.config.IdentityEndpoint)
}
func (s *OTCSuite) TestLoginEnvEmpty() {
@ -103,7 +103,7 @@ func (s *OTCSuite) TestDNSProvider_Present_EmptyZone() {
s.Require().NoError(err)
err = provider.Present("example.com", "", "foobar")
s.NotNil(err)
s.Error(err)
}
func (s *OTCSuite) TestDNSProvider_CleanUp() {

View file

@ -29,12 +29,12 @@ func TestNewDNSProviderConfig(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, provider.config)
assert.Equal(t, provider.token, "testToken", "The token should match")
assert.Equal(t, "testToken", provider.token, "The token should match")
}
func TestNewDNSProviderConfig_MissingCredErr(t *testing.T) {
_, err := NewDNSProviderConfig(NewDefaultConfig())
assert.EqualError(t, err, "rackspace: credentials missing")
require.EqualError(t, err, "rackspace: credentials missing")
}
func TestDNSProvider_Present(t *testing.T) {

View file

@ -83,7 +83,7 @@ func TestDNSProvider_addAndCleanupRecords(t *testing.T) {
require.NoError(t, e)
require.NotNil(t, updZone)
require.Len(t, updZone.Records, 0)
require.Empty(t, updZone.Records)
})
}
@ -143,6 +143,6 @@ func TestDNSProvider_concurrentAddAndCleanupRecords(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, updZone)
require.Len(t, updZone.Records, 0)
require.Empty(t, updZone.Records)
})
}

View file

@ -9,6 +9,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
@ -87,7 +88,7 @@ func (c *Client) AddRecord(ctx context.Context, zoneName string, record Record)
// EditRecord updates a record.
func (c *Client) EditRecord(ctx context.Context, zoneName string, id int64, record Record) error {
endpoint := c.createEndpoint(zoneName, fmt.Sprintf("%d", id))
endpoint := c.createEndpoint(zoneName, strconv.FormatInt(id, 10))
req, err := newJSONRequest(ctx, http.MethodPut, endpoint, record)
if err != nil {
@ -99,7 +100,7 @@ func (c *Client) EditRecord(ctx context.Context, zoneName string, id int64, reco
// DeleteRecord deletes a record.
func (c *Client) DeleteRecord(ctx context.Context, zoneName string, id int64) error {
endpoint := c.createEndpoint(zoneName, fmt.Sprintf("%d", id))
endpoint := c.createEndpoint(zoneName, strconv.FormatInt(id, 10))
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
if err != nil {

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"
)
@ -121,10 +120,10 @@ func TestLivePresent(t *testing.T) {
envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}
func TestLiveCleanUp(t *testing.T) {
@ -134,8 +133,8 @@ func TestLiveCleanUp(t *testing.T) {
envTest.RestoreEnv()
provider, err := NewDNSProvider()
assert.NoError(t, err)
require.NoError(t, err)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
assert.NoError(t, err)
require.NoError(t, err)
}

View file

@ -92,7 +92,7 @@ func TestNewDNSProvider(t *testing.T) {
})
_, err := NewDNSProvider()
assert.ErrorIs(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
})
}
@ -151,7 +151,7 @@ func TestNewDNSProviderConfig(t *testing.T) {
config.PrivateKeyPath = "./fixtures/non/existent/private.key"
_, err := NewDNSProviderConfig(config)
assert.ErrorIs(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
})
}

View file

@ -175,7 +175,6 @@ func TestLivePresent(t *testing.T) {
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)

View file

@ -21,7 +21,7 @@ func TestNewDNSProvider_Fail(t *testing.T) {
envTest.ClearEnv()
_, err := NewDNSProvider()
assert.Error(t, err, "VEGADNS_URL env missing")
require.Error(t, err, "VEGADNS_URL env missing")
}
func TestDNSProvider_TimeoutSuccess(t *testing.T) {
@ -34,8 +34,8 @@ func TestDNSProvider_TimeoutSuccess(t *testing.T) {
require.NoError(t, err)
timeout, interval := provider.Timeout()
assert.Equal(t, timeout, 12*time.Minute)
assert.Equal(t, interval, 1*time.Minute)
assert.Equal(t, 12*time.Minute, timeout)
assert.Equal(t, 1*time.Minute, interval)
}
func TestDNSProvider_Present(t *testing.T) {

View file

@ -2,6 +2,7 @@ package internal
import (
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"time"
@ -14,7 +15,7 @@ func authToken(userName string, wapiPass string) string {
func sha1string(txt string) string {
h := sha1.New()
_, _ = io.WriteString(h, txt)
return fmt.Sprintf("%x", h.Sum(nil))
return hex.EncodeToString(h.Sum(nil))
}
func czechHourString() string {

View file

@ -197,7 +197,7 @@ func (r *DNSProvider) getZones(ctx context.Context) ([]*ycdns.DnsZone, error) {
return nil, errors.New("unable to fetch dns zones")
}
return response.DnsZones, nil
return response.GetDnsZones(), nil
}
func (r *DNSProvider) upsertRecordSetData(ctx context.Context, zoneID, name, value string) error {
@ -223,7 +223,7 @@ func (r *DNSProvider) upsertRecordSetData(ctx context.Context, zoneID, name, val
var deletions []*ycdns.RecordSet
if exist != nil {
record.Data = append(record.Data, exist.Data...)
record.SetData(append(record.GetData(), exist.GetData()...))
deletions = append(deletions, exist)
}
@ -263,7 +263,7 @@ func (r *DNSProvider) removeRecordSetData(ctx context.Context, zoneID, name, val
var additions []*ycdns.RecordSet
if len(previousRecord.Data) > 1 {
if len(previousRecord.GetData()) > 1 {
// RecordSet is not empty we should update it
record := &ycdns.RecordSet{
Name: name,
@ -272,9 +272,9 @@ func (r *DNSProvider) removeRecordSetData(ctx context.Context, zoneID, name, val
Data: []string{},
}
for _, data := range previousRecord.Data {
for _, data := range previousRecord.GetData() {
if data != value {
record.Data = append(record.Data, data)
record.SetData(append(record.GetData(), data))
}
}
@ -309,13 +309,13 @@ func decodeCredentials(accountB64 string) (ycsdk.Credentials, error) {
}
func appendRecordSetData(record *ycdns.RecordSet, value string) bool {
for _, data := range record.Data {
for _, data := range record.GetData() {
if data == value {
return false
}
}
record.Data = append(record.Data, value)
record.SetData(append(record.GetData(), value))
return true
}

View file

@ -31,7 +31,7 @@ func loadMemcachedHosts() []string {
func TestNewMemcachedProviderEmpty(t *testing.T) {
emptyHosts := make([]string, 0)
_, err := NewMemcachedProvider(emptyHosts)
assert.EqualError(t, err, "no memcached hosts provided")
require.EqualError(t, err, "no memcached hosts provided")
}
func TestNewMemcachedProviderValid(t *testing.T) {

View file

@ -74,5 +74,5 @@ func TestLiveNewHTTPProvider(t *testing.T) {
cleanupResp, err := http.Get(chlgPath)
require.NoError(t, err)
assert.Equal(t, cleanupResp.StatusCode, 403)
assert.Equal(t, 403, cleanupResp.StatusCode)
}

View file

@ -9,6 +9,8 @@ import (
"github.com/go-acme/lego/v4/log"
)
const mailTo = "mailto:"
// Resource represents all important information about a registration
// of which the client needs to keep track itself.
// WARNING: will be removed in the future (acme.ExtendedAccount), https://github.com/go-acme/lego/issues/855.
@ -52,7 +54,7 @@ func (r *Registrar) Register(options RegisterOptions) (*Resource, error) {
if r.user.GetEmail() != "" {
log.Infof("acme: Registering account for %s", r.user.GetEmail())
accMsg.Contact = []string{"mailto:" + r.user.GetEmail()}
accMsg.Contact = []string{mailTo + r.user.GetEmail()}
}
account, err := r.core.Accounts.New(accMsg)
@ -76,7 +78,7 @@ func (r *Registrar) RegisterWithExternalAccountBinding(options RegisterEABOption
if r.user.GetEmail() != "" {
log.Infof("acme: Registering account for %s", r.user.GetEmail())
accMsg.Contact = []string{"mailto:" + r.user.GetEmail()}
accMsg.Contact = []string{mailTo + r.user.GetEmail()}
}
account, err := r.core.Accounts.NewEAB(accMsg, options.Kid, options.HmacEncoded)
@ -128,7 +130,7 @@ func (r *Registrar) UpdateRegistration(options RegisterOptions) (*Resource, erro
if r.user.GetEmail() != "" {
log.Infof("acme: Registering account for %s", r.user.GetEmail())
accMsg.Contact = []string{"mailto:" + r.user.GetEmail()}
accMsg.Contact = []string{mailTo + r.user.GetEmail()}
}
accountURL := r.user.GetRegistration().URI