Skip to content

Commit 374ce2c

Browse files
committed
Only block bob's /keys/query, not alices
1 parent b3d87c1 commit 374ce2c

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

internal/api/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type Client interface {
6565
Logf(t ct.TestLike, format string, args ...interface{})
6666
// The user for this client
6767
UserID() string
68+
// The current access token for this client
69+
CurrentAccessToken(t ct.TestLike) string
6870
Type() ClientTypeLang
6971
Opts() ClientCreationOpts
7072
}
@@ -78,6 +80,13 @@ type LoggedClient struct {
7880
Client
7981
}
8082

83+
func (c *LoggedClient) CurrentAccessToken(t ct.TestLike) string {
84+
t.Helper()
85+
token := c.Client.CurrentAccessToken(t)
86+
c.Logf(t, "%s CurrentAccessToken => %s", c.logPrefix(), token)
87+
return token
88+
}
89+
8190
func (c *LoggedClient) Login(t ct.TestLike, opts ClientCreationOpts) error {
8291
t.Helper()
8392
c.Logf(t, "%s Login %+v", c.logPrefix(), opts)

internal/api/js/js.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ func (c *JSClient) DeletePersistentStorage(t ct.TestLike) {
251251
`, indexedDBName, indexedDBCryptoName))
252252
}
253253

254+
func (c *JSClient) CurrentAccessToken(t ct.TestLike) string {
255+
token := chrome.MustRunAsyncFn[string](t, c.browser.Ctx, `
256+
return window.__client.getAccessToken();`)
257+
return *token
258+
}
259+
254260
func (c *JSClient) GetNotification(t ct.TestLike, roomID, eventID string) (*api.Notification, error) {
255261
return nil, fmt.Errorf("not implemented yet") // TODO
256262
}

internal/api/rust/rust.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ func (c *RustClient) Login(t ct.TestLike, opts api.ClientCreationOpts) error {
188188
return nil
189189
}
190190

191+
func (c *RustClient) CurrentAccessToken(t ct.TestLike) string {
192+
s, err := c.FFIClient.Session()
193+
if err != nil {
194+
ct.Fatalf(t, "error retrieving session: %s", err)
195+
}
196+
return s.AccessToken
197+
}
198+
191199
func (c *RustClient) DeletePersistentStorage(t ct.TestLike) {
192200
t.Helper()
193201
if c.persistentStoragePath != "" {

internal/deploy/rpc_client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ func (c *RPCClient) GetNotification(t ct.TestLike, roomID, eventID string) (*api
181181
return &notification, err
182182
}
183183

184+
func (c *RPCClient) CurrentAccessToken(t ct.TestLike) string {
185+
var token string
186+
err := c.client.Call("RPCServer.CurrentAccessToken", t.Name(), &token)
187+
if err != nil {
188+
ct.Fatalf(t, "RPCServer.CurrentAccessToken: %s", err)
189+
}
190+
return token
191+
}
192+
184193
// Remove any persistent storage, if it was enabled.
185194
func (c *RPCClient) DeletePersistentStorage(t ct.TestLike) {
186195
var void int

internal/deploy/rpc_server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ func (s *RPCServer) DeletePersistentStorage(testName string, void *int) error {
100100
return nil
101101
}
102102

103+
func (s *RPCServer) CurrentAccessToken(testName string, token *string) error {
104+
defer s.keepAlive()
105+
*token = s.activeClient.CurrentAccessToken(&api.MockT{TestName: testName})
106+
return nil
107+
}
108+
103109
func (s *RPCServer) Login(opts api.ClientCreationOpts, void *int) error {
104110
defer s.keepAlive()
105111
return s.activeClient.Login(&api.MockT{}, opts)

tests/to_device_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,14 @@ func TestToDeviceMessagesArentLostWhenKeysQueryFails(t *testing.T) {
345345
})
346346
defer closeCallbackServer()
347347
var eventID string
348+
bobAccessToken := bob.CurrentAccessToken(t)
349+
t.Logf("Bob's token => %s", bobAccessToken)
348350
tc.Deployment.WithMITMOptions(t, map[string]interface{}{
349351
"statuscode": map[string]interface{}{
350352
"return_status": http.StatusGatewayTimeout,
351353
"block_request": true,
352354
"count": 3,
353-
"filter": "~u .*/keys/query.*",
355+
"filter": "~u .*/keys/query.* ~hq " + bobAccessToken,
354356
},
355357
"callback": map[string]interface{}{
356358
"callback_url": callbackURL,

0 commit comments

Comments
 (0)