From 04dd026e9547453c4924b8b4810959d981abdff6 Mon Sep 17 00:00:00 2001 From: Rain Seven <128443127+RAiNY7Study@users.noreply.github.com> Date: Sun, 16 Aug 2026 23:46:28 +0800 Subject: [PATCH] test: align IMS registration expectations (#43) Co-authored-by: Meng Meng <227010654+MengMengCode@users.noreply.github.com> --- internal/vowifi/ims/provider_test.go | 8 +++++++- internal/vowifi/ims/security_provider_test.go | 4 ++-- internal/vowifi/ims/security_test.go | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/internal/vowifi/ims/provider_test.go b/internal/vowifi/ims/provider_test.go index eedd3ed..07c7b24 100644 --- a/internal/vowifi/ims/provider_test.go +++ b/internal/vowifi/ims/provider_test.go @@ -375,7 +375,6 @@ func serveRegistration(listener *net.UDPConn, nonce string, confirmSMS bool) err return fmt.Errorf("unexpected start line %q", startLine) } for _, forbidden := range []string{ - "p-access-network-info", "p-visited-network-id", "p-preferred-identity", } { @@ -387,6 +386,13 @@ func serveRegistration(listener *net.UDPConn, nonce string, confirmSMS bool) err ) } } + if headers["p-access-network-info"] != "IEEE-802.11;i-wlan-node-id=000000000000;network-provided" { + return fmt.Errorf("REGISTER P-Access-Network-Info = %q", headers["p-access-network-info"]) + } + if !strings.Contains(headers["allow"], "MESSAGE") || + !strings.Contains(string(packet[:count]), "Accept-Contact: *;+g.3gpp.smsip") { + return fmt.Errorf("REGISTER omitted SMS-over-IMS capability: Allow=%q", headers["allow"]) + } if step == 0 { if headers["authorization"] != "" { return errors.New("initial REGISTER unexpectedly authenticated") diff --git a/internal/vowifi/ims/security_provider_test.go b/internal/vowifi/ims/security_provider_test.go index 92c84fe..fee6ab2 100644 --- a/internal/vowifi/ims/security_provider_test.go +++ b/internal/vowifi/ims/security_provider_test.go @@ -531,8 +531,8 @@ func serveProtectedRegistrar( return result, fmt.Errorf("protected Contact = %q", headers["contact"]) } if strings.Contains(strings.ToUpper(startLine), "MESSAGE") || - strings.Contains(strings.ToUpper(headers["allow"]), "MESSAGE") { - return result, errors.New("registration transaction advertised or sent MESSAGE") + !strings.Contains(strings.ToUpper(headers["allow"]), "MESSAGE") { + return result, errors.New("registration transaction did not advertise MESSAGE correctly") } if _, err := protectedConnection.Write(testResponse( diff --git a/internal/vowifi/ims/security_test.go b/internal/vowifi/ims/security_test.go index 6343df7..de3cc8b 100644 --- a/internal/vowifi/ims/security_test.go +++ b/internal/vowifi/ims/security_test.go @@ -287,14 +287,18 @@ func TestXFRMPlanContainsFourStatesAndProtocolSpecificPolicies(t *testing.T) { "tcp 40666 50600 out": false, "udp 40666 50600 out": false, "tcp 50600 40666 in": false, - "tcp 50601 55610 in": false, - "udp 50601 55610 in": false, + "tcp * 55610 in": false, + "udp * 55610 in": false, "tcp 55610 50601 out": false, } for _, operation := range install[4:] { + sourcePort := "*" + if value, ok := optionalArgumentAfter(operation.arguments, "sport"); ok { + sourcePort = value + } key := strings.Join([]string{ argumentAfter(t, operation.arguments, "proto"), - argumentAfter(t, operation.arguments, "sport"), + sourcePort, argumentAfter(t, operation.arguments, "dport"), argumentAfter(t, operation.arguments, "dir"), }, " ") @@ -397,6 +401,15 @@ func argumentAfter(t *testing.T, arguments []string, name string) string { return "" } +func optionalArgumentAfter(arguments []string, name string) (string, bool) { + for index := 0; index+1 < len(arguments); index++ { + if arguments[index] == name { + return arguments[index+1], true + } + } + return "", false +} + func containsArguments(arguments []string, sequence ...string) bool { if len(sequence) == 0 || len(sequence) > len(arguments) { return false