<commit_before>---------------------------------------------------------------------------------------------
-- Requirement summary:
-- [Policies]: OnAllowSDLFunctionality with 'allowed=false' and with 'device' param from HMI
--
-- Description:
-- 1. Preconditions: App is registered, device is consented
-- 2. Steps: send SDL.OnAllowSDLFunctionality with 'allowed=false' and with 'device' to HMI
--
-- Expected result:
-- In case PoliciesManager receives SDL.OnAllowSDLFunctionality with 'allowed=false' and with 'device' param, PoliciesManager must record the named
-- device ('device' param) as NOT consented in Local PT ("user_consent_records"-> "device" sub-section) and send BasicCommunication.ActivateApp with
-- 'level' param of the value from 'default_hmi' key of 'pre-DataConsent'section of Local PT to HMI. App should stay in NONE HMI level
---------------------------------------------------------------------------------------------
config.deviceMAC = "12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0"

--[[ Required Shared libraries ]]
local commonFunctions = require ('user_modules/shared_testcases/commonFunctions')
local commonSteps = require('user_modules/shared_testcases/commonSteps')
local testCasesForPolicyTable = require('user_modules/shared_testcases/testCasesForPolicyTable')
local testCasesForPolicyTableSnapshot = require('user_modules/shared_testcases/testCasesForPolicyTableSnapshot')

--[[ Local variables ]]
local device_consent
local device_consent_group
local ServerAddress = commonFunctions:read_parameter_from_smart_device_link_ini("ServerAddress")

--[[ General Precondition before ATF start ]]
commonSteps:DeleteLogsFileAndPolicyTable()

--[[ General configuration parameters ]]
Test = require('connecttest')
require('cardinalities')
require('mobile_session')
require('user_modules/AppTypes')

--[[ Preconditions ]]
commonFunctions:newTestCasesGroup("Preconditions")
function Test:Precondition_trigger_getting_device_consent()
  testCasesForPolicyTable:trigger_getting_device_consent(self, config.application1.registerAppInterfaceParams.appName, config.deviceMAC)
end

--[[ Test ]]
commonFunctions:newTestCasesGroup("Test")
function Test:TestStep_Allowed_false_without_device()

  device_consent_group = testCasesForPolicyTableSnapshot:get_data_from_PTS("app_policies.device.groups.1")
  device_consent = testCasesForPolicyTableSnapshot:get_data_from_PTS("device_data."..config.deviceMAC..".user_consent_records.device.consent_groups.DataConsent-2")
  --print("device_consent = " ..device_consent)
  if( (device_consent == nil) or (device_consent_group == nil)) then
    self:FailTestCase("Device is not consented after user consent.")
  elseif (device_consent_group ~= "DataConsent-2") then
    self:FailTestCase("app_policies.device.groups is not DataConsent-2.")
  elseif (device_consent) then
    if(device_consent ~= true) then
      self:FailTestCase("Device is not consented after user consent.")
    else
      print("DeviceConsented!")
      self.hmiConnection:SendNotification("SDL.OnAllowSDLFunctionality", {allowed = false, source = "GUI"})
    end
  end
end

function Test:TestStep_Check_Device_IsnotAllowed()
  testCasesForPolicyTableSnapshot:extract_pts({self.applications[config.application1.registerAppInterfaceParams.appName]})
  device_consent = testCasesForPolicyTableSnapshot:get_data_from_PTS("device_data."..config.deviceMAC..".user_consent_records.device.consent_groups.DataConsent-2")
  local RequestId = self.hmiConnection:SendRequest("SDL.ActivateApp", { appID = self.applications[config.application1.registerAppInterfaceParams.appName]})
  EXPECT_HMIRESPONSE(RequestId)
  :Do(function(_,data)
      if (data.result.isSDLAllowed == true) then
        self:FailTestCase("Device is still consented after user disallowed access to it.")
      end

      local RequestId1 = self.hmiConnection:SendRequest("SDL.GetUserFriendlyMessage", {language = "EN-US", messageCodes = {"DataConsent"}})
      --hmi side: expect SDL.GetUserFriendlyMessage message response
      EXPECT_HMIRESPONSE( RequestId1, {result = {code = 0, method = "SDL.GetUserFriendlyMessage"}})
      :Do(function(_,_)
          self.hmiConnection:SendNotification("SDL.OnAllowSDLFunctionality",
            {allowed = false, source = "GUI", device = {id = config.deviceMAC, name = ServerAddress, isSDLAllowed = false}})
        end)

      EXPECT_HMICALL("BasicCommunication.PolicyUpdate",{})
      :Do(function(_,_)<commit_msg>Script is ready for merging<commit_after>---------------------------------------------------------------------------------------------
-- Requirement summary:
-- [Policies]: OnAllowSDLFunctionality with 'allowed=false' and with 'device' param from HMI
--
-- Description:
-- 1. Preconditions: App is registered, device is consented
-- 2. Steps: send SDL.OnAllowSDLFunctionality with 'allowed=false' and with 'device' to HMI
--
-- Expected result:
-- In case PoliciesManager receives SDL.OnAllowSDLFunctionality with 'allowed=false' and with 'device' param, PoliciesManager must record the named
-- device ('device' param) as NOT consented in Local PT ("user_consent_records"-> "device" sub-section) and send BasicCommunication.ActivateApp with
-- 'level' param of the value from 'default_hmi' key of 'pre-DataConsent'section of Local PT to HMI. App should stay in NONE HMI level
---------------------------------------------------------------------------------------------
config.deviceMAC = "12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0"

--[[ Required Shared libraries ]]
local commonFunctions = require ('user_modules/shared_testcases/commonFunctions')
local commonSteps = require('user_modules/shared_testcases/commonSteps')
local testCasesForPolicyTable = require('user_modules/shared_testcases/testCasesForPolicyTable')
local testCasesForPolicyTableSnapshot = require('user_modules/shared_testcases/testCasesForPolicyTableSnapshot')

--[[ Local variables ]]
local device_consent
local device_consent_group
local ServerAddress = commonFunctions:read_parameter_from_smart_device_link_ini("ServerAddress")

--[[ General Precondition before ATF start ]]
commonSteps:DeleteLogsFileAndPolicyTable()

--[[ General configuration parameters ]]
Test = require('connecttest')
require('cardinalities')
require('mobile_session')
require('user_modules/AppTypes')

--[[ Preconditions ]]
commonFunctions:newTestCasesGroup("Preconditions")
function Test:Precondition_trigger_getting_device_consent()
  testCasesForPolicyTable:trigger_getting_device_consent(self, config.application1.registerAppInterfaceParams.appName, config.deviceMAC)
end

--[[ Test ]]
commonFunctions:newTestCasesGroup("Test")
function Test:TestStep_Allowed_false_with_device()

  device_consent_group = testCasesForPolicyTableSnapshot:get_data_from_PTS("app_policies.device.groups.1")
  device_consent = testCasesForPolicyTableSnapshot:get_data_from_PTS("device_data."..config.deviceMAC..".user_consent_records.device.consent_groups.DataConsent-2")
  --print("device_consent = " ..device_consent)
  if( (device_consent == nil) or (device_consent_group == nil)) then
    self:FailTestCase("Device is not consented after user consent.")
  elseif (device_consent_group ~= "DataConsent-2") then
    self:FailTestCase("app_policies.device.groups is not DataConsent-2.")
  elseif (device_consent) then
    if(device_consent ~= true) then
      self:FailTestCase("Device is not consented after user consent.")
    else
      self.hmiConnection:SendNotification("SDL.OnAllowSDLFunctionality", 
        {allowed = false, source = "GUI",  device = {id = config.deviceMAC, name = ServerAddress, isSDLAllowed = false}})
    end
  end
end

function Test:TestStep_Check_Device_IsnotAllowed()
  testCasesForPolicyTableSnapshot:extract_pts({self.applications[config.application1.registerAppInterfaceParams.appName]})
  device_consent = testCasesForPolicyTableSnapshot:get_data_from_PTS("device_data."..config.deviceMAC..".user_consent_records.device.consent_groups.DataConsent-2")
  local RequestId = self.hmiConnection:SendRequest("SDL.ActivateApp", { appID = self.applications[config.application1.registerAppInterfaceParams.appName]})
  EXPECT_HMIRESPONSE(RequestId)
  :Do(function(_,data)
      if (data.result.isSDLAllowed == true) then
        self:FailTestCase("Device is still consented after user disallowed access to it.")
      end

      local RequestId1 = self.hmiConnection:SendRequest("SDL.GetUserFriendlyMessage", {language = "EN-US", messageCodes = {"DataConsent"}})
      --hmi side: expect SDL.GetUserFriendlyMessage message response
      EXPECT_HMIRESPONSE( RequestId1, {result = {code = 0, method = "SDL.GetUserFriendlyMessage"}})
      :Do(function(_,_)
          self.hmiConnection:SendNotification("SDL.OnAllowSDLFunctionality",
            {allowed = false, source = "GUI", device = {id = config.deviceMAC, name = ServerAddress, isSDLAllowed = false}})
        end)

      EXPECT_HMICALL("BasicCommunication.PolicyUpdate",{})
      :Do(function(_,_)
{'fraction_non_alphanumeric': 0.1417786166315088, 'fraction_numerical': 0.013767070056622626, 'mean_word_length': 4.715736040609137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '6082837', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2556, 'n_words': 521}