* Remove Deployment.Client and change Deploy - `Deployment.Client` was used to get pre-registered clients. Now we want tests to register new users for each test, for dirty runs. So swap for `Deployment.Register` everywhere. - `Deploy` was used to deploy a blueprint. We don't want this to enable dirty runs. So replace it with the number of servers you need e.g `Deploy(t, 2)`. * Fix up more broken refactoring * unbreak tests; make user localpart look nicer * Alice and bob must share a room for presence * Fix user directory test * Fix race condition caused by making the room later than before
208 lines
6.6 KiB
Go
208 lines
6.6 KiB
Go
package csapi_tests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/matrix-org/complement"
|
|
"github.com/matrix-org/complement/b"
|
|
"github.com/matrix-org/complement/client"
|
|
"github.com/matrix-org/complement/helpers"
|
|
"github.com/matrix-org/complement/match"
|
|
"github.com/matrix-org/complement/must"
|
|
)
|
|
|
|
func TestRoomCreate(t *testing.T) {
|
|
deployment := complement.Deploy(t, 1)
|
|
defer deployment.Destroy(t)
|
|
|
|
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
|
|
bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
|
|
|
|
t.Run("Parallel", func(t *testing.T) {
|
|
// sytest: POST /createRoom makes a public room
|
|
t.Run("POST /createRoom makes a public room", func(t *testing.T) {
|
|
t.Parallel()
|
|
roomAlias := "30-room-create-alias-random"
|
|
|
|
res := alice.CreateRoom(t, map[string]interface{}{
|
|
"visibility": "public",
|
|
"room_alias_name": roomAlias,
|
|
})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 200,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyTypeEqual("room_id", gjson.String),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom makes a private room
|
|
t.Run("POST /createRoom makes a private room", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
res := alice.CreateRoom(t, map[string]interface{}{
|
|
"visibility": "private",
|
|
})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 200,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyTypeEqual("room_id", gjson.String),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom makes a room with a topic
|
|
t.Run("POST /createRoom makes a room with a topic", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
roomID := alice.MustCreateRoom(t, map[string]interface{}{
|
|
"topic": "Test Room",
|
|
"preset": "public_chat",
|
|
})
|
|
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.topic"})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 200,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyEqual("topic", "Test Room"),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom makes a room with a name
|
|
t.Run("POST /createRoom makes a room with a name", func(t *testing.T) {
|
|
t.Parallel()
|
|
roomID := alice.MustCreateRoom(t, map[string]interface{}{
|
|
"name": "Test Room",
|
|
"preset": "public_chat",
|
|
})
|
|
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.name"})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 200,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyEqual("name", "Test Room"),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom creates a room with the given version
|
|
t.Run("POST /createRoom creates a room with the given version", func(t *testing.T) {
|
|
t.Parallel()
|
|
roomID := alice.MustCreateRoom(t, map[string]interface{}{
|
|
"room_version": "2",
|
|
"preset": "public_chat",
|
|
})
|
|
res := alice.MustDo(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "state", "m.room.create"})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 200,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyEqual("room_version", "2"),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom makes a private room with invites
|
|
t.Run("POST /createRoom makes a private room with invites", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
res := alice.CreateRoom(t, map[string]interface{}{
|
|
"visibility": "private",
|
|
"invite": []string{bob.UserID},
|
|
})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 200,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyTypeEqual("room_id", gjson.String),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom rejects attempts to create rooms with numeric versions
|
|
t.Run("POST /createRoom rejects attempts to create rooms with numeric versions", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
res := alice.CreateRoom(t, map[string]interface{}{
|
|
"visibility": "private",
|
|
"room_version": 1,
|
|
"preset": "public_chat",
|
|
})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 400,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyEqual("errcode", "M_BAD_JSON"),
|
|
},
|
|
})
|
|
})
|
|
// sytest: POST /createRoom rejects attempts to create rooms with unknown versions
|
|
t.Run("POST /createRoom rejects attempts to create rooms with unknown versions", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
res := alice.CreateRoom(t, map[string]interface{}{
|
|
"visibility": "private",
|
|
"room_version": "ahfgwjyerhgiuveisbruvybseyrugvi",
|
|
"preset": "public_chat",
|
|
})
|
|
must.MatchResponse(t, res, match.HTTPResponse{
|
|
StatusCode: 400,
|
|
JSON: []match.JSON{
|
|
match.JSONKeyEqual("errcode", "M_UNSUPPORTED_ROOM_VERSION"),
|
|
},
|
|
})
|
|
})
|
|
// sytest: Rooms can be created with an initial invite list (SYN-205)
|
|
t.Run("Rooms can be created with an initial invite list (SYN-205)", func(t *testing.T) {
|
|
roomID := alice.MustCreateRoom(t, map[string]interface{}{
|
|
"invite": []string{bob.UserID},
|
|
})
|
|
|
|
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID))
|
|
})
|
|
|
|
// sytest: Can /sync newly created room
|
|
t.Run("Can /sync newly created room", func(t *testing.T) {
|
|
roomID := alice.MustCreateRoom(t, map[string]interface{}{})
|
|
|
|
// This will do the syncing for us
|
|
alice.SendEventSynced(t, roomID, b.Event{
|
|
Type: "m.room.test",
|
|
Content: map[string]interface{}{},
|
|
})
|
|
})
|
|
|
|
// sytest: POST /createRoom ignores attempts to set the room version via creation_content
|
|
t.Run("POST /createRoom ignores attempts to set the room version via creation_content", func(t *testing.T) {
|
|
roomID := alice.MustCreateRoom(t, map[string]interface{}{
|
|
"creation_content": map[string]interface{}{
|
|
"test": "azerty",
|
|
"room_version": "test",
|
|
},
|
|
})
|
|
|
|
// Wait until user has joined the room
|
|
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
|
|
|
|
// Get ordered timeline via a full sync
|
|
res, _ := alice.MustSync(t, client.SyncReq{})
|
|
|
|
roomObj := res.Get("rooms.join." + client.GjsonEscape(roomID))
|
|
|
|
if !roomObj.Exists() {
|
|
t.Fatalf("Room did not appear in sync")
|
|
}
|
|
|
|
event0 := roomObj.Get("timeline.events.0")
|
|
|
|
if !event0.Exists() {
|
|
t.Fatalf("First timeline event does not exist")
|
|
}
|
|
|
|
if event0.Get("type").Str != "m.room.create" {
|
|
t.Fatalf("First event was not m.room.create: %s", event0)
|
|
}
|
|
if !event0.Get("content.room_version").Exists() {
|
|
t.Fatalf("Room creation event did not have room version: %s", event0)
|
|
}
|
|
if event0.Get("content.room_version").Str == "test" {
|
|
t.Fatalf("Room creation event room_version was a bogus room version: %s", event0)
|
|
}
|
|
if event0.Get("content.test").Str != "azerty" {
|
|
t.Fatalf("Room creation event content 'test' key did not have expected value of 'azerty': %s", event0)
|
|
}
|
|
})
|
|
})
|
|
}
|