<commit_before>---------------------------------------------------------------------------------------------------
-- Issue: https://github.com/SmartDeviceLink/sdl_core/issues/1921
-- Precondition:
-- 1. SDL and HMI are started.
-- 2. App is registered.
-- Steps:
-- 1. SDL received UpdatedPT with at least one <unknown_parameter> or <unknown_RPC>
-- and after cutting off <unknown_parameter> or <unknown_RPC> UpdatedPT is invalid
-- Expected result: SDL must log the error internally and discard Policy Table Update
-- Actual result:N/A
---------------------------------------------------------------------------------------------------
--[[ Required Shared libraries ]]
local runner = require('user_modules/script_runner')
local commonDefects = require('test_scripts/Defects/4_5/commonDefects')
local commonFunctions = require('user_modules/shared_testcases/commonFunctions')

--[[ Local Functions ]]
local CuttingUnknownStatus = false

--[[ Local Functions ]]
local function ptuUpdateFunc(tbl)
  local VDgroup = {
    rpcs = {
      GetVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SubscribeVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        newParameter = {"value"}
      },
      UnknownAPI = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SendLocation = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"}
      }
    }
  }
  tbl.policy_table.functional_groupings["NewTestCaseGroup"] = VDgroup
  tbl.policy_table.app_policies[config.application1.registerAppInterfaceParams.appID].groups =
  {"Base-4", "NewTestCaseGroup"}
end

local function NotValidPtuUpdateFunc(tbl)
  local VDgroup = {
    rpcs = {
      GetVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SubscribeVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        newParameter = {"value"}
      },
      UnknownAPI = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SendLocation = {
        -- missed mandatory hmi_levels parameter
      }
    }
  }
  tbl.policy_table.functional_groupings["NewTestCaseGroup"] = VDgroup
  tbl.policy_table.app_policies[config.application1.registerAppInterfaceParams.appID].groups =
  {"Base-4", "NewTestCaseGroup"}
end

local function CheckCuttingUnknowValues(self)
  commonDefects.rai_ptu_n_without_OnPermissionsChange(1, ptuUpdateFunc,self)
  self.mobileSession1:ExpectNotification("OnPermissionsChange")
  :Times(2)
  :ValidIf(function(_,data)
      local ErrorStatus = false
      local ErrorMessage = ""
      if #data.payload.permissionItem ~= 0 then
        for i=1, #data.payload.permissionItem do
          if data.payload.permissionItem[i].rpcName == "UnknownAPI" then
            ErrorStatus = true
            CuttingUnknownStatus = true
            ErrorMessage = ErrorMessage .. " OnPermissionsChange contains unknown_RPC value.\n"
          end
          if data.payload.permissionItem[i].newParameter then
            ErrorStatus = true
            CuttingUnknownStatus = true
            ErrorMessage = ErrorMessage .. " OnPermissionsChange contains unknown_parameter value.\n"
          end
        end
      else
        ErrorStatus = true
        ErrorMessage = ErrorMessage .. "OnPermissionsChange is not contain permissionItem elements"
      end
      if ErrorStatus == true then
        return false, ErrorMessage
      else
        return true
      end
    end)
  commonFunctions:userPrint(33, "Check PTU content of PTU attempt in SDL log by message 'PTU content is'.\n"
    .. "'policy_table' must not contain 'newParameter' and 'UnknownAPI' values.")
end

local function InvalidPTAfterCutingUnknownValues(self)
  if CuttingUnknownStatus == true then
    self:FailTestCase("Unknown values are not cut from PT, so test case is not executed.")
  else
    commonDefects.UnsuccessPTU(NotValidPtuUpdateFunc,self)
    commonFunctions:userPrint(33, "Check PTU content of second PTU attempt in SDL log by message" ..
    " 'PTU content is'.\n'policy_table' must not contain 'newParameter' and 'UnknownAPI' values.")
  end
end

--[[ Scenario ]]
runner.Title("Preconditions")
runner.Step("Clean environment", commonDefects.preconditions)
runner.Step("Start SDL, HMI, connect Mobile, start Session", commonDefects.start)

runner.Title("Test")
runner.Step("Check_cutting_unknown_values_from_PT", CheckCuttingUnknowValues)
runner.Step("Invalid_PTU_after_cuting_unknown_values", InvalidPTAfterCutingUnknownValues)

runner.Title("Postconditions")
runner.Step("Stop SDL", commonDefects.postconditions)
<commit_msg>Updated script according review comments<commit_after>---------------------------------------------------------------------------------------------------
-- Issue: https://github.com/SmartDeviceLink/sdl_core/issues/1921
-- Precondition:
-- 1. SDL and HMI are started.
-- 2. App is registered.
-- Steps:
-- 1. SDL received UpdatedPT with at least one <unknown_parameter> or <unknown_RPC>
-- and after cutting off <unknown_parameter> or <unknown_RPC> UpdatedPT is invalid
-- Expected result: SDL must log the error internally and discard Policy Table Update
-- Actual result:N/A
---------------------------------------------------------------------------------------------------
--[[ Required Shared libraries ]]
local runner = require('user_modules/script_runner')
local commonDefects = require('test_scripts/Defects/4_5/commonDefects')
local commonFunctions = require('user_modules/shared_testcases/commonFunctions')

--[[ Local Functions ]]
local isCuttingUnknownError = false
local isError
local ErrorMessage

--[[ Local Functions ]]
local function ptuUpdateFunc(tbl)
  local VDgroup = {
    rpcs = {
      GetVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SubscribeVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        newParameter = {"value"}
      },
      UnknownAPI = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SendLocation = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"}
      }
    }
  }
  tbl.policy_table.functional_groupings["NewTestCaseGroup"] = VDgroup
  tbl.policy_table.app_policies[config.application1.registerAppInterfaceParams.appID].groups =
  {"Base-4", "NewTestCaseGroup"}
end

local function NotValidPtuUpdateFunc(tbl)
  local VDgroup = {
    rpcs = {
      GetVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SubscribeVehicleData = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        newParameter = {"value"}
      },
      UnknownAPI = {
        hmi_levels = {"BACKGROUND", "FULL", "LIMITED"},
        parameters = {"gps"}
      },
      SendLocation = {
        -- missed mandatory hmi_levels parameter
      }
    }
  }
  tbl.policy_table.functional_groupings["NewTestCaseGroup"] = VDgroup
  tbl.policy_table.app_policies[config.application1.registerAppInterfaceParams.appID].groups =
  {"Base-4", "NewTestCaseGroup"}
end

local function ErrorOccurred(Message)
  isError = true
  ErrorMessage = ErrorMessage .. Message
end

local function CheckCuttingUnknowValues(self)
  commonDefects.rai_ptu_n_without_OnPermissionsChange(1, ptuUpdateFunc,self)
  self.mobileSession1:ExpectNotification("OnPermissionsChange")
  :Times(2)
  :ValidIf(function(_,data)
      isError = false
      ErrorMessage = ""
      if #data.payload.permissionItem ~= 0 then
        for i=1, #data.payload.permissionItem do
          if data.payload.permissionItem[i].rpcName == "UnknownAPI" then
            isCuttingUnknownError = true
            ErrorOccurred(" OnPermissionsChange contains unknown_RPC value.\n")
          end
          if data.payload.permissionItem[i].newParameter then
            isCuttingUnknownError = true
            ErrorOccurred(" OnPermissionsChange contains unknown_parameter value.\n")
          end
        end
      else
        ErrorOccurred("OnPermissionsChange is not contain permissionItem elements")
      end
      if isError == true then
        return false, ErrorMessage
      else
        return true
      end
    end)
  commonFunctions:userPrint(33, "Check PTU content of PTU attempt in SDL log by message 'PTU content is'.\n"
    .. "'policy_table' must not contain 'newParameter' and 'UnknownAPI' values.")
end

local function InvalidPTAfterCutingUnknownValues(self)
  if isCuttingUnknownError == true then
    self:FailTestCase("Unknown values are not cut from PT, so test case is not executed.")
  else
    commonDefects.UnsuccessPTU(NotValidPtuUpdateFunc,self)
    commonFunctions:userPrint(33, "Check PTU content of second PTU attempt in SDL log by message" ..
    " 'PTU content is'.\n'policy_table' must not contain 'newParameter' and 'UnknownAPI' values.")
  end
end

--[[ Scenario ]]
runner.Title("Preconditions")
runner.Step("Clean environment", commonDefects.preconditions)
runner.Step("Start SDL, HMI, connect Mobile, start Session", commonDefects.start)

runner.Title("Test")
runner.Step("Check_cutting_unknown_values_from_PT", CheckCuttingUnknowValues)
runner.Step("Invalid_PTU_after_cuting_unknown_values", InvalidPTAfterCutingUnknownValues)

runner.Title("Postconditions")
runner.Step("Stop SDL", commonDefects.postconditions)

{'fraction_non_alphanumeric': 0.14497041420118342, 'fraction_numerical': 0.004649196956889264, 'mean_word_length': 2.929016189290162, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '18476', 'n_tokens_mistral': 2713, 'n_tokens_neox': 2628, 'n_words': 633}