forked from TrueCloudLab/lego
chore: update linter (#1524)
This commit is contained in:
parent
d2455c5f53
commit
2de6e0b0c8
31 changed files with 97 additions and 25 deletions
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(`[
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -213,6 +213,7 @@ func TestDNSProvider_Present(t *testing.T) {
|
|||
}`)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue