TEL-1359: return InvalidArgument for invalid outbound trunk updates (#5242)

This commit is contained in:
He Chen authored and GitHub committed 2026-11-18 11:53:50 -08:00
1 parent d1b95c28b3
commit 3f3a62dc58
2 files changed
+29 -2

No files matched your search

+3 -2
View File
@@ -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.
+26
View File
@@ -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)
}