mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Make checkRequest only accept a token
After all, we're only going to make a request using a token.
This commit is contained in:
parent
8e9bb4f842
commit
e152ce9ae7
@ -44,14 +44,14 @@ func TestSecondPollerFiltersToDevice(t *testing.T) {
|
|||||||
deviceBToken := "DEVICE_B_TOKEN"
|
deviceBToken := "DEVICE_B_TOKEN"
|
||||||
v2.addAccountWithDeviceID(alice, "B", deviceBToken)
|
v2.addAccountWithDeviceID(alice, "B", deviceBToken)
|
||||||
seenInitialRequest := false
|
seenInitialRequest := false
|
||||||
v2.SetCheckRequest(func(userID, token string, req *http.Request) {
|
v2.SetCheckRequest(func(token string, req *http.Request) {
|
||||||
if userID != alice || token != deviceBToken {
|
if token != deviceBToken {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
qps := req.URL.Query()
|
qps := req.URL.Query()
|
||||||
since := qps.Get("since")
|
since := qps.Get("since")
|
||||||
filter := qps.Get("filter")
|
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 == "" {
|
if filter == "" {
|
||||||
t.Errorf("expected a filter on all v2 syncs from poller, but got none")
|
t.Errorf("expected a filter on all v2 syncs from poller, but got none")
|
||||||
return
|
return
|
||||||
|
@ -54,10 +54,7 @@ func TestSyncWithNewTokenAfterOldExpires(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
t.Log("From this point forward, the poller should not make any initial sync requests.")
|
t.Log("From this point forward, the poller should not make any initial sync requests.")
|
||||||
v2.SetCheckRequest(func(userID, token string, req *http.Request) {
|
v2.SetCheckRequest(func(token string, req *http.Request) {
|
||||||
if userID != alice {
|
|
||||||
t.Errorf("Got unexpected poll for %s, expected %s only", userID, alice)
|
|
||||||
}
|
|
||||||
switch token {
|
switch token {
|
||||||
case aliceToken1: // this is okay; we should return a token expiry response
|
case aliceToken1: // this is okay; we should return a token expiry response
|
||||||
case aliceToken2: // this is also okay; we should provide a proper 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.")
|
t.Log("From this point forward, the poller should not make any initial sync requests.")
|
||||||
v2.SetCheckRequest(func(userID, token string, req *http.Request) {
|
v2.SetCheckRequest(func(token string, req *http.Request) {
|
||||||
if userID != alice {
|
|
||||||
t.Errorf("Got unexpected poll for %s, expected %s only", userID, alice)
|
|
||||||
}
|
|
||||||
switch token {
|
switch token {
|
||||||
case aliceToken1: // either is okay
|
case aliceToken1: // either is okay
|
||||||
case aliceToken2:
|
case aliceToken2:
|
||||||
|
@ -54,7 +54,7 @@ type testV2Server struct {
|
|||||||
// received from pollers, but before the response is generated. This allows us to
|
// 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
|
// confirm that the proxy is polling the homeserver's v2 sync endpoint in the
|
||||||
// manner that we expect.
|
// manner that we expect.
|
||||||
checkRequest func(userID, token string, req *http.Request)
|
checkRequest func(token string, req *http.Request)
|
||||||
mu *sync.Mutex
|
mu *sync.Mutex
|
||||||
tokenToUser map[string]string
|
tokenToUser map[string]string
|
||||||
tokenToDevice map[string]string
|
tokenToDevice map[string]string
|
||||||
@ -65,7 +65,7 @@ type testV2Server struct {
|
|||||||
timeToWaitForV2Response time.Duration
|
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()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.checkRequest = fn
|
s.checkRequest = fn
|
||||||
@ -268,7 +268,7 @@ func runTestV2Server(t testutils.TestBenchInterface) *testV2Server {
|
|||||||
check := server.checkRequest
|
check := server.checkRequest
|
||||||
server.mu.Unlock()
|
server.mu.Unlock()
|
||||||
if check != nil {
|
if check != nil {
|
||||||
check(userID, token, req)
|
check(token, req)
|
||||||
}
|
}
|
||||||
resp := server.nextResponse(userID, token)
|
resp := server.nextResponse(userID, token)
|
||||||
body, err := json.Marshal(resp)
|
body, err := json.Marshal(resp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user