42 lines
1.6 KiB
Go
42 lines
1.6 KiB
Go
package asterisk
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestOriginatePreservesApprovedRouteAndCaller(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
trunk, dialed, caller, expected string
|
|
}{
|
|
{"shuqi", "708915000000001", "BD1234", "PJSIP/708915000000001@shuqi"},
|
|
{"zhongding", "15000000001", "mbkq", "PJSIP/15000000001@zhongding"},
|
|
{"baiying", "mka75515000000001", "KQ1234", "PJSIP/mka75515000000001@baiying"},
|
|
} {
|
|
request, err := approvedOriginateRequest("execution-123", tc.trunk, tc.dialed, tc.caller, 7*time.Second+900*time.Millisecond)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if request.Endpoint != tc.expected || request.CallerID != tc.caller || request.ChannelID != "execution-123" || request.Timeout != 7 || request.App != "go-sip-agent" {
|
|
t.Fatalf("Agent changed approved SIP route/caller or exceeded answer deadline: %+v", request)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOriginateRejectsMissingOrUnrepresentableSignedRoute(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
executionID, trunk, dialed, caller string
|
|
answer time.Duration
|
|
}{
|
|
{"", "shuqi", "708915000000001", "BD1234", time.Second},
|
|
{"execution-123", "../shuqi", "708915000000001", "BD1234", time.Second},
|
|
{"execution-123", "shuqi", "7089/15000000001", "BD1234", time.Second},
|
|
{"execution-123", "shuqi", "708915000000001", "BD1234\n", time.Second},
|
|
{"execution-123", "shuqi", "708915000000001", "BD1234", 900 * time.Millisecond},
|
|
} {
|
|
if _, err := approvedOriginateRequest(tc.executionID, tc.trunk, tc.dialed, tc.caller, tc.answer); err == nil {
|
|
t.Fatal("invalid signed route or subsecond answer timeout cannot create a channel")
|
|
}
|
|
}
|
|
}
|