1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16 #include <string>
17 #include <vector>
18 #include "distributed_device_profile_client.h"
19 #include "distributed_device_profile_constants.h"
20 #include "distributed_device_profile_errors.h"
21
22 #include "session_key_manager.h"
23
24 using namespace testing::ext;
25 namespace OHOS {
26 namespace DistributedDeviceProfile {
27 using namespace std;
28 namespace {
29 const std::string TAG = "SessionKeyManagerTest";
30 int32_t g_sessionKeyId = 0;
31 }
32
33 class SessionKeyManagerTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 };
40
SetUpTestCase()41 void SessionKeyManagerTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void SessionKeyManagerTest::TearDownTestCase()
46 {
47 }
48
SetUp()49 void SessionKeyManagerTest::SetUp()
50 {
51 }
52
TearDown()53 void SessionKeyManagerTest::TearDown()
54 {
55 }
56
57 /*
58 * @tc.name: PutSessionKey001
59 * @tc.desc: PutSessionKey
60 * @tc.type: FUNC
61 * @tc.require:
62 */
63 HWTEST_F(SessionKeyManagerTest, PutSessionKey001, TestSize.Level1)
64 {
65 uint32_t userId = 100;
66 std::vector<uint8_t> sessionKey;
67 sessionKey.emplace_back(1);
68 sessionKey.emplace_back(2);
69 sessionKey.emplace_back(3);
70 sessionKey.emplace_back(4);
71 sessionKey.emplace_back(5);
72 int32_t ret = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient::
73 GetInstance().PutSessionKey(userId, sessionKey, g_sessionKeyId);
74 EXPECT_NE(ret, DP_SUCCESS);
75 }
76
77 /*
78 * @tc.name: PutSessionKey002
79 * @tc.desc: PutSessionKey
80 * @tc.type: FUNC
81 * @tc.require:
82 */
83 HWTEST_F(SessionKeyManagerTest, PutSessionKey002, TestSize.Level1)
84 {
85 uint32_t userId = 100;
86 std::vector<uint8_t> sessionKey;
87 sessionKey.emplace_back(1);
88 sessionKey.emplace_back(2);
89 sessionKey.emplace_back(3);
90 sessionKey.emplace_back(4);
91 sessionKey.emplace_back(5);
92 int32_t ret = SessionKeyManager::GetInstance().PutSessionKey(userId, sessionKey, g_sessionKeyId);
93 EXPECT_NE(ret, DP_SUCCESS);
94 }
95
96 /*
97 * @tc.name: PutSessionKey003
98 * @tc.desc: PutSessionKey
99 * @tc.type: FUNC
100 * @tc.require:
101 */
102 HWTEST_F(SessionKeyManagerTest, PutSessionKey003, TestSize.Level1)
103 {
104 uint32_t userId = 0;
105 std::vector<uint8_t> sessionKey;
106 sessionKey.emplace_back(1);
107 sessionKey.emplace_back(2);
108 sessionKey.emplace_back(3);
109 sessionKey.emplace_back(4);
110 sessionKey.emplace_back(5);
111 int32_t ret = SessionKeyManager::GetInstance().PutSessionKey(userId, sessionKey, g_sessionKeyId);
112 EXPECT_EQ(ret, DP_INVALID_PARAMS);
113 }
114
115 /*
116 * @tc.name: GetSessionKey001
117 * @tc.desc: GetSessionKey
118 * @tc.type: FUNC
119 * @tc.require:
120 */
121 HWTEST_F(SessionKeyManagerTest, GetSessionKey001, TestSize.Level1)
122 {
123 uint32_t userId = 100;
124 std::vector<uint8_t> sessionKey;
125 int32_t ret = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient::
126 GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
127 EXPECT_NE(ret, DP_SUCCESS);
128 }
129
130 /*
131 * @tc.name: GetSessionKey004
132 * @tc.desc: GetSessionKey
133 * @tc.type: FUNC
134 * @tc.require:
135 */
136 HWTEST_F(SessionKeyManagerTest, GetSessionKey004, TestSize.Level1)
137 {
138 uint32_t userId = 100;
139 std::vector<uint8_t> sessionKey;
140 int32_t ret = SessionKeyManager::GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
141 EXPECT_NE(ret, DP_SUCCESS);
142 }
143
144 /*
145 * @tc.name: UpdateSessionKey001
146 * @tc.desc: UpdateSessionKey
147 * @tc.type: FUNC
148 * @tc.require:
149 */
150 HWTEST_F(SessionKeyManagerTest, UpdateSessionKey001, TestSize.Level1)
151 {
152 uint32_t userId = 100;
153 std::vector<uint8_t> sessionKey;
154 sessionKey.emplace_back(6);
155 sessionKey.emplace_back(7);
156 sessionKey.emplace_back(8);
157 sessionKey.emplace_back(9);
158 sessionKey.emplace_back(10);
159 int32_t ret = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient::
160 GetInstance().UpdateSessionKey(userId, g_sessionKeyId, sessionKey);
161 EXPECT_NE(ret, DP_SUCCESS);
162 }
163
164 /*
165 * @tc.name: UpdateSessionKey002
166 * @tc.desc: UpdateSessionKey
167 * @tc.type: FUNC
168 * @tc.require:
169 */
170 HWTEST_F(SessionKeyManagerTest, UpdateSessionKey002, TestSize.Level1)
171 {
172 uint32_t userId = 100;
173 std::vector<uint8_t> sessionKey;
174 sessionKey.emplace_back(6);
175 sessionKey.emplace_back(7);
176 sessionKey.emplace_back(8);
177 sessionKey.emplace_back(9);
178 sessionKey.emplace_back(10);
179 int32_t ret = SessionKeyManager::GetInstance().UpdateSessionKey(userId, g_sessionKeyId, sessionKey);
180 EXPECT_NE(ret, DP_SUCCESS);
181 }
182
183 /*
184 * @tc.name: UpdateSessionKey003
185 * @tc.desc: UpdateSessionKey
186 * @tc.type: FUNC
187 * @tc.require:
188 */
189 HWTEST_F(SessionKeyManagerTest, UpdateSessionKey003, TestSize.Level1)
190 {
191 uint32_t userId = 0;
192 std::vector<uint8_t> sessionKey;
193 sessionKey.emplace_back(6);
194 sessionKey.emplace_back(7);
195 sessionKey.emplace_back(8);
196 sessionKey.emplace_back(9);
197 sessionKey.emplace_back(10);
198 int32_t ret = SessionKeyManager::GetInstance().UpdateSessionKey(userId, g_sessionKeyId, sessionKey);
199 EXPECT_EQ(ret, DP_INVALID_PARAMS);
200 }
201
202 /*
203 * @tc.name: GetSessionKey002
204 * @tc.desc: GetSessionKey
205 * @tc.type: FUNC
206 * @tc.require:
207 */
208 HWTEST_F(SessionKeyManagerTest, GetSessionKey002, TestSize.Level1)
209 {
210 uint32_t userId = 100;
211 std::vector<uint8_t> sessionKey;
212 int32_t ret = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient::
213 GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
214 EXPECT_NE(ret, DP_SUCCESS);
215 }
216
217 /*
218 * @tc.name: GetSessionKey005
219 * @tc.desc: GetSessionKey
220 * @tc.type: FUNC
221 * @tc.require:
222 */
223 HWTEST_F(SessionKeyManagerTest, GetSessionKey005, TestSize.Level1)
224 {
225 uint32_t userId = 100;
226 std::vector<uint8_t> sessionKey;
227 int32_t ret = SessionKeyManager::GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
228 EXPECT_NE(ret, DP_SUCCESS);
229 }
230
231 /*
232 * @tc.name: DeleteSessionKey001
233 * @tc.desc: DeleteSessionKey
234 * @tc.type: FUNC
235 * @tc.require:
236 */
237 HWTEST_F(SessionKeyManagerTest, DeleteSessionKey001, TestSize.Level1)
238 {
239 uint32_t userId = 100;
240 int32_t ret = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient::
241 GetInstance().DeleteSessionKey(userId, g_sessionKeyId);
242 EXPECT_NE(ret, DP_SUCCESS);
243 }
244
245 /*
246 * @tc.name: DeleteSessionKey002
247 * @tc.desc: DeleteSessionKey
248 * @tc.type: FUNC
249 * @tc.require:
250 */
251 HWTEST_F(SessionKeyManagerTest, DeleteSessionKey002, TestSize.Level1)
252 {
253 uint32_t userId = 100;
254 int32_t ret = SessionKeyManager::GetInstance().DeleteSessionKey(userId, g_sessionKeyId);
255 EXPECT_NE(ret, DP_SUCCESS);
256 }
257
258 /*
259 * @tc.name: DeleteSessionKey003
260 * @tc.desc: DeleteSessionKey
261 * @tc.type: FUNC
262 * @tc.require:
263 */
264 HWTEST_F(SessionKeyManagerTest, DeleteSessionKey003, TestSize.Level1)
265 {
266 uint32_t userId = 0;
267 int32_t ret = SessionKeyManager::GetInstance().DeleteSessionKey(userId, g_sessionKeyId);
268 EXPECT_EQ(ret, DP_INVALID_PARAMS);
269 }
270
271 /*
272 * @tc.name: GetSessionKey003
273 * @tc.desc: GetSessionKey
274 * @tc.type: FUNC
275 * @tc.require:
276 */
277 HWTEST_F(SessionKeyManagerTest, GetSessionKey003, TestSize.Level1)
278 {
279 uint32_t userId = 100;
280 std::vector<uint8_t> sessionKey;
281 int32_t ret = OHOS::DistributedDeviceProfile::DistributedDeviceProfileClient::
282 GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
283 EXPECT_NE(ret, DP_SUCCESS);
284 }
285
286 /*
287 * @tc.name: GetSessionKey006
288 * @tc.desc: GetSessionKey
289 * @tc.type: FUNC
290 * @tc.require:
291 */
292 HWTEST_F(SessionKeyManagerTest, GetSessionKey006, TestSize.Level1)
293 {
294 uint32_t userId = 100;
295 std::vector<uint8_t> sessionKey;
296 int32_t ret = SessionKeyManager::GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
297 EXPECT_NE(ret, DP_SUCCESS);
298 }
299
300 /*
301 * @tc.name: GetSessionKey007
302 * @tc.desc: GetSessionKey
303 * @tc.type: FUNC
304 * @tc.require:
305 */
306 HWTEST_F(SessionKeyManagerTest, GetSessionKey007, TestSize.Level1)
307 {
308 uint32_t userId = 0;
309 std::vector<uint8_t> sessionKey;
310 int32_t ret = SessionKeyManager::GetInstance().GetSessionKey(userId, g_sessionKeyId, sessionKey);
311 EXPECT_EQ(ret, DP_INVALID_PARAMS);
312 }
313 }
314 }
315