Skip to content

Commit

Permalink
Make checkRequest only accept a token
Browse files Browse the repository at this point in the history
After all, we're only going to make a request using a token.
  • Loading branch information
David Robertson committed Sep 5, 2023
1 parent 8e9bb4f commit e152ce9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tests-integration/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions tests-integration/token_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests-integration/v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e152ce9

Please sign in to comment.