summaryrefslogtreecommitdiff
path: root/test/benchmark_tests/security_tests/bm_load_security_update_whitelist.cpp
blob: 9c9a43d9307aebb5e1b99acf01225d6a1203133b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (C) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <benchmark/benchmark.h>
#include "../../common/utility.hpp"
namespace {
std::string configuration_file { "/vsomeip/0_0/vsomeip_security.json" };
}

// Since this set of tests check a private method, there is the need to indirectly change the
// parameters used by load_security_update_whitelist, and check its changes using other methods.
// The is_policy_removal_allowed method checks if a selected uid is present in the whitelist.
// The is_policy_update_allowed method checks if a selected service_id is present in the whitelist.

static void BM_load_security_update_whitelist_check_no_uids_loaded(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    std::vector<vsomeip_v3::uid_t> user_ids;

    std::vector<vsomeip_v3::service_t> services;
    utility::get_policy_services(policy_elements.at(0), services);

    // Add a security whitelist with an empty list of user uids.
    utility::add_security_whitelist(policy_elements.at(0), user_ids, services, true);

    // Using load function to indirectly call load_security_update_whitelist.
    for (auto _ : state) {
    security->load(policy_elements.at(0));
    }
}

static void BM_load_security_update_whitelist_check_uids_loaded(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    std::vector<vsomeip_v3::uid_t> user_ids;
    utility::get_policy_uids(policy_elements.at(0), user_ids);

    std::vector<vsomeip_v3::service_t> services;
    utility::get_policy_services(policy_elements.at(0), services);

    // Add a security whitelist with a list of uids loaded
    utility::add_security_whitelist(policy_elements.at(0), user_ids, services, true);

    // Using load function to indirectly call load_security_update_whitelist.
    for (auto _ : state) {
    security->load(policy_elements.at(0));
    }
}

static void BM_load_security_update_whitelist_check_no_service_ids_loaded(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies with an empty service id vector.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    std::vector<vsomeip_v3::uid_t> user_ids;
    utility::get_policy_uids(policy_elements.at(0), user_ids);

    std::vector<vsomeip_v3::service_t> services;

    // Add a security whitelist with an empty list of user uids.
    utility::add_security_whitelist(policy_elements.at(0), user_ids, services, true);

    // Using load function to indirectly call load_security_update_whitelist.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

static void BM_load_security_update_whitelist_check_service_ids_loaded(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    std::vector<vsomeip_v3::uid_t> user_ids;
    utility::get_policy_uids(policy_elements.at(0), user_ids);

    std::vector<vsomeip_v3::service_t> services;
    utility::get_policy_services(policy_elements.at(0), services);

    // Add a security whitelist with list of service ids loaded.
    utility::add_security_whitelist(policy_elements.at(0), user_ids, services, true);

    // Using load function to indirectly call load_security_update_whitelist.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

static void BM_load_security_update_whitelist_check_whitelist_disabled(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    std::vector<vsomeip_v3::uid_t> user_ids;
    utility::get_policy_uids(policy_elements.at(0), user_ids);

    std::vector<vsomeip_v3::service_t> services;
    utility::get_policy_services(policy_elements.at(0), services);

    // Add a security whitelist with check_whitelist disabled
    utility::add_security_whitelist(policy_elements.at(0), user_ids, services, false);

    // Using load function to indirectly call load_security_update_whitelist.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

BENCHMARK(BM_load_security_update_whitelist_check_no_uids_loaded);
BENCHMARK(BM_load_security_update_whitelist_check_no_service_ids_loaded);
BENCHMARK(BM_load_security_update_whitelist_check_uids_loaded);
BENCHMARK(BM_load_security_update_whitelist_check_service_ids_loaded);
BENCHMARK(BM_load_security_update_whitelist_check_whitelist_disabled);