From 8803bf7867c002e884d4e2fcb7f5845efd2a6c02 Mon Sep 17 00:00:00 2001 From: Daniel Grotti Date: Fri, 16 Jun 2023 11:32:51 +0200 Subject: [PATCH] MT#56961 Clean $xavp(callee_prefs) when cleaning $xavp(callee_peer_prefs) The following scenario disclouse an issue with "ngcp_clean" lua function in case of callee peer: - A is a local subscriber with Peer_auth set and force_outbound_call_to_peer set; - B is a local subscriber with Peer_auth set and force_outbound_call_to_peer set; A calls B. We clean and load callee preferences of B. Call is detected as forced to PSTN. We clean and load peer preferences. When we set outbound peer_auth* values, the $xavp(callee_prefs) still contains values from B (instead of peering preferences). When we clean preferences for the callee peer, we only clean "callee_peer_prefs" and not "callee_prefs". "callee_prefs" are clean only in case of 'usr' or 'dom' preferences. This patch try to fix this problem in order to fix this scenario with outbound user authentication. Change-Id: I76dfa6f9e074b3d83ac67bd818e59233ca50492c (cherry picked from commit 8cdd63731bb0b5eeb8617e77d10d96170db58793) --- ngcp/pp.lua | 11 +++++++++++ tests/ngcp_pp.lua | 20 +++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ngcp/pp.lua b/ngcp/pp.lua index a452f28..e1c9bcc 100644 --- a/ngcp/pp.lua +++ b/ngcp/pp.lua @@ -19,6 +19,7 @@ -- local utils = require 'ngcp.utils' local NGCPPrefs = require 'ngcp.pref' +local NGCPXAvp = require 'ngcp.xavp' -- class NGCPPeerPrefs local NGCPPeerPrefs = utils.inheritsFrom(NGCPPrefs) @@ -35,5 +36,15 @@ function NGCPPeerPrefs:new(config) return instance end +function NGCPPeerPrefs:clean(vtype) + NGCPPrefs.clean(self, vtype) + if not vtype then + NGCPXAvp:new('callee', 'prefs'):clean() + NGCPXAvp:new('caller', 'prefs'):clean() + else + NGCPXAvp:new(vtype, 'prefs'):clean() + end +end + -- class return NGCPPeerPrefs diff --git a/tests/ngcp_pp.lua b/tests/ngcp_pp.lua index af494da..5f7793d 100644 --- a/tests/ngcp_pp.lua +++ b/tests/ngcp_pp.lua @@ -22,7 +22,7 @@ local lemock = require('lemock') local utils = require 'ngcp.utils' local utable = utils.table local PPFetch = require 'tests_v.pp_vars' - +local NGCPXAvp = require 'ngcp.xavp' local ksrMock = require 'mocks.ksr' KSR = ksrMock:new() @@ -234,6 +234,24 @@ TestNGCPPeerPrefs = {} --class lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") end + function TestNGCPPeerPrefs:test_clean_prefs() + local xavp_pref = NGCPXAvp:new('callee', 'prefs') + local xavp = NGCPPeerPrefs:xavp('callee') + xavp("testid",1) + xavp("foo","foo") + xavp_pref("two",2) + lu.assertEquals(KSR.pv.get("$xavp(callee_prefs=>two)"),2) + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1) + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo") + lu.assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") + self.d:clean('callee') + lu.assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") + lu.assertNil(KSR.pv.get("$xavp(peer)")) + lu.assertEquals(KSR.pv.get("$xavp(callee_prefs=>dummy)"), "callee") + end + function TestNGCPPeerPrefs:test_tostring() local callee_xavp = NGCPPeerPrefs:xavp('callee') callee_xavp("testid",1)