-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require number, CIDR or auth for SIP inbound. (#890)
- Loading branch information
Showing
3 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"github.com/livekit/protocol": patch | ||
--- | ||
|
||
Require number, CIDR or auth for SIP inbound. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package livekit | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSIPTrunkAs(t *testing.T) { | ||
|
@@ -35,3 +36,141 @@ func TestSIPTrunkAs(t *testing.T) { | |
require.Equal(t, out, got) | ||
}) | ||
} | ||
|
||
func TestSIPValidate(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
req interface { | ||
Validate() error | ||
} | ||
exp bool | ||
}{ | ||
{ | ||
name: "inbound empty", | ||
req: &SIPInboundTrunkInfo{}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "inbound numbers", | ||
req: &SIPInboundTrunkInfo{ | ||
Numbers: []string{"+1111"}, | ||
}, | ||
exp: true, | ||
}, | ||
{ | ||
name: "inbound ips", | ||
req: &SIPInboundTrunkInfo{ | ||
AllowedAddresses: []string{"1.1.1.1"}, | ||
}, | ||
exp: true, | ||
}, | ||
{ | ||
name: "inbound auth", | ||
req: &SIPInboundTrunkInfo{ | ||
AuthUsername: "user", | ||
AuthPassword: "pass", | ||
}, | ||
exp: true, | ||
}, | ||
{ | ||
name: "inbound x-header", | ||
req: &SIPInboundTrunkInfo{ | ||
Numbers: []string{"+1111"}, | ||
HeadersToAttributes: map[string]string{ | ||
"X-Test": "test", | ||
}, | ||
}, | ||
exp: true, | ||
}, | ||
{ | ||
name: "inbound other header", | ||
req: &SIPInboundTrunkInfo{ | ||
Numbers: []string{"+1111"}, | ||
HeadersToAttributes: map[string]string{ | ||
"From": "from", | ||
}, | ||
}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound empty", | ||
req: &SIPOutboundTrunkInfo{}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound no numbers", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sip.example.com", | ||
}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound with numbers", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sip.example.com", | ||
Numbers: []string{"+2222"}, | ||
}, | ||
exp: true, | ||
}, | ||
{ | ||
name: "outbound with user", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "[email protected]", | ||
Numbers: []string{"+2222"}, | ||
}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound with transport", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sip.example.com;transport=tcp", | ||
Numbers: []string{"+2222"}, | ||
}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound with schema", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sip:example.com", | ||
Numbers: []string{"+2222"}, | ||
}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound with schema (tls)", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sips:example.com", | ||
Numbers: []string{"+2222"}, | ||
}, | ||
exp: false, | ||
}, | ||
{ | ||
name: "outbound x-header", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sip.example.com", | ||
Numbers: []string{"+2222"}, | ||
HeadersToAttributes: map[string]string{ | ||
"X-Test": "test", | ||
}, | ||
}, | ||
exp: true, | ||
}, | ||
{ | ||
name: "outbound other header", | ||
req: &SIPOutboundTrunkInfo{ | ||
Address: "sip.example.com", | ||
Numbers: []string{"+2222"}, | ||
HeadersToAttributes: map[string]string{ | ||
"From": "from", | ||
}, | ||
}, | ||
exp: false, | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
err := c.req.Validate() | ||
require.Equal(t, c.exp, err == nil, "error: %v", err) | ||
}) | ||
} | ||
} |