2 * Copyright (c) 2011 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.
17 * @file test_cases.cpp
18 * @author Tonasz Swierczek (t.swierczek@samsung.com)
20 * @brief Implementation file for ACE install test cases.
25 #include <dpl/test/test_runner.h>
26 #include <dpl/log/log.h>
28 #include "ace_api_install.h"
29 #include "widget_installer.h"
30 #include <ace-dao-ro/AceDAOReadOnly.h>
32 RUNNER_TEST_GROUP_INIT(ACE_INSTALL_TEST_SUITE)
35 * test author: Tomasz Swierczek (t.swierczek@samsung.com)
36 * tested functions: ace_install_initialize(),
37 * ace_install_shutdown()
38 * purpose: New C-API tests. Tests proper initialization and deinitialization
39 * of ace-install library.
41 RUNNER_TEST(ace_install_test_01_initialization)
43 RUNNER_ASSERT(ACE_OK == ace_install_initialize());
44 RUNNER_ASSERT(ACE_OK == ace_install_shutdown());
45 RUNNER_ASSERT(ACE_OK == ace_install_initialize());
49 * test author: Tomasz Swierczek (t.swierczek@samsung.com)
50 * tested functions: ace_update_policy()
51 * purpose: New C-API tests. Tests proper policy re-parsing many times in a row.
53 RUNNER_TEST(ace_install_test_02_policy_update)
55 RUNNER_ASSERT(ACE_OK == ace_update_policy());
56 RUNNER_ASSERT(ACE_OK == ace_update_policy());
57 RUNNER_ASSERT(ACE_OK == ace_update_policy());
62 * test author: Tomasz Swierczek (t.swierczek@samsung.com)
63 * tested functions: ace_set_requested_dev_caps(),
64 * ace_get_requested_dev_caps(), ace_free_requested_dev_caps()
65 * purpose: New C-API tests. Tests proper setting and getting widget dev caps
68 RUNNER_TEST(ace_install_test_03_requested_dev_caps)
70 ace_widget_handle_t handle = InstallerMockup::registerWidget();
71 ace_requested_dev_cap_t reqDevCaps[2];
72 reqDevCaps[0].device_capability = "dev-cap1";
73 reqDevCaps[0].smack_granted = ACE_TRUE;
74 reqDevCaps[1].device_capability = "dev-cap2";
75 reqDevCaps[1].smack_granted = ACE_FALSE;
76 ace_requested_dev_cap_list_t caps;
78 caps.items = reqDevCaps;
79 RUNNER_ASSERT(ACE_OK == ace_set_requested_dev_caps(handle, &caps));
80 ace_requested_dev_cap_list_t capsGotFromDB;
81 RUNNER_ASSERT(ACE_OK == ace_get_requested_dev_caps(handle, &capsGotFromDB));
82 RUNNER_ASSERT(capsGotFromDB.count == caps.count);
84 bool one = false, two = false;
85 for (i = 0; i < capsGotFromDB.count; ++i) {
86 if (0 == strcmp(capsGotFromDB.items[i].device_capability,
87 caps.items[0].device_capability)) {
88 RUNNER_ASSERT(capsGotFromDB.items[i].smack_granted ==
89 caps.items[0].smack_granted);
92 RUNNER_ASSERT(capsGotFromDB.items[i].smack_granted ==
93 caps.items[1].smack_granted);
94 RUNNER_ASSERT(0 == strcmp(capsGotFromDB.items[i].device_capability,
95 caps.items[1].device_capability));
99 RUNNER_ASSERT(one && two);
100 RUNNER_ASSERT(ACE_OK == ace_free_requested_dev_caps(&capsGotFromDB));
104 * test author: Andrzej Surdej (a.surdej@gmail.com)
105 * tested functions: ace_register_widget(),
106 * ace_unregister_widget()
107 * purpose: New C-API tests. Tests proper setting and getting widget info.
110 int widgetHandle = 1000;
111 std::string testAuthor = "someAwesomeProgrammer;)";
112 std::string testVersion = "1.1.1R";
113 std::string widgetGuid = "http://widgets.org/myTestWidget";
114 std::string widgetShareHref = "http://shareWithOtherNiggers.ny.wrong";
119 * test: ace_register_widget(), ace_unregister_widget()
120 * description: Try to install and uninstall widget with all correct info.
121 * expect: widget should be installed and uninstalled correctly.
123 RUNNER_TEST(ace_install_test_04_correct_widget_info)
125 struct widget_info info;
126 info.author = strdup(testAuthor.c_str());
127 info.id = strdup(widgetGuid.c_str());
129 info.version = strdup(testVersion.c_str());
130 info.shareHerf = strdup(widgetShareHref.c_str());
132 ace_return_t retValue = ace_register_widget(widgetHandle, &info, NULL);
134 //clean up before asserts
138 free(info.shareHerf);
140 RUNNER_ASSERT(ACE_OK == retValue);
141 RUNNER_ASSERT(AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
143 std::string gotVersion = AceDB::AceDAOReadOnly::getVersion(widgetHandle);
144 RUNNER_ASSERT(gotVersion == testVersion);
146 std::string gotGuid = AceDB::AceDAOReadOnly::getGUID(widgetHandle);
147 RUNNER_ASSERT(gotGuid == widgetGuid);
149 std::string gotShareHref = AceDB::AceDAOReadOnly::getShareHref(widgetHandle);
150 RUNNER_ASSERT(gotShareHref == widgetShareHref);
152 RUNNER_ASSERT(AceDB::AceDAOReadOnly::getWidgetType(widgetHandle) == AppTypes::WAC20);
153 RUNNER_ASSERT(AceDB::AceDAOReadOnly::getAuthorName(widgetHandle) == testAuthor);
155 RUNNER_ASSERT(ACE_OK == ace_unregister_widget(widgetHandle));
156 RUNNER_ASSERT(!AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
161 * test: ace_register_widget(), ace_unregister_widget()
162 * description: Negative test. NULL widget data passed.
163 * expect: Widget should not be installed.
165 RUNNER_TEST(ace_install_test_06_wrong_widget_info)
167 ace_return_t retVal = ace_register_widget(widgetHandle, NULL, NULL);
168 RUNNER_ASSERT(retVal != ACE_OK);
169 RUNNER_ASSERT(!AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
171 ace_unregister_widget(widgetHandle);
176 * test: ace_register_widget(), ace_unregister_widget()
177 * description: Check if the same widget can be installed twice.
178 * expect: First widget should be installed, second widget should NOT be installed.
180 RUNNER_TEST(ace_install_test_07_twins)
182 struct widget_info info;
183 info.author = strdup(testAuthor.c_str());
184 info.id = strdup(widgetGuid.c_str());
186 info.version = strdup(testVersion.c_str());
187 info.shareHerf = strdup(widgetShareHref.c_str());
189 ace_return_t retValue = ace_register_widget(widgetHandle, &info, NULL);
191 //clean up before asserts
195 free(info.shareHerf);
197 RUNNER_ASSERT(ACE_OK == retValue);
198 RUNNER_ASSERT(AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
200 retValue = ace_register_widget(widgetHandle, &info, NULL);
201 RUNNER_ASSERT(ACE_OK != retValue);
203 RUNNER_ASSERT(AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
204 ace_unregister_widget(widgetHandle);
209 * test: ace_register_widget(), got***.empty(), getWidgetType(), ace_unregister_widget()
210 * description: Installing Widget with NULL info
211 * expect: Widget should be installed, all data about widget should be empty.
213 RUNNER_TEST(ace_install_test_08_empty_values)
215 struct widget_info info;
220 info.shareHerf = NULL;
222 ace_return_t retValue = ace_register_widget(widgetHandle, &info, NULL);
224 //clean up before asserts
228 free(info.shareHerf);
230 RUNNER_ASSERT(ACE_OK == retValue);
231 RUNNER_ASSERT(AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
233 std::string gotAuthor = AceDB::AceDAOReadOnly::getAuthorName(widgetHandle);
234 RUNNER_ASSERT(gotAuthor.empty());
236 std::string gotVersion = AceDB::AceDAOReadOnly::getVersion(widgetHandle);
237 RUNNER_ASSERT(gotVersion.empty());
239 std::string gotGuid = AceDB::AceDAOReadOnly::getGUID(widgetHandle);
240 RUNNER_ASSERT(gotGuid.empty());
242 std::string gotShareHref = AceDB::AceDAOReadOnly::getShareHref(widgetHandle);
243 RUNNER_ASSERT(gotShareHref.empty());
245 RUNNER_ASSERT(AceDB::AceDAOReadOnly::getWidgetType(widgetHandle) == AppTypes::Tizen);
247 RUNNER_ASSERT(ACE_OK == ace_unregister_widget(widgetHandle));
248 RUNNER_ASSERT(!AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
253 std::string commonName0 = "commonNameForZeroElement";
254 std::string md50 = "md5CertificateForZeroElement";
255 std::string sha0 = "shaCertificateForZeroElement";
256 ace_cert_owner_t owner0 = AUTHOR;
257 ace_cert_type_t type0 = ENDENTITY;
260 std::string commonName1 = "commonNameForFirstElement";
261 std::string md51 = "md5CertificateForFirstElement";
262 std::string sha1 = "shaCertificateForFirstElement";
263 ace_cert_owner_t owner1 = AUTHOR;
264 ace_cert_type_t type1 = ENDENTITY;
267 std::string commonName2 = "commonNameForSecondElement";
268 std::string md52 = "md5CertificateForSecondElement";
269 std::string sha2 = "shaCertificateForSecondElement";
270 ace_cert_owner_t owner2 = DISTRIBUTOR;
271 ace_cert_type_t type2 = ROOT;
276 * test: ace_register_widget(), getKeyCommonNameList(), getKeyFingerprints()
277 * description: Check if certificate verification works well while widget installing. Also check saved certificate data.
278 * expect: Widget should be installed properly, all data from certificate should match.
280 RUNNER_TEST(ace_install_test_09_certificate_list)
282 struct widget_info info;
287 info.shareHerf = NULL;
289 ace_certificate_data** certList = new ace_certificate_data*[4];
290 certList[3] = NULL; //last element
292 for (int i = 0; i < 3; ++i) {
293 certList[i] = new ace_certificate_data;
295 certList[0]->chain_id = chaniId0;
296 certList[0]->common_name = strdup(commonName0.c_str());
297 certList[0]->md5_fp = strdup(md50.c_str());
298 certList[0]->sha1_fp = strdup(sha0.c_str());
299 certList[0]->owner = owner0;
300 certList[0]->type = type0;
302 certList[1]->chain_id = chaniId1;
303 certList[1]->common_name = strdup(commonName1.c_str());
304 certList[1]->md5_fp = strdup(md51.c_str());
305 certList[1]->sha1_fp = strdup(sha1.c_str());
306 certList[1]->owner = owner1;
307 certList[1]->type = type1;
309 certList[2]->chain_id = chaniId2;
310 certList[2]->common_name = strdup(commonName2.c_str());
311 certList[2]->md5_fp = strdup(md52.c_str());
312 certList[2]->sha1_fp = strdup(sha2.c_str());
313 certList[2]->owner = owner2;
314 certList[2]->type = type2;
316 ace_return_t retValue = ace_register_widget(widgetHandle, &info, certList);
318 //clean up before asserts
322 free(info.shareHerf);
323 for (int i = 0; i < 3; ++i) {
324 free(certList[i]->common_name);
325 free(certList[i]->md5_fp);
326 free(certList[i]->sha1_fp);
331 RUNNER_ASSERT(ACE_OK == retValue);
332 RUNNER_ASSERT(AceDB::AceDAOReadOnly::isWidgetInstalled(widgetHandle));
334 WidgetCertificateCNList commonNameList =
335 AceDB::AceDAOReadOnly::getKeyCommonNameList(widgetHandle,
336 WidgetCertificateData::AUTHOR,
337 WidgetCertificateData::ENDENTITY);
338 RUNNER_ASSERT(2 == commonNameList.size());
339 RUNNER_ASSERT(commonName0 == commonNameList.front() ||
340 commonName0 == commonNameList.back());
341 RUNNER_ASSERT(commonName1 == commonNameList.front() ||
342 commonName1 == commonNameList.back());
343 commonNameList.clear();
345 AceDB::AceDAOReadOnly::getKeyCommonNameList(widgetHandle,
346 WidgetCertificateData::DISTRIBUTOR,
347 WidgetCertificateData::ROOT);
348 RUNNER_ASSERT(1 == commonNameList.size());
349 RUNNER_ASSERT(commonName2 == commonNameList.front());
351 FingerPrintList fpList =
352 AceDB::AceDAOReadOnly::getKeyFingerprints(widgetHandle,
353 WidgetCertificateData::AUTHOR,
354 WidgetCertificateData::ENDENTITY);
355 RUNNER_ASSERT(4 == fpList.size());
359 AceDB::AceDAOReadOnly::getKeyFingerprints(widgetHandle,
360 WidgetCertificateData::DISTRIBUTOR,
361 WidgetCertificateData::ROOT);
362 RUNNER_ASSERT(2 == fpList.size());
364 ace_unregister_widget(widgetHandle);
368 * test author: Tomasz Swierczek (t.swierczek@samsung.com)
369 * tested functions: ace_get_policy_result()
370 * purpose: New C-API tests. Tests proper policy evaluation by security daemon
371 * and successful passing data to ace-install library. For three calls,
372 * three results are expected: ACE_PERMIT, ACE_DENY and ACE_PROMPT.
374 RUNNER_TEST(ace_install_test_10_policy_results)
376 ace_widget_handle_t handle = InstallerMockup::registerWidget();
377 ace_resource_t resourceA = "resourcePermit";
378 ace_resource_t resourceB = "resourceDeny";
379 ace_resource_t resourceC = "resourcePrompt";
380 ace_policy_result_t result = ACE_UNDEFINED;
381 RUNNER_ASSERT(ACE_OK == ace_get_policy_result(resourceA,
384 RUNNER_ASSERT(ACE_PERMIT == result);
385 RUNNER_ASSERT(ACE_OK == ace_get_policy_result(resourceB,
388 RUNNER_ASSERT(ACE_DENY == result);
389 RUNNER_ASSERT(ACE_OK == ace_get_policy_result(resourceC,
392 RUNNER_ASSERT(ACE_PROMPT == result);