2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
26 #include <ckm/ckm-type.h>
27 #include <ckmc/ckmc-type.h>
28 #include <ckmc/ckmc-error.h>
29 #include <tests_common.h>
30 #include <sys/types.h>
31 #include <access_provider2.h>
33 // RUNNER_ASSERT wrappers
34 template <typename F, typename... Args>
35 void assert_result(int expected, F&& func, Args... args)
37 int ret = func(args...);
38 RUNNER_ASSERT_MSG(ret == expected, "Expected " << expected << " got: " << ret);
41 template <typename F, typename... Args>
42 void assert_positive(F&& func, Args... args)
44 assert_result(CKMC_ERROR_NONE, std::move(func), args...);
47 template <typename F, typename... Args>
48 void assert_invalid_param(F&& func, Args... args)
50 assert_result(CKMC_ERROR_INVALID_PARAMETER, std::move(func), args...);
56 size_t list_size(const T* list)
67 // service lifecycle management
72 void start_service(ServiceIdx idx);
73 void stop_service(ServiceIdx idx);
75 // support for error printing
76 const char * CKMCErrorToString(int error);
77 std::string CKMCReadableError(int error);
80 typedef std::unique_ptr<char, void (*)(void *)> CharPtr;
82 // returns process label
85 std::string aliasWithLabel(const char *label, const char *alias);
87 // changes process label
88 void change_label(const char* label);
90 // changes process label upon construction and restores it upon destruction
94 ScopedLabel(const char* label);
98 CharPtr m_original_label;
101 void save_data(const char* alias, const char *data, int expected_err = CKMC_ERROR_NONE);
102 void save_data(const char* alias, const char *data, size_t len, int expected_err);
106 ScopedSaveData(const char* alias, const char *data, int expected_err = CKMC_ERROR_NONE);
107 virtual ~ScopedSaveData();
113 class GarbageCollector
116 void save(const char* alias, const char *data, int expected_err = CKMC_ERROR_NONE);
117 void save(const char* alias, const char *data, size_t len, int expected_err);
118 void add(const char* alias);
119 virtual ~GarbageCollector();
123 std::string item_alias;
124 std::string owner_label;
128 std::vector<save_item> m_garbage;
134 ScopedDBUnlock(uid_t user_id, const char* passwd);
135 virtual ~ScopedDBUnlock();
141 void check_remove_allowed(const char* alias);
142 void check_remove_denied(const char* alias);
143 void check_remove_not_visible(const char* alias);
144 void check_read(const char* alias,
146 const char *test_data,
148 int expected_code = CKMC_ERROR_NONE);
149 void check_read(const char* alias,
151 const char *test_data,
152 int expected_code = CKMC_ERROR_NONE);
153 void check_read_allowed(const char* alias, const char *data);
154 void check_read_not_visible(const char* alias);
155 void check_key(const char *alias,
156 int expected_error = CKMC_ERROR_NONE,
157 ckmc_key_type_e expected_type = CKMC_KEY_NONE);
158 void check_key_allowed(const char *alias, ckmc_key_type_e expected_type = CKMC_KEY_NONE);
159 void check_key_not_visible(const char *alias);
160 void check_cert_allowed(const char *alias);
161 void check_cert_not_visible(const char *alias);
162 void allow_access(const char* alias, const char* accessor, int permissionMask);
163 void allow_access_negative(const char* alias, const char* accessor, int permissionMask, int expectedCode);
164 void deny_access(const char* alias, const char* accessor);
165 void deny_access_negative(const char* alias, const char* accessor, int expectedCode);
167 void unlock_user_data(uid_t user_id, const char *passwd);
168 void remove_user_data(uid_t user_id);
169 void reset_user_data(uid_t user_id, const char *passwd);
171 ckmc_raw_buffer_s prepare_message_buffer(const char * input);
172 void check_alias_list(const CKM::AliasVector& expected);
179 size_t count_aliases(alias_type_ type, size_t minimum_initial_element_count = 0);
180 std::string sharedDatabase(const CKM::Alias & alias);
182 // Test env class for database cleanup. Pass database uids to cleanup before and after test
183 template <uid_t ...Args>
187 class RemoveDataEnv<>
190 void init(const std::string&)
196 template <uid_t UID, uid_t ...Args>
197 class RemoveDataEnv<UID, Args...> : public RemoveDataEnv<Args...>
200 void init(const std::string & str) {
201 remove_user_data(UID);
202 RemoveDataEnv<Args...>::init(str);
205 RemoveDataEnv<Args...>::finish();
206 remove_user_data(UID);