Return 404 with DeleteRoom/RemoveParticipant when deleting non-existent resources (#1860)

Fixes #1587
This commit is contained in:
David Zhao
2023-07-08 22:30:49 -07:00
committed by GitHub
parent cbec68ae44
commit 42a7d52272
2 changed files with 17 additions and 2 deletions
+10
View File
@@ -127,6 +127,11 @@ func (s *RoomService) DeleteRoom(ctx context.Context, req *livekit.DeleteRoomReq
if err := EnsureCreatePermission(ctx); err != nil {
return nil, twirpAuthError(err)
}
if _, _, err := s.roomStore.LoadRoom(ctx, livekit.RoomName(req.Room), false); err == ErrRoomNotFound {
return nil, twirp.NotFoundError("room not found")
}
err := s.router.WriteRoomRTC(ctx, livekit.RoomName(req.Room), &livekit.RTCNodeMessage{
Message: &livekit.RTCNodeMessage_DeleteRoom{
DeleteRoom: req,
@@ -187,6 +192,11 @@ func (s *RoomService) GetParticipant(ctx context.Context, req *livekit.RoomParti
func (s *RoomService) RemoveParticipant(ctx context.Context, req *livekit.RoomParticipantIdentity) (*livekit.RemoveParticipantResponse, error) {
AppendLogFields(ctx, "room", req.Room, "participant", req.Identity)
if _, err := s.roomStore.LoadParticipant(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)); err == ErrParticipantNotFound {
return nil, twirp.NotFoundError("participant not found")
}
err := s.writeParticipantMessage(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity), &livekit.RTCNodeMessage{
Message: &livekit.RTCNodeMessage_RemoveParticipant{
RemoveParticipant: req,
+7 -2
View File
@@ -17,7 +17,7 @@ import (
)
func TestDeleteRoom(t *testing.T) {
t.Run("normal deletion", func(t *testing.T) {
t.Run("delete non-existent", func(t *testing.T) {
svc := newTestRoomService(config.RoomConfig{})
grant := &auth.ClaimGrants{
Video: &auth.VideoGrant{
@@ -29,7 +29,12 @@ func TestDeleteRoom(t *testing.T) {
_, err := svc.DeleteRoom(ctx, &livekit.DeleteRoomRequest{
Room: "testroom",
})
require.NoError(t, err)
require.Error(t, err)
if terr, ok := err.(twirp.Error); ok {
require.Equal(t, twirp.NotFound, terr.Code())
} else {
require.Fail(t, "should be twirp error")
}
})
t.Run("missing permissions", func(t *testing.T) {