35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package ari
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"ai-operator/internal/config"
|
|
)
|
|
|
|
func TestBuildWebSocketURLBasic(t *testing.T) {
|
|
got, err := BuildWebSocketURL(config.AsteriskConfig{ARIWSURL: "ws://127.0.0.1:8088/ari/events", ARIApp: "ai-operator", ARIUser: "u", ARIPassword: "p"}, WSAuthBasic)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.URL != "ws://127.0.0.1:8088/ari/events?app=ai-operator" {
|
|
t.Fatalf("url=%s", got.URL)
|
|
}
|
|
if strings.Contains(got.Sanitized, "p") && strings.Contains(got.Sanitized, "api_key") {
|
|
t.Fatalf("sanitized leaked: %s", got.Sanitized)
|
|
}
|
|
}
|
|
|
|
func TestBuildWebSocketURLQueryAPIKeyMasks(t *testing.T) {
|
|
got, err := BuildWebSocketURL(config.AsteriskConfig{ARIWSURL: "ws://127.0.0.1:8088/ari/events?x=1", ARIApp: "ai-operator", ARIUser: "user", ARIPassword: "secret"}, WSAuthQueryAPIKey)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(got.URL, "x=1") || !strings.Contains(got.URL, "app=ai-operator") || !strings.Contains(got.URL, "api_key=") {
|
|
t.Fatalf("url=%s", got.URL)
|
|
}
|
|
if strings.Contains(got.Sanitized, "secret") || !strings.Contains(got.Sanitized, "%2A%2A%2AMASKED%2A%2A%2A") {
|
|
t.Fatalf("sanitized=%s", got.Sanitized)
|
|
}
|
|
}
|