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)
25 #include <unordered_set>
27 #include <ckm/ckm-type.h>
28 #include <ckmc/ckmc-type.h>
29 #include <ckmc/ckmc-error.h>
30 #include <tests_common.h>
31 #include <sys/types.h>
33 void switch_to_storage_user(const char* label);
34 void switch_to_storage_ocsp_user(const char* label);
37 // RUNNER_ASSERT wrappers
38 template <typename F, typename... Args>
39 void assert_result(int expected, F&& func, Args... args)
41 int ret = func(args...);
42 RUNNER_ASSERT_MSG(ret == expected, "Expected " << expected << " got: " << ret);
45 template <typename F, typename... Args>
46 void assert_positive(F&& func, Args... args)
48 assert_result(CKMC_ERROR_NONE, std::move(func), args...);
51 template <typename F, typename... Args>
52 void assert_invalid_param(F&& func, Args... args)
54 assert_result(CKMC_ERROR_INVALID_PARAMETER, std::move(func), args...);
60 size_t list_size(const T* list)
71 // service lifecycle management
76 void start_service(ServiceIdx idx);
77 void stop_service(ServiceIdx idx);
79 // support for error printing
80 const char * CKMCErrorToString(int error);
81 std::string CKMCReadableError(int error);
83 // Class responsible for db cleanup after positive tests. Will remove all used aliases in destructor
89 const char* alias(const char* alias)
91 return m_aliases.insert(CKM::Alias(alias)).first->c_str();
97 std::unordered_set<CKM::Alias> m_aliases;
101 typedef std::unique_ptr<char, void (*)(void *)> CharPtr;
103 // returns process label
106 std::string aliasWithLabel(const char *label, const char *alias);
108 // changes process label
109 void change_label(const char* label);
111 // changes process label upon construction and restores it upon destruction
115 ScopedLabel(const char* label);
119 CharPtr m_original_label;
122 void save_data(const char* alias, const char *data, int expected_err = CKMC_ERROR_NONE);
126 ScopedSaveData(const char* alias, const char *data, int expected_err = CKMC_ERROR_NONE);
127 virtual ~ScopedSaveData();
133 class GarbageCollector
136 void save(const char* alias, const char *data, int expected_err = CKMC_ERROR_NONE);
137 virtual ~GarbageCollector();
141 std::string item_alias;
142 std::string owner_label;
146 std::vector<save_item> m_garbage;
152 ScopedDBUnlock(uid_t user_id, const char* passwd);
153 virtual ~ScopedDBUnlock();
159 void check_remove_allowed(const char* alias);
160 void check_remove_denied(const char* alias);
161 void check_remove_not_visible(const char* alias);
162 void check_read(const char* alias, const char *label, const char *test_data, int expected_code = CKMC_ERROR_NONE);
163 void check_read_allowed(const char* alias, const char *data);
164 void check_read_not_visible(const char* alias);
165 void allow_access(const char* alias, const char* accessor, int permissionMask);
166 void allow_access_negative(const char* alias, const char* accessor, int permissionMask, int expectedCode);
167 void deny_access(const char* alias, const char* accessor);
168 void deny_access_negative(const char* alias, const char* accessor, int expectedCode);
170 void unlock_user_data(uid_t user_id, const char *passwd);
171 void remove_user_data(uid_t user_id);
172 void reset_user_data(uid_t user_id, const char *passwd);
174 ckmc_raw_buffer_s prepare_message_buffer(const char * input);
175 void check_alias_list(const CKM::AliasVector& expected);