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

Add testcase when joining unknown room. #869

Merged
merged 1 commit into from
Nov 21, 2024
Merged
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
49 changes: 49 additions & 0 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ func processRoomRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
if request.Room.Action == "leave" && request.Room.UserId == "test-userid1" {
assert.Fail("Should not receive \"leave\" event for first user, received %+v", request.Room)
}
case "test-invalid-room":
response := &BackendClientResponse{
Type: "error",
Error: &Error{
Code: "no_such_room",
Message: "The user is not invited to this room.",
},
}
return response
}

if strings.Contains(t.Name(), "Federation") {
Expand Down Expand Up @@ -2800,6 +2809,46 @@ func TestJoinRoom(t *testing.T) {
require.Equal("", roomMsg.Room.RoomId)
}

func TestJoinInvalidRoom(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
require := require.New(t)
assert := assert.New(t)
hub, _, _, server := CreateHubForTest(t)

client := NewTestClient(t, server, hub)
defer client.CloseWithBye()

require.NoError(client.SendHello(testDefaultUserId))

ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

hello, err := client.RunUntilHello(ctx)
require.NoError(err)

// Join room by id.
roomId := "test-invalid-room"
msg := &ClientMessage{
Id: "ABCD",
Type: "room",
Room: &RoomClientMessage{
RoomId: roomId,
SessionId: roomId + "-" + hello.Hello.SessionId,
},
}
require.NoError(client.WriteJSON(msg))

message, err := client.RunUntilMessage(ctx)
require.NoError(err)
require.NoError(checkUnexpectedClose(err))

assert.Equal(msg.Id, message.Id)
if assert.NoError(checkMessageType(message, "error")) {
assert.Equal("no_such_room", message.Error.Code)
}
}

func TestJoinRoomTwice(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
Expand Down
Loading