From e152ce9ae7d034a04369228f540af590b39271b1 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 5 Sep 2023 18:12:26 +0100 Subject: [PATCH] Make checkRequest only accept a token After all, we're only going to make a request using a token. --- tests-integration/poller_test.go | 6 +++--- tests-integration/token_management_test.go | 10 ++-------- tests-integration/v3_test.go | 6 +++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/tests-integration/poller_test.go b/tests-integration/poller_test.go index 6e02c1f..b26d99c 100644 --- a/tests-integration/poller_test.go +++ b/tests-integration/poller_test.go @@ -44,14 +44,14 @@ func TestSecondPollerFiltersToDevice(t *testing.T) { deviceBToken := "DEVICE_B_TOKEN" v2.addAccountWithDeviceID(alice, "B", deviceBToken) seenInitialRequest := false - v2.SetCheckRequest(func(userID, token string, req *http.Request) { - if userID != alice || token != deviceBToken { + v2.SetCheckRequest(func(token string, req *http.Request) { + if token != deviceBToken { return } qps := req.URL.Query() since := qps.Get("since") filter := qps.Get("filter") - t.Logf("CheckRequest: %v %v since=%v filter=%v", userID, token, since, filter) + t.Logf("CheckRequest: %v since=%v filter=%v", token, since, filter) if filter == "" { t.Errorf("expected a filter on all v2 syncs from poller, but got none") return diff --git a/tests-integration/token_management_test.go b/tests-integration/token_management_test.go index 831a6ec..7346965 100644 --- a/tests-integration/token_management_test.go +++ b/tests-integration/token_management_test.go @@ -54,10 +54,7 @@ func TestSyncWithNewTokenAfterOldExpires(t *testing.T) { ) t.Log("From this point forward, the poller should not make any initial sync requests.") - v2.SetCheckRequest(func(userID, token string, req *http.Request) { - if userID != alice { - t.Errorf("Got unexpected poll for %s, expected %s only", userID, alice) - } + v2.SetCheckRequest(func(token string, req *http.Request) { switch token { case aliceToken1: // this is okay; we should return a token expiry response case aliceToken2: // this is also okay; we should provide a proper response @@ -149,10 +146,7 @@ func TestSyncWithNewTokenBeforeOldExpires(t *testing.T) { ) t.Log("From this point forward, the poller should not make any initial sync requests.") - v2.SetCheckRequest(func(userID, token string, req *http.Request) { - if userID != alice { - t.Errorf("Got unexpected poll for %s, expected %s only", userID, alice) - } + v2.SetCheckRequest(func(token string, req *http.Request) { switch token { case aliceToken1: // either is okay case aliceToken2: diff --git a/tests-integration/v3_test.go b/tests-integration/v3_test.go index 210c12a..d5f9f89 100644 --- a/tests-integration/v3_test.go +++ b/tests-integration/v3_test.go @@ -54,7 +54,7 @@ type testV2Server struct { // received from pollers, but before the response is generated. This allows us to // confirm that the proxy is polling the homeserver's v2 sync endpoint in the // manner that we expect. - checkRequest func(userID, token string, req *http.Request) + checkRequest func(token string, req *http.Request) mu *sync.Mutex tokenToUser map[string]string tokenToDevice map[string]string @@ -65,7 +65,7 @@ type testV2Server struct { timeToWaitForV2Response time.Duration } -func (s *testV2Server) SetCheckRequest(fn func(userID, token string, req *http.Request)) { +func (s *testV2Server) SetCheckRequest(fn func(token string, req *http.Request)) { s.mu.Lock() defer s.mu.Unlock() s.checkRequest = fn @@ -268,7 +268,7 @@ func runTestV2Server(t testutils.TestBenchInterface) *testV2Server { check := server.checkRequest server.mu.Unlock() if check != nil { - check(userID, token, req) + check(token, req) } resp := server.nextResponse(userID, token) body, err := json.Marshal(resp)