test: align IMS registration expectations (#43)

Co-authored-by: Meng Meng <[email protected]>
This commit is contained in:
Rain Seven
2026-08-16 23:46:28 +08:00
committed by GitHub
co-authored by Meng Meng
parent a2a72dfd30
commit 04dd026e95
3 changed files with 25 additions and 6 deletions
+7 -1
View File
@@ -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")
@@ -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(
+16 -3
View File
@@ -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