Make checkRequest only accept a token

After all, we're only going to make a request using a token.
This commit is contained in:
David Robertson 2023-09-05 18:12:26 +01:00
parent 8e9bb4f842
commit e152ce9ae7
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
3 changed files with 8 additions and 14 deletions

View File

@ -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

View File

@ -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:

View File

@ -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)