todoist: replace deprecated verification endpoint (#4828)

This commit is contained in:
Arun Kumar Rai
2026-04-01 10:41:21 +05:00
committed by GitHub
parent bfaa370c78
commit 03acc788f8
2 changed files with 53 additions and 1 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
if verify {
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.todoist.com/rest/v2/projects", nil)
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.todoist.com/api/v1/projects", nil)
if err != nil {
continue
}
+52
View File
@@ -3,6 +3,9 @@ package todoist
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
@@ -11,6 +14,12 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/engine/ahocorasick"
)
type roundTripFunc func(*http.Request) (*http.Response, error)
func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return f(req)
}
var (
validPattern = "qpgv7z8amkp4ln55znaacezm9jy35wcayy6bya2r"
invalidPattern = "qpgv7z8amkp4ln55znaa?ezm9jy35wcayy6bya2r"
@@ -89,3 +98,46 @@ func TestTodoist_Pattern(t *testing.T) {
})
}
}
func TestTodoist_VerificationEndpoint(t *testing.T) {
d := Scanner{}
input := fmt.Sprintf("%s token = '%s'", keyword, validPattern)
prevClient := client
t.Cleanup(func() {
client = prevClient
})
called := false
client = &http.Client{
Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
called = true
if req.URL.String() != "https://api.todoist.com/api/v1/projects" {
t.Fatalf("unexpected verification URL: %s", req.URL.String())
}
if req.Header.Get("Authorization") == "" {
t.Fatal("missing Authorization header")
}
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader("{}")),
Header: make(http.Header),
}, nil
}),
}
results, err := d.FromData(context.Background(), true, []byte(input))
if err != nil {
t.Fatalf("FromData returned error: %v", err)
}
if !called {
t.Fatal("verification HTTP request was not made")
}
if len(results) != 1 {
t.Fatalf("expected 1 result, got %d", len(results))
}
if !results[0].Verified {
t.Fatal("expected result to be verified")
}
}