Skip to content

Commit

Permalink
cleanup(probeservices): short-circuit check_report_id
Browse files Browse the repository at this point in the history
Originally included in #997.

Reference issue: ooni/probe#2380.
  • Loading branch information
bassosimone committed Dec 14, 2022
1 parent 8df1173 commit 3f7ee48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 45 deletions.
28 changes: 8 additions & 20 deletions internal/engine/probeservices/checkreportid.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
package probeservices

import (
"context"
"net/url"

"github.com/ooni/probe-cli/v3/internal/httpx"
"github.com/ooni/probe-cli/v3/internal/model"
)
import "context"

// CheckReportID checks whether the given ReportID exists.
func (c Client) CheckReportID(ctx context.Context, reportID string) (bool, error) {
query := url.Values{}
query.Add("report_id", reportID)
var response model.OOAPICheckReportIDResponse
err := (&httpx.APIClientTemplate{
BaseURL: c.BaseURL,
HTTPClient: c.HTTPClient,
Logger: c.Logger,
UserAgent: c.UserAgent,
}).WithBodyLogging().Build().GetJSONWithQuery(ctx, "/api/_/check_report_id", query, &response)
if err != nil {
return false, err
}
return response.Found, nil
// The API has been returning true for some time now. So, it does not make
// sense for us to actually issue the API call. Let's short circuit it.
//
// See https://github.com/ooni/api/blob/80913ffd446e7a46761c4c8fdf3e42174f0ce645/newapi/ooniapi/private.py#L208
//
// TODO(https://github.com/ooni/probe/issues/2389): remove this code.
return true, nil
}
25 changes: 0 additions & 25 deletions internal/engine/probeservices/checkreportid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package probeservices

import (
"context"
"errors"
"net/http"
"testing"

Expand Down Expand Up @@ -37,27 +36,3 @@ func TestCheckReportIDWorkingAsIntended(t *testing.T) {
t.Fatal("unexpected found value")
}
}

func TestCheckReportIDWorkingWithCancelledContext(t *testing.T) {
client := Client{
APIClientTemplate: httpx.APIClientTemplate{
BaseURL: "https://api.ooni.io/",
HTTPClient: http.DefaultClient,
Logger: log.Log,
UserAgent: "miniooni/0.1.0-dev",
},
LoginCalls: &atomicx.Int64{},
RegisterCalls: &atomicx.Int64{},
StateFile: NewStateFile(&kvstore.Memory{}),
}
reportID := `20201209T052225Z_urlgetter_IT_30722_n1_E1VUhMz08SEkgYFU`
ctx, cancel := context.WithCancel(context.Background())
cancel() // fail immediately
found, err := client.CheckReportID(ctx, reportID)
if !errors.Is(err, context.Canceled) {
t.Fatalf("not the error we expected: %+v", err)
}
if found != false {
t.Fatal("unexpected found value")
}
}

0 comments on commit 3f7ee48

Please sign in to comment.