Skip to content

Commit 9ce0387

Browse files
authored
Fix hostname validation for a new type. (#968)
1 parent 0790473 commit 9ce0387

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

livekit/sip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (p *SIPOutboundConfig) Validate() error {
311311
return errors.New("no outbound hostname specified")
312312
} else if strings.Contains(p.Hostname, "transport=") {
313313
return errors.New("trunk transport should be set as a field, not a URI parameter")
314-
} else if strings.ContainsAny(p.Hostname, "@;") || strings.HasPrefix(p.Address, "sip:") || strings.HasPrefix(p.Address, "sips:") {
314+
} else if strings.ContainsAny(p.Hostname, "@;") || strings.HasPrefix(p.Hostname, "sip:") || strings.HasPrefix(p.Hostname, "sips:") {
315315
return errors.New("trunk hostname should be a domain name or IP, not SIP URI")
316316
}
317317
if err := validateHeaderKeys(p.HeadersToAttributes); err != nil {

rpc/sip_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func TestNewCreateSIPParticipantRequest(t *testing.T) {
104104
}, res)
105105

106106
r.HidePhoneNumber = false
107+
r.SipNumber = tr.Numbers[0]
107108
r.Trunk = &livekit.SIPOutboundConfig{
108109
Hostname: tr.Address,
109110
Transport: tr.Transport,
@@ -114,6 +115,11 @@ func TestNewCreateSIPParticipantRequest(t *testing.T) {
114115
}
115116
r.SipTrunkId = ""
116117
exp.SipTrunkId = ""
118+
for k, v := range tr.Headers {
119+
if _, ok := r.Headers[k]; !ok {
120+
r.Headers[k] = v
121+
}
122+
}
117123
exp.ParticipantAttributes[livekit.AttrSIPTrunkID] = ""
118124
res, err = NewCreateSIPParticipantRequest("p_123", "call-id", "xyz.sip.livekit.cloud", "url", "token", r, nil)
119125
require.NoError(t, err)

0 commit comments

Comments
 (0)