Просмотр исходного кода

fix(integration): keep secrets in request URLs out of error logs

HTTP client errors carry the full request URL, so the Telegram bot
token and the Discord, Slack and Cubox webhook or API URLs were logged
at warn or error level when a request failed. Keep only the scheme and
host of these URLs in errors, and drop the URL from the Discord and
Slack status errors.
Fred 4 часов назад
Родитель
Сommit
ba992dc843

+ 41 - 7
internal/http/client/client.go

@@ -12,6 +12,7 @@ import (
 	"io"
 	"io"
 	"net"
 	"net"
 	"net/http"
 	"net/http"
+	"net/url"
 	"time"
 	"time"
 
 
 	"miniflux.app/v2/internal/config"
 	"miniflux.app/v2/internal/config"
@@ -78,11 +79,12 @@ func NewClientWithOptions(opts Options) *http.Client {
 
 
 // requestBuilder builds and executes HTTP requests with the builder pattern.
 // requestBuilder builds and executes HTTP requests with the builder pattern.
 type requestBuilder struct {
 type requestBuilder struct {
-	err      error
-	endpoint string
-	method   string
-	body     io.Reader
-	headers  http.Header
+	err            error
+	endpoint       string
+	method         string
+	body           io.Reader
+	headers        http.Header
+	secretEndpoint bool
 }
 }
 
 
 // NewRequestBuilder creates a new request builder for the given endpoint.
 // NewRequestBuilder creates a new request builder for the given endpoint.
@@ -106,6 +108,13 @@ func (r *requestBuilder) WithHeader(key, value string) *requestBuilder {
 	return r
 	return r
 }
 }
 
 
+// WithSecretEndpoint keeps the path and query of the endpoint out of the
+// returned errors, for endpoints that embed a secret such as a webhook token.
+func (r *requestBuilder) WithSecretEndpoint() *requestBuilder {
+	r.secretEndpoint = true
+	return r
+}
+
 // WithJSON marshals payload as JSON, sets the body and Content-Type.
 // WithJSON marshals payload as JSON, sets the body and Content-Type.
 func (r *requestBuilder) WithJSON(payload any) *requestBuilder {
 func (r *requestBuilder) WithJSON(payload any) *requestBuilder {
 	requestBody, err := json.Marshal(payload)
 	requestBody, err := json.Marshal(payload)
@@ -142,7 +151,7 @@ func (r *requestBuilder) Do() (*http.Response, error) {
 	// Content-Length header and lets the client replay the body on redirects.
 	// Content-Length header and lets the client replay the body on redirects.
 	req, err := http.NewRequest(r.method, r.endpoint, r.body)
 	req, err := http.NewRequest(r.method, r.endpoint, r.body)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("unable to create request: %w", err)
+		return nil, fmt.Errorf("unable to create request: %w", r.redactURL(err))
 	}
 	}
 
 
 	for key, values := range r.headers {
 	for key, values := range r.headers {
@@ -160,8 +169,33 @@ func (r *requestBuilder) Do() (*http.Response, error) {
 
 
 	response, err := NewClientWithOptions(clientOptions).Do(req)
 	response, err := NewClientWithOptions(clientOptions).Do(req)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("unable to send request: %w", err)
+		return nil, fmt.Errorf("unable to send request: %w", r.redactURL(err))
 	}
 	}
 
 
 	return response, nil
 	return response, nil
 }
 }
+
+func (r *requestBuilder) redactURL(err error) error {
+	if r.secretEndpoint {
+		return RedactURLInError(err)
+	}
+	return err
+}
+
+// RedactURLInError hides the path and query of the URL carried by a
+// *url.Error in err, for requests whose URL embeds a secret such as a token.
+// Only the scheme and host are kept, which is enough to diagnose network
+// failures. The error is modified in place and returned.
+//
+// Call it before wrapping err: fmt.Errorf formats the message of the
+// wrapping error immediately, so a later change would not be reflected.
+func RedactURLInError(err error) error {
+	if urlErr, ok := errors.AsType[*url.Error](err); ok {
+		redactedURL := "xxxxx"
+		if parsedURL, parseErr := url.Parse(urlErr.URL); parseErr == nil && parsedURL.Host != "" {
+			redactedURL = parsedURL.Scheme + "://" + parsedURL.Host + "/xxxxx"
+		}
+		urlErr.URL = redactedURL
+	}
+	return err
+}

+ 97 - 0
internal/http/client/client_test.go

@@ -9,6 +9,8 @@ import (
 	"net"
 	"net"
 	"net/http"
 	"net/http"
 	"net/http/httptest"
 	"net/http/httptest"
+	"net/url"
+	"strings"
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
@@ -168,6 +170,101 @@ func TestRequestBuilderWithInvalidEndpoint(t *testing.T) {
 	}
 	}
 }
 }
 
 
+func TestRequestBuilderWithSecretEndpointRedactsErrors(t *testing.T) {
+	configureIntegrationAllowPrivateNetworksOption(t)
+
+	const secret = "secret-token"
+
+	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		connection, _, err := w.(http.Hijacker).Hijack()
+		if err != nil {
+			t.Errorf("unable to hijack connection: %v", err)
+			return
+		}
+		connection.Close()
+	}))
+	defer server.Close()
+
+	tests := []struct {
+		name            string
+		endpoint        string
+		wantErrContains string
+	}{
+		{
+			name:            "connection fails",
+			endpoint:        server.URL + "/webhooks/" + secret + "?token=" + secret,
+			wantErrContains: `unable to send request: Post "` + server.URL + `/xxxxx"`,
+		},
+		{
+			name:            "invalid endpoint",
+			endpoint:        server.URL + "/webhooks/" + secret + "\n",
+			wantErrContains: `unable to create request: parse "xxxxx"`,
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			response, err := NewRequestBuilder(tt.endpoint).
+				WithMethod(http.MethodPost).
+				WithSecretEndpoint().
+				Do()
+			if err == nil {
+				response.Body.Close()
+				t.Fatal("expected an error, got nil")
+			}
+
+			if strings.Contains(err.Error(), secret) {
+				t.Fatalf("expected the error to not contain the secret, got %q", err)
+			}
+
+			if !strings.Contains(err.Error(), tt.wantErrContains) {
+				t.Fatalf("expected the error to contain %q, got %q", tt.wantErrContains, err)
+			}
+		})
+	}
+}
+
+func TestRedactURLInError(t *testing.T) {
+	tests := []struct {
+		name string
+		err  error
+		want string
+	}{
+		{
+			name: "network error",
+			err:  &url.Error{Op: "Post", URL: "https://example.org/bot123:secret-token/sendMessage?key=secret-token", Err: io.ErrUnexpectedEOF},
+			want: `Post "https://example.org/xxxxx": unexpected EOF`,
+		},
+		{
+			name: "network error with userinfo and port",
+			err:  &url.Error{Op: "Get", URL: "https://user:password@example.org:8443/secret-token", Err: io.ErrUnexpectedEOF},
+			want: `Get "https://example.org:8443/xxxxx": unexpected EOF`,
+		},
+		{
+			name: "unparsable URL",
+			err:  &url.Error{Op: "parse", URL: "https://example.org/secret-token\n", Err: errors.New("net/url: invalid control character in URL")},
+			want: `parse "xxxxx": net/url: invalid control character in URL`,
+		},
+		{
+			name: "error without URL",
+			err:  io.ErrUnexpectedEOF,
+			want: "unexpected EOF",
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := RedactURLInError(tt.err).Error(); got != tt.want {
+				t.Fatalf("expected %q, got %q", tt.want, got)
+			}
+		})
+	}
+
+	if err := RedactURLInError(nil); err != nil {
+		t.Fatalf("expected nil, got %v", err)
+	}
+}
+
 func configureIntegrationAllowPrivateNetworksOption(t *testing.T) {
 func configureIntegrationAllowPrivateNetworksOption(t *testing.T) {
 	t.Helper()
 	t.Helper()
 
 

+ 1 - 0
internal/integration/cubox/cubox.go

@@ -28,6 +28,7 @@ func (c *Client) SaveLink(entryURL string) error {
 
 
 	response, err := client.NewRequestBuilder(c.apiLink).
 	response, err := client.NewRequestBuilder(c.apiLink).
 		WithMethod(http.MethodPost).
 		WithMethod(http.MethodPost).
+		WithSecretEndpoint().
 		WithJSON(&card{
 		WithJSON(&card{
 			Type:    "url",
 			Type:    "url",
 			Content: entryURL,
 			Content: entryURL,

+ 89 - 0
internal/integration/cubox/cubox_test.go

@@ -0,0 +1,89 @@
+// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+package cubox
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"strings"
+	"testing"
+
+	"miniflux.app/v2/internal/config"
+)
+
+func TestSaveLinkErrorsDoNotContainAPILink(t *testing.T) {
+	configureIntegrationAllowPrivateNetworksOption(t)
+
+	const secret = "0123456789abcdef"
+
+	closeConnection := func(t *testing.T, w http.ResponseWriter) {
+		connection, _, err := w.(http.Hijacker).Hijack()
+		if err != nil {
+			t.Errorf("unable to hijack connection: %v", err)
+			return
+		}
+		connection.Close()
+	}
+
+	tests := []struct {
+		name            string
+		handler         func(t *testing.T, w http.ResponseWriter)
+		wantErrContains string
+	}{
+		{
+			name: "connection fails",
+			handler: func(t *testing.T, w http.ResponseWriter) {
+				closeConnection(t, w)
+			},
+			wantErrContains: "cubox: unable to send request",
+		},
+		{
+			name: "error status",
+			handler: func(t *testing.T, w http.ResponseWriter) {
+				w.WriteHeader(http.StatusInternalServerError)
+			},
+			wantErrContains: "cubox: unable to save link: status=500",
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+				tt.handler(t, w)
+			}))
+			defer server.Close()
+
+			err := NewClient(server.URL + "/c/api/save/" + secret).SaveLink("https://example.org/entry")
+			if err == nil {
+				t.Fatal("expected an error, got nil")
+			}
+
+			if strings.Contains(err.Error(), secret) {
+				t.Fatalf("expected the error to not contain the secret, got %q", err)
+			}
+
+			if !strings.Contains(err.Error(), tt.wantErrContains) {
+				t.Fatalf("expected the error to contain %q, got %q", tt.wantErrContains, err)
+			}
+		})
+	}
+}
+
+func configureIntegrationAllowPrivateNetworksOption(t *testing.T) {
+	t.Helper()
+
+	t.Setenv("INTEGRATION_ALLOW_PRIVATE_NETWORKS", "1")
+
+	configParser := config.NewConfigParser()
+	parsedOptions, err := configParser.ParseEnvironmentVariables()
+	if err != nil {
+		t.Fatalf("Unable to configure test options: %v", err)
+	}
+
+	previousOptions := config.Opts
+	config.Opts = parsedOptions
+	t.Cleanup(func() {
+		config.Opts = previousOptions
+	})
+}

+ 2 - 1
internal/integration/discord/discord.go

@@ -35,6 +35,7 @@ func (c *Client) SendDiscordMsg(feed *model.Feed, entries model.Entries) error {
 
 
 		response, err := client.NewRequestBuilder(c.webhookURL).
 		response, err := client.NewRequestBuilder(c.webhookURL).
 			WithMethod(http.MethodPost).
 			WithMethod(http.MethodPost).
+			WithSecretEndpoint().
 			WithJSON(&discordMessage{
 			WithJSON(&discordMessage{
 				Embeds: []discordEmbed{
 				Embeds: []discordEmbed{
 					{
 					{
@@ -70,7 +71,7 @@ func (c *Client) SendDiscordMsg(feed *model.Feed, entries model.Entries) error {
 		response.Body.Close()
 		response.Body.Close()
 
 
 		if response.StatusCode >= 400 {
 		if response.StatusCode >= 400 {
-			return fmt.Errorf("discord: unable to send a notification: url=%s status=%d", c.webhookURL, response.StatusCode)
+			return fmt.Errorf("discord: unable to send a notification: status=%d", response.StatusCode)
 		}
 		}
 	}
 	}
 
 

+ 93 - 0
internal/integration/discord/discord_test.go

@@ -0,0 +1,93 @@
+// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+package discord
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"strings"
+	"testing"
+
+	"miniflux.app/v2/internal/config"
+	"miniflux.app/v2/internal/model"
+)
+
+func TestSendDiscordMsgErrorsDoNotContainWebhookURL(t *testing.T) {
+	configureIntegrationAllowPrivateNetworksOption(t)
+
+	const secret = "api/webhooks/123/0123456789abcdef"
+
+	closeConnection := func(t *testing.T, w http.ResponseWriter) {
+		connection, _, err := w.(http.Hijacker).Hijack()
+		if err != nil {
+			t.Errorf("unable to hijack connection: %v", err)
+			return
+		}
+		connection.Close()
+	}
+
+	tests := []struct {
+		name            string
+		handler         func(t *testing.T, w http.ResponseWriter)
+		wantErrContains string
+	}{
+		{
+			name: "connection fails",
+			handler: func(t *testing.T, w http.ResponseWriter) {
+				closeConnection(t, w)
+			},
+			wantErrContains: "discord: unable to send request",
+		},
+		{
+			name: "error status",
+			handler: func(t *testing.T, w http.ResponseWriter) {
+				w.WriteHeader(http.StatusInternalServerError)
+			},
+			wantErrContains: "discord: unable to send a notification: status=500",
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+				tt.handler(t, w)
+			}))
+			defer server.Close()
+
+			feed := &model.Feed{ID: 1, Title: "Feed", SiteURL: "https://example.org/"}
+			entries := model.Entries{&model.Entry{ID: 1, Title: "Entry", URL: "https://example.org/entry"}}
+
+			err := NewClient(server.URL+"/"+secret).SendDiscordMsg(feed, entries)
+			if err == nil {
+				t.Fatal("expected an error, got nil")
+			}
+
+			if strings.Contains(err.Error(), secret) {
+				t.Fatalf("expected the error to not contain the secret, got %q", err)
+			}
+
+			if !strings.Contains(err.Error(), tt.wantErrContains) {
+				t.Fatalf("expected the error to contain %q, got %q", tt.wantErrContains, err)
+			}
+		})
+	}
+}
+
+func configureIntegrationAllowPrivateNetworksOption(t *testing.T) {
+	t.Helper()
+
+	t.Setenv("INTEGRATION_ALLOW_PRIVATE_NETWORKS", "1")
+
+	configParser := config.NewConfigParser()
+	parsedOptions, err := configParser.ParseEnvironmentVariables()
+	if err != nil {
+		t.Fatalf("Unable to configure test options: %v", err)
+	}
+
+	previousOptions := config.Opts
+	config.Opts = parsedOptions
+	t.Cleanup(func() {
+		config.Opts = previousOptions
+	})
+}

+ 2 - 1
internal/integration/slack/slack.go

@@ -35,6 +35,7 @@ func (c *Client) SendSlackMsg(feed *model.Feed, entries model.Entries) error {
 
 
 		response, err := client.NewRequestBuilder(c.webhookURL).
 		response, err := client.NewRequestBuilder(c.webhookURL).
 			WithMethod(http.MethodPost).
 			WithMethod(http.MethodPost).
+			WithSecretEndpoint().
 			WithJSON(&slackMessage{
 			WithJSON(&slackMessage{
 				Attachments: []slackAttachments{
 				Attachments: []slackAttachments{
 					{
 					{
@@ -74,7 +75,7 @@ func (c *Client) SendSlackMsg(feed *model.Feed, entries model.Entries) error {
 		response.Body.Close()
 		response.Body.Close()
 
 
 		if response.StatusCode >= 400 {
 		if response.StatusCode >= 400 {
-			return fmt.Errorf("slack: unable to send a notification: url=%s status=%d", c.webhookURL, response.StatusCode)
+			return fmt.Errorf("slack: unable to send a notification: status=%d", response.StatusCode)
 		}
 		}
 	}
 	}
 
 

+ 93 - 0
internal/integration/slack/slack_test.go

@@ -0,0 +1,93 @@
+// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+package slack
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"strings"
+	"testing"
+
+	"miniflux.app/v2/internal/config"
+	"miniflux.app/v2/internal/model"
+)
+
+func TestSendSlackMsgErrorsDoNotContainWebhookURL(t *testing.T) {
+	configureIntegrationAllowPrivateNetworksOption(t)
+
+	const secret = "services/T000/B000/0123456789abcdef"
+
+	closeConnection := func(t *testing.T, w http.ResponseWriter) {
+		connection, _, err := w.(http.Hijacker).Hijack()
+		if err != nil {
+			t.Errorf("unable to hijack connection: %v", err)
+			return
+		}
+		connection.Close()
+	}
+
+	tests := []struct {
+		name            string
+		handler         func(t *testing.T, w http.ResponseWriter)
+		wantErrContains string
+	}{
+		{
+			name: "connection fails",
+			handler: func(t *testing.T, w http.ResponseWriter) {
+				closeConnection(t, w)
+			},
+			wantErrContains: "slack: unable to send request",
+		},
+		{
+			name: "error status",
+			handler: func(t *testing.T, w http.ResponseWriter) {
+				w.WriteHeader(http.StatusInternalServerError)
+			},
+			wantErrContains: "slack: unable to send a notification: status=500",
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+				tt.handler(t, w)
+			}))
+			defer server.Close()
+
+			feed := &model.Feed{ID: 1, Title: "Feed", SiteURL: "https://example.org/"}
+			entries := model.Entries{&model.Entry{ID: 1, Title: "Entry", URL: "https://example.org/entry"}}
+
+			err := NewClient(server.URL+"/"+secret).SendSlackMsg(feed, entries)
+			if err == nil {
+				t.Fatal("expected an error, got nil")
+			}
+
+			if strings.Contains(err.Error(), secret) {
+				t.Fatalf("expected the error to not contain the secret, got %q", err)
+			}
+
+			if !strings.Contains(err.Error(), tt.wantErrContains) {
+				t.Fatalf("expected the error to contain %q, got %q", tt.wantErrContains, err)
+			}
+		})
+	}
+}
+
+func configureIntegrationAllowPrivateNetworksOption(t *testing.T) {
+	t.Helper()
+
+	t.Setenv("INTEGRATION_ALLOW_PRIVATE_NETWORKS", "1")
+
+	configParser := config.NewConfigParser()
+	parsedOptions, err := configParser.ParseEnvironmentVariables()
+	if err != nil {
+		t.Fatalf("Unable to configure test options: %v", err)
+	}
+
+	previousOptions := config.Opts
+	config.Opts = parsedOptions
+	t.Cleanup(func() {
+		config.Opts = previousOptions
+	})
+}

+ 10 - 8
internal/integration/telegrambot/client.go

@@ -25,20 +25,22 @@ const (
 )
 )
 
 
 type Client struct {
 type Client struct {
-	botToken string
-	chatID   string
+	apiEndpoint string
+	botToken    string
+	chatID      string
 }
 }
 
 
 func NewClient(botToken, chatID string) *Client {
 func NewClient(botToken, chatID string) *Client {
 	return &Client{
 	return &Client{
-		botToken: botToken,
-		chatID:   chatID,
+		apiEndpoint: telegramAPIEndpoint,
+		botToken:    botToken,
+		chatID:      chatID,
 	}
 	}
 }
 }
 
 
 // Specs: https://core.telegram.org/bots/api#getme
 // Specs: https://core.telegram.org/bots/api#getme
 func (c *Client) GetMe() (*User, error) {
 func (c *Client) GetMe() (*User, error) {
-	endpointURL, err := url.JoinPath(telegramAPIEndpoint, "/bot"+c.botToken, "/getMe")
+	endpointURL, err := url.JoinPath(c.apiEndpoint, "/bot"+c.botToken, "/getMe")
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("telegram: unable to join base URL and path: %w", err)
 		return nil, fmt.Errorf("telegram: unable to join base URL and path: %w", err)
 	}
 	}
@@ -54,7 +56,7 @@ func (c *Client) GetMe() (*User, error) {
 	httpClient := client.NewClientWithOptions(client.Options{Timeout: defaultClientTimeout})
 	httpClient := client.NewClientWithOptions(client.Options{Timeout: defaultClientTimeout})
 	response, err := httpClient.Do(request)
 	response, err := httpClient.Do(request)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("telegram: unable to send request: %v", err)
+		return nil, fmt.Errorf("telegram: unable to send request: %v", client.RedactURLInError(err))
 	}
 	}
 	defer response.Body.Close()
 	defer response.Body.Close()
 
 
@@ -72,7 +74,7 @@ func (c *Client) GetMe() (*User, error) {
 
 
 // Specs: https://core.telegram.org/bots/api#sendmessage
 // Specs: https://core.telegram.org/bots/api#sendmessage
 func (c *Client) SendMessage(message *MessageRequest) (*Message, error) {
 func (c *Client) SendMessage(message *MessageRequest) (*Message, error) {
-	endpointURL, err := url.JoinPath(telegramAPIEndpoint, "/bot"+c.botToken, "/sendMessage")
+	endpointURL, err := url.JoinPath(c.apiEndpoint, "/bot"+c.botToken, "/sendMessage")
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("telegram: unable to join base URL and path: %w", err)
 		return nil, fmt.Errorf("telegram: unable to join base URL and path: %w", err)
 	}
 	}
@@ -94,7 +96,7 @@ func (c *Client) SendMessage(message *MessageRequest) (*Message, error) {
 	httpClient := client.NewClientWithOptions(client.Options{Timeout: defaultClientTimeout})
 	httpClient := client.NewClientWithOptions(client.Options{Timeout: defaultClientTimeout})
 	response, err := httpClient.Do(request)
 	response, err := httpClient.Do(request)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("telegram: unable to send request: %v", err)
+		return nil, fmt.Errorf("telegram: unable to send request: %v", client.RedactURLInError(err))
 	}
 	}
 	defer response.Body.Close()
 	defer response.Body.Close()
 
 

+ 65 - 0
internal/integration/telegrambot/client_test.go

@@ -0,0 +1,65 @@
+// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+package telegrambot
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"strings"
+	"testing"
+)
+
+func TestRequestErrorsDoNotContainBotToken(t *testing.T) {
+	const secret = "123456:ABC-DEF1234ghIkl"
+
+	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		connection, _, err := w.(http.Hijacker).Hijack()
+		if err != nil {
+			t.Errorf("unable to hijack connection: %v", err)
+			return
+		}
+		connection.Close()
+	}))
+	defer server.Close()
+
+	client := NewClient(secret, "-100123")
+	client.apiEndpoint = server.URL
+
+	tests := []struct {
+		name string
+		call func() error
+	}{
+		{
+			name: "getMe",
+			call: func() error {
+				_, err := client.GetMe()
+				return err
+			},
+		},
+		{
+			name: "sendMessage",
+			call: func() error {
+				_, err := client.SendMessage(&MessageRequest{ChatID: "-100123", Text: "Entry"})
+				return err
+			},
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			err := tt.call()
+			if err == nil {
+				t.Fatal("expected an error, got nil")
+			}
+
+			if strings.Contains(err.Error(), secret) {
+				t.Fatalf("expected the error to not contain the bot token, got %q", err)
+			}
+
+			if want := "telegram: unable to send request"; !strings.Contains(err.Error(), want) {
+				t.Fatalf("expected the error to contain %q, got %q", want, err)
+			}
+		})
+	}
+}