diff --git a/internal/asterisk/loader.go b/internal/asterisk/loader.go index 32316e3..268937f 100644 --- a/internal/asterisk/loader.go +++ b/internal/asterisk/loader.go @@ -41,7 +41,9 @@ type appliedState struct { Trunks []loadedTrunk `json:"trunks"` } -var endpointLine = regexp.MustCompile(`(?m)^\s*Endpoint:\s+(\S+)`) +// Asterisk prints Endpoint: /; the slash and caller ID are +// display metadata, not part of the configured endpoint name. +var endpointLine = regexp.MustCompile(`(?m)^[ \t]*Endpoint:[ \t]+([^/< \t\r\n]+)(?:/[^ \t\r\n]+)?`) func endpointOption(output []byte, name string) string { for line := range strings.SplitSeq(string(output), "\n") { diff --git a/internal/asterisk/loader_test.go b/internal/asterisk/loader_test.go index 0701d48..70ec9d8 100644 --- a/internal/asterisk/loader_test.go +++ b/internal/asterisk/loader_test.go @@ -18,7 +18,7 @@ func TestLoaderPersistsOnlyVerifiedNativeReload(t *testing.T) { script := `#!/bin/sh case "$*" in *"pjsip show transports"*) echo 'Transport: go-sip-udp udp 0 0 0.0.0.0:5060' ;; - *"pjsip show endpoints"*) echo 'Endpoint: '; echo 'Endpoint: trunk-shuqi Not in use' ;; + *"pjsip show endpoints"*) echo 'Endpoint: '; echo 'Endpoint: trunk-shuqi/BD93205882 Not in use' ;; *"pjsip show endpoint trunk-shuqi"*) echo 'Aor: trunk-shuqi-aor allow: alaw transport: go-sip-udp context: go-sip-no-inbound'; echo 'from_user : BD93205882'; echo 'callerid : "BD93205882" ' ;; *"pjsip show aor trunk-shuqi-aor"*) echo 'Contact: sip:61.132.228.221:5060' ;; *) exit 9 ;; @@ -99,6 +99,14 @@ esac } } +func TestEndpointReadbackSeparatesCallerDisplayFromEndpointName(t *testing.T) { + output := []byte(" Endpoint: \n Endpoint: trunk-shuqi/BD93205882 Not in use\n Endpoint: trunk-foreign/other Not in use\n") + matches := endpointLine.FindAllSubmatch(output, -1) + if len(matches) != 2 || string(matches[0][1]) != "trunk-shuqi" || string(matches[1][1]) != "trunk-foreign" { + t.Fatalf("invalid endpoint names from native Asterisk listing: %q", matches) + } +} + func TestLoaderFailsClosedWithoutApprovedStaticTransport(t *testing.T) { dir := t.TempDir() loader := Loader{ConfigDir: dir, Asterisk: "/bin/true", LibraryDir: dir}