31 lines
965 B
Go
31 lines
965 B
Go
package asterisk
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAgentARIOptionsRequirePrivateIssuedCredential(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "ari-secret")
|
|
secret := strings.Repeat("a", 64)
|
|
if err := os.WriteFile(path, []byte(secret), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
options, err := (Loader{ConfigDir: dir}).ariOptions()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if options.URL != "http://127.0.0.1:8088/ari" || options.WebsocketURL != "ws://127.0.0.1:8088/ari/events" || options.Application != "go-sip-agent" || options.Username != "go-sip-agent" || options.Password != secret {
|
|
t.Fatal("ARI must bind the issued user identity and loopback endpoint")
|
|
}
|
|
if err := os.Chmod(path, 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := (Loader{ConfigDir: dir}).ariOptions(); err == nil || strings.Contains(err.Error(), secret) {
|
|
t.Fatalf("public credential must fail without leaking its value: %v", err)
|
|
}
|
|
}
|