2 * Copyright (c) 2015 - 2019 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 Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 #include <sys/types.h>
24 #include <ckm-common.h>
26 #include <dpl/test/test_runner.h>
27 #include <dpl/test/test_runner_child.h>
29 #include <ckm/ckm-manager.h>
30 #include <ckm/ckm-control.h>
31 #include <ckm/ckm-password.h>
32 #include <ckm/ckm-type.h>
34 #include <ckm-policy.h>
36 typedef ProcessSettings::Executor<
38 ProcessSettings::CreateUser,
39 ProcessSettings::UnlockCkm,
40 ProcessSettings::InstallApp,
41 ProcessSettings::ChangeSmack,
42 ProcessSettings::ChangeUid> PS;
44 typedef ProcessSettings::Executor<
46 ProcessSettings::CreateUser,
47 ProcessSettings::UnlockCkm,
48 ProcessSettings::InstallApp,
49 ProcessSettings::ChangeSmack> PSNoUid;
51 typedef ProcessSettings::Executor<
53 ProcessSettings::ChangeUid> PSUid;
55 RUNNER_TEST_GROUP_INIT(GROUP_02_IntegrationStorageApiWithCynara);
57 RUNNER_CHILD_TEST(G02T01_StorageNegative) {
58 RUNNER_IGNORED_MSG("Cynara integration with CKM Storage API was canceled.");
59 // We are ordinary user without any privileges.
60 // Cynara should deny all accesses.
61 PS ps("PkgIdG02T01", "UserG02T01", PrivNone);
65 auto manager = CKM::Manager::create();
66 std::string data = "Custom data";
67 CKM::RawBuffer rawBuffer(data.begin(), data.end());
68 CKM::RawBuffer output;
69 const char *alias = "dataG02T01";
72 CKM_API_ERROR_ACCESS_DENIED == (temp = manager->saveData(alias, rawBuffer, CKM::Policy())),
73 "Error=" << CKM::APICodeToString(temp));
76 CKM_API_ERROR_ACCESS_DENIED == (temp = manager->getData(alias, CKM::Password(), output)),
77 "Error=" << CKM::APICodeToString(temp));
80 RUNNER_CHILD_TEST(G02T02_StoragePositive) {
81 RUNNER_IGNORED_MSG("Cynara integration with CKM Storage API was canceled.");
82 // We are root. We will be allowed.
84 auto manager = CKM::Manager::create();
85 std::string data = "Custom data";
86 CKM::RawBuffer rawBuffer(data.begin(), data.end());
87 CKM::RawBuffer output;
88 const char *alias = "/System dataG02T02";
90 // This funciton may return error.
91 manager->removeAlias(alias);
94 CKM_API_SUCCESS == (temp = manager->saveData(alias, rawBuffer, CKM::Policy())),
95 "Error=" << CKM::APICodeToString(temp));
98 CKM_API_SUCCESS == (temp = manager->getData(alias, CKM::Password(), output)),
99 "Error=" << CKM::APICodeToString(temp));
101 RUNNER_ASSERT_MSG(rawBuffer == output, "Data mismatch.");
104 RUNNER_CHILD_TEST(G02T03_StoragePositive) {
105 RUNNER_IGNORED_MSG("Cynara integration with CKM Storage API was canceled.");
106 // We are oridinary user with proper privileges.
107 PS ps("PkgIdG02T03", "UserG02T03", PrivCKMStore);
111 auto manager = CKM::Manager::create();
112 std::string data = "Custom data";
113 CKM::RawBuffer rawBuffer(data.begin(), data.end());
114 CKM::RawBuffer output;
115 const char *dataAlias = "dataG02T03";
118 CKM_API_SUCCESS == (temp = manager->saveData(dataAlias, rawBuffer, CKM::Policy())),
119 "Error=" << CKM::APICodeToString(temp));
122 CKM_API_SUCCESS == (temp = manager->getData(dataAlias, CKM::Password(), output)),
123 "Error=" << CKM::APICodeToString(temp));
125 RUNNER_ASSERT_MSG(rawBuffer == output, "Data mismatch.");
128 RUNNER_CHILD_TEST(G02T04_StorageNegative) {
129 RUNNER_IGNORED_MSG("Cynara integration with CKM Storage API was canceled.");
130 // There is some user with privileges but we are
131 // are ordinary user without any.
132 // Cynara should deny all accesses.
133 PSNoUid ps("PkgIdG02T04", "UserG02T04", PrivCKMBoth);
136 PSUid ps2("", "", PrivNone);
137 ps2.SetUid(ps.GetUid()+1);
141 auto manager = CKM::Manager::create();
142 std::string data = "Custom data";
143 CKM::RawBuffer rawBuffer(data.begin(), data.end());
144 CKM::RawBuffer output;
145 const char *alias = "dataG02T04";
148 CKM_API_ERROR_ACCESS_DENIED == (temp = manager->saveData(alias, rawBuffer, CKM::Policy())),
149 "Error=" << CKM::APICodeToString(temp));
152 CKM_API_ERROR_ACCESS_DENIED == (temp = manager->getData(alias, CKM::Password(), output)),
153 "Error=" << CKM::APICodeToString(temp));
156 RUNNER_CHILD_TEST(G02T05_StorageNegative) {
157 RUNNER_IGNORED_MSG("Cynara integration with CKM Storage API was canceled.");
158 // We have wrong privilege.
159 // Cynara should deny all accesses to storage.
160 PSNoUid ps("PkgIdG02T05", "UserG02T05", PrivCKMControl);
164 auto manager = CKM::Manager::create();
165 std::string data = "Custom data";
166 CKM::RawBuffer rawBuffer(data.begin(), data.end());
167 CKM::RawBuffer output;
168 const char *alias = "dataG02T05";
171 CKM_API_ERROR_ACCESS_DENIED == (temp = manager->saveData(alias, rawBuffer, CKM::Policy())),
172 "Error=" << CKM::APICodeToString(temp));
175 CKM_API_ERROR_ACCESS_DENIED == (temp = manager->getData(alias, CKM::Password(), output)),
176 "Error=" << CKM::APICodeToString(temp));