diff --git a/pkg/service/sip.go b/pkg/service/sip.go index d3de32f27..00d3b7a2c 100644 --- a/pkg/service/sip.go +++ b/pkg/service/sip.go @@ -331,12 +331,13 @@ func (s *SIPService) UpdateSIPOutboundTrunk(ctx context.Context, req *livekit.Up } switch a := req.Action.(type) { default: - return nil, errors.New("missing or unsupported action") + return nil, twirp.NewError(twirp.InvalidArgument, "missing or unsupported action") case livekit.UpdateSIPOutboundTrunkRequestAction: var result livekit.ValidationResult info, result = a.ApplyResult(info) + // The updated trunk failed validation (for example, the update removed its last number). if err := result.LogUnlikelySoftErrors(unlikelyLoggerFromCtx(ctx)); err != nil { - return nil, err + return nil, twirp.WrapError(twirp.NewError(twirp.InvalidArgument, err.Error()), err) } } // No additional validation needed for outbound. diff --git a/pkg/service/sip_test.go b/pkg/service/sip_test.go index a2f20cf51..ebab0a2a5 100644 --- a/pkg/service/sip_test.go +++ b/pkg/service/sip_test.go @@ -297,3 +297,29 @@ func TestCreateSIPParticipantSourceCallUnsupported(t *testing.T) { require.Equal(t, psrpc.Unimplemented, code) }) } + +func TestSIPOutboundTrunkUpdateValidation(t *testing.T) { + ctx, s, rs := newTestSIPService(t) + + created, err := s.CreateSIPOutboundTrunk(ctx, &livekit.CreateSIPOutboundTrunkRequest{ + Trunk: &livekit.SIPOutboundTrunkInfo{ + Name: "outbound", + Address: "sip.example.com", + Numbers: []string{"+15550001001"}, + }, + }) + require.NoError(t, err) + + // Removing the last number leaves an invalid trunk: a client error, not a server error. + _, err = s.UpdateSIPOutboundTrunk(ctx, &livekit.UpdateSIPOutboundTrunkRequest{ + SipTrunkId: created.SipTrunkId, + Action: &livekit.UpdateSIPOutboundTrunkRequest_Update{Update: &livekit.SIPOutboundTrunkUpdate{ + Numbers: &livekit.ListUpdate{Remove: []string{"+15550001001"}}, + }}, + }) + requireInvalidArgument(t, err) + + stored, err := rs.LoadSIPOutboundTrunk(ctx, created.SipTrunkId) + require.NoError(t, err) + require.Equal(t, []string{"+15550001001"}, stored.Numbers) +}