Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for passing through unsigned data in /keys/query #749

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ jobs:
- homeserver: Synapse
repo: element-hq/synapse
tags: synapse_blacklist
packages: ./tests/msc3874 ./tests/msc3902
packages: >-
./tests/msc3874
./tests/msc3902
./tests/msc4229
env: "COMPLEMENT_ENABLE_DIRTY_RUNS=1 COMPLEMENT_SHARE_ENV_PREFIX=PASS_ PASS_SYNAPSE_COMPLEMENT_DATABASE=sqlite"
timeout: 20m

Expand Down
11 changes: 11 additions & 0 deletions tests/msc4229/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tests

import (
"testing"

"github.com/matrix-org/complement"
)

func TestMain(m *testing.M) {
complement.TestMain(m, "msc4229")
}
63 changes: 63 additions & 0 deletions tests/msc4229/msc4229_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package tests

import (
"fmt"
"github.com/matrix-org/complement"
"testing"

"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
)

// Create two homeservers, one of which has a user that uploads device-keys data with
// "unsigned" data.
//
// Check that users on both servers see the unsigned data.
func TestUnsignedDeviceDataIsReturned(t *testing.T) {
deployment := complement.Deploy(t, 2)
defer deployment.Destroy(t)
hs1user := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
hs2user := deployment.Register(t, "hs2", helpers.RegistrationOpts{})

hs1userDeviceKeys, _ := hs1user.MustGenerateOneTimeKeys(t, 0)
hs1userDeviceKeys["unsigned"] = map[string]interface{}{"a": "b"}
hs1user.MustUploadKeys(t, hs1userDeviceKeys, nil)

// Have each user request the keys, and check the unsigned data is there
for _, user := range []*client.CSAPI{hs1user, hs2user} {
res := user.MustDo(t, "POST", []string{"_matrix", "client", "v3", "keys", "query"},
client.WithJSONBody(t, map[string]any{"device_keys": map[string]any{hs1user.UserID: []string{}}}),
)
must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyPresent(fmt.Sprintf(
"device_keys.%s.%s", hs1user.UserID, hs1user.DeviceID,
)),
match.JSONKeyEqual(fmt.Sprintf(
"device_keys.%s.%s.unsigned", hs1user.UserID, hs1user.DeviceID,
), map[string]interface{}{"a": "b"}),
},
})
}

// If a displayname is set, that is added tp the unsigned data, for the local user's query only
hs1user.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "devices", hs1user.DeviceID},
client.WithJSONBody(t, map[string]any{"display_name": "complement"}),
)

res := hs1user.MustDo(t, "POST", []string{"_matrix", "client", "v3", "keys", "query"},
client.WithJSONBody(t, map[string]any{"device_keys": map[string]any{hs1user.UserID: []string{}}}),
)
must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyPresent(fmt.Sprintf(
"device_keys.%s.%s", hs1user.UserID, hs1user.DeviceID,
)),
match.JSONKeyEqual(fmt.Sprintf(
"device_keys.%s.%s.unsigned", hs1user.UserID, hs1user.DeviceID,
), map[string]interface{}{"a": "b", "device_display_name": "complement"}),
},
})
}
Loading