1 /*
2 * Copyright (c) 2021-2023 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
16 #include <gtest/gtest.h>
17 #define private public
18 #include "account_log_wrapper.h"
19 #include "os_account_info.h"
20 #include "os_account_manager.h"
21 #include "os_account_constants.h"
22 #undef private
23
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::AccountSA;
27
28 namespace {
29 const int INT_ID = 12;
30 const std::string STRING_NAME = "account";
31 const std::string OVER_LENGTH_ACCOUNT_NAME(Constants::LOCAL_NAME_MAX_SIZE + 1, '1');
32 const OsAccountType INT_TYPE = OsAccountType::ADMIN;
33 const int64_t STRING_SERIAL_NUMBER = 121012012;
34 constexpr std::int32_t UID_TRANSFORM_DIVISOR = 200000;
35 const int32_t ROOT_UID = 0;
36 const int32_t TEST_UID = 100;
37 const std::vector<std::string> VECTOR_CONSTRAINTS {"one", "two", "three", "four", "five"};
38 const bool BOOL_IS_OS_ACCOUNT_VERIFIED = true;
39 const bool BOOL_IS_OS_ACCOUNT_COMPLETED = true;
40 const bool BOOL_IS_ACTIVED = true;
41 #ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
42 const int32_t CREATE_LOCAL_ID = 121;
43 #endif // ENABLE_MULTIPLE_OS_ACCOUNTS
44 const std::string OVER_LENGTH_NAME =
45 "EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYX**E||TIj::KBCB??BAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQyerewewgZG"
46 "RCk11aGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSfggdfghBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQ1ygZG"
47 "lNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIW<<Gh>>adsfasBAMFBQQEAAABfQECAwAEEQUwewrewrwrwerSITFBBhNRYQcicRwerQygZGfafd"
48 "4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5w+BAMFBQQEAAABfQECAwAEEQTFBBhNYQcicRQygZG"
49 "jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A++fid8e7j4ZiYXHgDxBfN5jJayQ3werwrwrwrwwerOnBLsKQGdF+1GbYAwJJsdfgsdfgi4yN2M1seF";
50 const std::string STRING_PHOTO =
51 "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gAUU29mdHdhcmU6IFNuaXBhc3Rl/"
52 "9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/"
53 "9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/"
54 "8AAEQgAEgAOAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//"
55 "EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU"
56 "1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6On"
57 "q8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//"
58 "EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJS"
59 "lNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+"
60 "jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A++fid8e7j4ZiYXHgDxBfN5jJayQ3OnBLsKQGdF+1GbYAwJJi4yN2M1seF/"
61 "i+fEtnHfv4O8R6dpcoby75ltLxHcNtMeyzuJ5FYEMDuQBSpUkNgH5l+Ndx4XtPix4ik0/"
62 "xFpssN5bwwXwPilDIZ0klLxSq2vWLAIWACMjBeilQNo6j9ni50R9U8U6lF400m18Q30sTMLnxC1758CxqrO8EesXXzBgiiV5SQPlCgHnNSfI5f1+"
63 "av33Q5L3rdP68nb7mfWlFFFaCP//Z";
64 const int64_t INT_CREATE_TIME = 1551925510;
65 const int64_t INT_LAST_LOGINGGED_IN_TIME = 1551925510;
66 const std::string STRING_JSON =
67 "{\"constraints\":[\"one\",\"two\",\"three\",\"four\",\"five\"],\"createTime\":1551925510,\"domainInfo\":{"
68 "\"accountName\":\"\",\"domain\":\"\"},\"isActived\":false,"
69 "\"isCreateCompleted\":true,\"isVerified\":true,\"lastLoginTime\":1551925510,\"localId\":12,\"localName\":"
70 "\"account\",\"photo\":\"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gAUU29mdHdhcmU6IFNuaXBhc3Rl/"
71 "9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/"
72 "9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/"
73 "8AAEQgAEgAOAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//"
74 "EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU"
75 "1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6On"
76 "q8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//"
77 "EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJS"
78 "lNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+"
79 "jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A++fid8e7j4ZiYXHgDxBfN5jJayQ3OnBLsKQGdF+1GbYAwJJi4yN2M1seF/"
80 "i+fEtnHfv4O8R6dpcoby75ltLxHcNtMeyzuJ5FYEMDuQBSpUkNgH5l+Ndx4XtPix4ik0/"
81 "xFpssN5bwwXwPilDIZ0klLxSq2vWLAIWACMjBeilQNo6j9ni50R9U8U6lF400m18Q30sTMLnxC1758CxqrO8EesXXzBgiiV5SQPlCgHnNSfI5f1+"
82 "av33Q5L3rdP68nb7mfWlFFFaCP//Z\",\"serialNumber\":121012012,\"toBeRemoved\":false,\"type\":0}";
83 } // namespace
84 class OsAccountInfoTest : public testing::Test {
85 public:
86 static void SetUpTestCase(void);
87 static void TearDownTestCase(void);
88 void SetUp(void) override;
89 void TearDown(void) override;
90 };
91
SetUpTestCase(void)92 void OsAccountInfoTest::SetUpTestCase(void)
93 {}
94
TearDownTestCase(void)95 void OsAccountInfoTest::TearDownTestCase(void)
96 {}
97
SetUp(void)98 void OsAccountInfoTest::SetUp(void) __attribute__((no_sanitize("cfi")))
99 {
100 testing::UnitTest *test = testing::UnitTest::GetInstance();
101 ASSERT_NE(test, nullptr);
102 const testing::TestInfo *testinfo = test->current_test_info();
103 ASSERT_NE(testinfo, nullptr);
104 string testCaseName = string(testinfo->name());
105 ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
106 }
107
TearDown(void)108 void OsAccountInfoTest::TearDown(void)
109 {}
110
111 /**
112 * @tc.name: OsAccountInfo_OsAccountInfo_0100
113 * @tc.desc: Create a OsAccountInfo object with no parameter.
114 * @tc.type: FUNC
115 * @tc.require:
116 */
117 HWTEST_F(OsAccountInfoTest, OsAccountInfo_OsAccountInfo_0100, TestSize.Level0)
118 {
119 OsAccountInfo *osAccountInfo = new (std::nothrow) OsAccountInfo();
120 EXPECT_NE(osAccountInfo, nullptr);
121 delete (osAccountInfo);
122 }
123
124 /**
125 * @tc.name: OsAccountInfo_OsAccountInfo_0200
126 * @tc.desc: Create a OsAccountInfo object with four parameters.
127 * @tc.type: FUNC
128 * @tc.require:
129 */
130 HWTEST_F(OsAccountInfoTest, OsAccountInfo_OsAccountInfo_0200, TestSize.Level1)
131 {
132 OsAccountInfo *osAccountInfo =
133 new (std::nothrow) OsAccountInfo(INT_ID, STRING_NAME, INT_TYPE, STRING_SERIAL_NUMBER);
134 EXPECT_NE(osAccountInfo, nullptr);
135 delete (osAccountInfo);
136 }
137
138 /**
139 * @tc.name: OsAccountInfo_GetId_0100
140 * @tc.desc: Get the id with valid data.
141 * @tc.type: FUNC
142 * @tc.require:
143 */
144 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetId_0100, TestSize.Level1)
145 {
146 int id = INT_ID;
147 OsAccountInfo osAccountInfo;
148 osAccountInfo.localId_ = id;
149 EXPECT_EQ(id, osAccountInfo.GetLocalId());
150 }
151
152 /**
153 * @tc.name: OsAccountInfo_SetLocalId_0100
154 * @tc.desc: Set the id with valid data.
155 * @tc.type: FUNC
156 * @tc.require:
157 */
158 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetLocalId_0100, TestSize.Level1)
159 {
160 OsAccountInfo osAccountInfo;
161 osAccountInfo.SetLocalId(INT_ID);
162 EXPECT_EQ(INT_ID, osAccountInfo.localId_);
163 }
164
165 /**
166 * @tc.name: OsAccountInfo_GetLocalName_0100
167 * @tc.desc: Get the name with valid data.
168 * @tc.type: FUNC
169 * @tc.require:
170 */
171 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetLocalName_0100, TestSize.Level1)
172 {
173 std::string name = STRING_NAME;
174 OsAccountInfo osAccountInfo;
175 osAccountInfo.localName_ = name;
176 EXPECT_EQ(name, osAccountInfo.GetLocalName());
177 }
178
179 /**
180 * @tc.name: OsAccountInfo_SetLocalName_0100
181 * @tc.desc: Set the name with valid data.
182 * @tc.type: FUNC
183 * @tc.require:
184 */
185 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetLocalName_0100, TestSize.Level1)
186 {
187 OsAccountInfo osAccountInfo;
188 osAccountInfo.SetLocalName(STRING_NAME);
189 EXPECT_EQ(STRING_NAME, osAccountInfo.localName_);
190 }
191
192 /**
193 * @tc.name: OsAccountInfo_GetType_0100
194 * @tc.desc: Get the type with valid data.
195 * @tc.type: FUNC
196 * @tc.require:
197 */
198 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetType_0100, TestSize.Level1)
199 {
200 OsAccountType type = INT_TYPE;
201 OsAccountInfo osAccountInfo;
202 osAccountInfo.type_ = type;
203 EXPECT_EQ(type, osAccountInfo.GetType());
204 }
205
206 /**
207 * @tc.name: OsAccountInfo_SetType_0100
208 * @tc.desc: Set the type with valid data.
209 * @tc.type: FUNC
210 * @tc.require:
211 */
212 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetType_0100, TestSize.Level1)
213 {
214 OsAccountInfo osAccountInfo;
215 osAccountInfo.SetType(INT_TYPE);
216 EXPECT_EQ(INT_TYPE, osAccountInfo.type_);
217 }
218
219 /**
220 * @tc.name: OsAccountInfo_GetConstraints_0100
221 * @tc.desc: Get the Constraints with valid data.
222 * @tc.type: FUNC
223 * @tc.require:
224 */
225 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetConstraints_0100, TestSize.Level1)
226 {
227 std::vector<std::string> constraints = VECTOR_CONSTRAINTS;
228 OsAccountInfo osAccountInfo;
229 osAccountInfo.constraints_ = constraints;
230 EXPECT_EQ(constraints.size(), osAccountInfo.GetConstraints().size());
231 }
232
233 /**
234 * @tc.name: OsAccountInfo_SetConstraints_0100
235 * @tc.desc: Set the Constraints with valid data.
236 * @tc.type: FUNC
237 * @tc.require:
238 */
239 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetConstraints_0100, TestSize.Level1)
240 {
241 OsAccountInfo osAccountInfo;
242 osAccountInfo.SetConstraints(VECTOR_CONSTRAINTS);
243 EXPECT_EQ(VECTOR_CONSTRAINTS.size(), osAccountInfo.constraints_.size());
244 }
245
246 /**
247 * @tc.name: OsAccountInfo_GetIsVerified_0100
248 * @tc.desc: Get the isVerified with valid data.
249 * @tc.type: FUNC
250 * @tc.require:
251 */
252 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetIsVerified_0100, TestSize.Level1)
253 {
254 bool isVerified = BOOL_IS_OS_ACCOUNT_VERIFIED;
255 OsAccountInfo osAccountInfo;
256 osAccountInfo.isVerified_ = isVerified;
257 EXPECT_EQ(isVerified, osAccountInfo.GetIsVerified());
258 }
259
260 /**
261 * @tc.name: OsAccountInfo_SetIsVerified_0100
262 * @tc.desc: Set the isVerified with valid data.
263 * @tc.type: FUNC
264 * @tc.require:
265 */
266 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetIsVerified_0100, TestSize.Level1)
267 {
268 OsAccountInfo osAccountInfo;
269 osAccountInfo.SetIsVerified(BOOL_IS_OS_ACCOUNT_VERIFIED);
270 EXPECT_EQ(BOOL_IS_OS_ACCOUNT_VERIFIED, osAccountInfo.isVerified_);
271 }
272
273 /**
274 * @tc.name: OsAccountInfo_GetIsCreateCompleted_0100
275 * @tc.desc: Get the isCreateCompleted with valid data.
276 * @tc.type: FUNC
277 * @tc.require:
278 */
279 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetIsCreateCompleted_0100, TestSize.Level1)
280 {
281 bool isCreateCompleted = BOOL_IS_OS_ACCOUNT_COMPLETED;
282 OsAccountInfo osAccountInfo;
283 osAccountInfo.isCreateCompleted_ = isCreateCompleted;
284 EXPECT_EQ(isCreateCompleted, osAccountInfo.GetIsCreateCompleted());
285 }
286
287 /**
288 * @tc.name: OsAccountInfo_SetIsCreateCompleted_0100
289 * @tc.desc: Set the isCreateCompleted with valid data.
290 * @tc.type: FUNC
291 * @tc.require:
292 */
293 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetIsCreateCompleted_0100, TestSize.Level1)
294 {
295 OsAccountInfo osAccountInfo;
296 osAccountInfo.SetIsCreateCompleted(BOOL_IS_OS_ACCOUNT_COMPLETED);
297 EXPECT_EQ(BOOL_IS_OS_ACCOUNT_COMPLETED, osAccountInfo.isCreateCompleted_);
298 }
299
300 /**
301 * @tc.name: OsAccountInfo_GetIsActived_0100
302 * @tc.desc: Get the isActived with valid data.
303 * @tc.type: FUNC
304 * @tc.require:
305 */
306 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetIsActived_0100, TestSize.Level1)
307 {
308 bool isActived = BOOL_IS_ACTIVED;
309 OsAccountInfo osAccountInfo;
310 osAccountInfo.isActivated_ = isActived;
311 EXPECT_EQ(isActived, osAccountInfo.GetIsActived());
312 }
313
314 /**
315 * @tc.name: OsAccountInfo_SetIsActived_0100
316 * @tc.desc: Set the isActived with valid data.
317 * @tc.type: FUNC
318 * @tc.require:
319 */
320 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetIsActived_0100, TestSize.Level1)
321 {
322 OsAccountInfo osAccountInfo;
323 osAccountInfo.SetIsActived(BOOL_IS_ACTIVED);
324 EXPECT_EQ(BOOL_IS_ACTIVED, osAccountInfo.isActivated_);
325 }
326
327 /**
328 * @tc.name: OsAccountInfo_GetPhoto_0100
329 * @tc.desc: Get the photo with valid data.
330 * @tc.type: FUNC
331 * @tc.require:
332 */
333 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetPhoto_0100, TestSize.Level1)
334 {
335 std::string photo = STRING_PHOTO;
336 OsAccountInfo osAccountInfo;
337 osAccountInfo.photo_ = photo;
338 EXPECT_EQ(photo, osAccountInfo.GetPhoto());
339 }
340
341 /**
342 * @tc.name: OsAccountInfo_SetPhoto_0100
343 * @tc.desc: Set the photo with valid data.
344 * @tc.type: FUNC
345 * @tc.require:
346 */
347 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetPhoto_0100, TestSize.Level1)
348 {
349 OsAccountInfo osAccountInfo;
350 osAccountInfo.SetPhoto(STRING_PHOTO);
351 EXPECT_EQ(STRING_PHOTO, osAccountInfo.photo_);
352 }
353
354 /**
355 * @tc.name: OsAccountInfo_GetCreateTime_0100
356 * @tc.desc: Get the createTime with valid data.
357 * @tc.type: FUNC
358 * @tc.require:
359 */
360 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetCreateTime_0100, TestSize.Level1)
361 {
362 int64_t createTime = INT_CREATE_TIME;
363 OsAccountInfo osAccountInfo;
364 osAccountInfo.createTime_ = createTime;
365 EXPECT_EQ(createTime, osAccountInfo.GetCreateTime());
366 }
367
368 /**
369 * @tc.name: OsAccountInfo_SetCreateTime_0100
370 * @tc.desc: Set the createTime with valid data.
371 * @tc.type: FUNC
372 * @tc.require:
373 */
374 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetCreateTime_0100, TestSize.Level1)
375 {
376 OsAccountInfo osAccountInfo;
377 osAccountInfo.SetCreateTime(INT_CREATE_TIME);
378 EXPECT_EQ(INT_CREATE_TIME, osAccountInfo.createTime_);
379 }
380
381 /**
382 * @tc.name: OsAccountInfo_GetLastLoginTime_0100
383 * @tc.desc: Get the lastLoginTime with valid data.
384 * @tc.type: FUNC
385 * @tc.require:
386 */
387 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetLastLoginTime_0100, TestSize.Level1)
388 {
389 int64_t lastLoginTime = INT_LAST_LOGINGGED_IN_TIME;
390 OsAccountInfo osAccountInfo;
391 osAccountInfo.lastLoginTime_ = lastLoginTime;
392 EXPECT_EQ(lastLoginTime, osAccountInfo.GetLastLoginTime());
393 }
394
395 /**
396 * @tc.name: OsAccountInfo_GetSerialNumber_0100
397 * @tc.desc: Get the serialNumber with valid data.
398 * @tc.type: FUNC
399 * @tc.require:
400 */
401 HWTEST_F(OsAccountInfoTest, OsAccountInfo_GetSerialNumber_0100, TestSize.Level1)
402 {
403 int64_t serialNumber = STRING_SERIAL_NUMBER;
404 OsAccountInfo osAccountInfo;
405 osAccountInfo.serialNumber_ = serialNumber;
406 EXPECT_EQ(serialNumber, osAccountInfo.GetSerialNumber());
407 }
408
409 /**
410 * @tc.name: OsAccountInfo_SetSerialNumber_0100
411 * @tc.desc: Set the serialNumber with valid data.
412 * @tc.type: FUNC
413 * @tc.require:
414 */
415 HWTEST_F(OsAccountInfoTest, OsAccountInfo_SetSerialNumber_0100, TestSize.Level1)
416 {
417 OsAccountInfo osAccountInfo;
418 osAccountInfo.SetSerialNumber(STRING_SERIAL_NUMBER);
419 EXPECT_EQ(STRING_SERIAL_NUMBER, osAccountInfo.serialNumber_);
420 }
421
422 /**
423 * @tc.name: OsAccountInfo_FromJson_0100
424 * @tc.desc: Set an object by Json.
425 * @tc.type: FUNC
426 * @tc.require:
427 */
428 HWTEST_F(OsAccountInfoTest, OsAccountInfo_FromJson_0100, TestSize.Level1)
429 {
430 OsAccountInfo osAccountInfo;
431
432 nlohmann::json jsonObject = Json::parse(STRING_JSON, nullptr, false);
433 ASSERT_EQ(jsonObject.is_discarded(), false);
434 osAccountInfo.FromJson(jsonObject);
435 EXPECT_EQ(osAccountInfo.GetLocalId(), INT_ID);
436 }
437
438 /**
439 * @tc.name: OsAccountInfo_ToString_0100
440 * @tc.desc: Convert os account info to string.
441 * @tc.type: FUNC
442 * @tc.require:
443 */
444 HWTEST_F(OsAccountInfoTest, OsAccountInfo_ToString_0100, TestSize.Level1)
445 {
446 int id = INT_ID;
447 OsAccountInfo osAccountInfoSrc;
448 osAccountInfoSrc.localId_ = id;
449 std::string jsonString = osAccountInfoSrc.ToString();
450 nlohmann::json jsonObject = nlohmann::json::parse(jsonString, nullptr, false);
451 ASSERT_EQ(jsonObject.is_discarded(), false);
452 OsAccountInfo osAccountInfoTar;
453 osAccountInfoTar.FromJson(jsonObject);
454 EXPECT_EQ(osAccountInfoTar.GetLocalId(), INT_ID);
455 }
456
457 /**
458 * @tc.name: OsAccountInfo_Marshalling_0100
459 * @tc.desc: Test Marshalling Unmarshalling with valid data.
460 * @tc.type: FUNC
461 * @tc.require:
462 */
463 HWTEST_F(OsAccountInfoTest, OsAccountInfo_Marshalling_0100, TestSize.Level1)
464 {
465 // make info with an owner
466 int id = INT_ID;
467 OsAccountInfo osAccountInfoSrc;
468 osAccountInfoSrc.localId_ = id;
469 // marshalling
470 Parcel parcel;
471 EXPECT_EQ(osAccountInfoSrc.Marshalling(parcel), true);
472 // unmarshalling
473 auto infoPtr = OsAccountInfo::Unmarshalling(parcel);
474 ASSERT_NE(infoPtr, nullptr);
475 // check the data
476 EXPECT_EQ(INT_ID, infoPtr->localId_);
477 }
478
479 /**
480 * @tc.name: GetOsAccountName01
481 * @tc.desc: Test GetOsAccountName
482 * @tc.type: FUNC
483 * @tc.require: issueI8ZEEN
484 */
485 HWTEST_F(OsAccountInfoTest, GetOsAccountName01, TestSize.Level1)
486 {
487 std::string name;
488 setuid(TEST_UID * UID_TRANSFORM_DIVISOR);
489 EXPECT_EQ(ERR_OK, OsAccountManager::GetOsAccountName(name));
490 OsAccountInfo osAccountInfo;
491 setuid(ROOT_UID);
492 EXPECT_EQ(ERR_OK, OsAccountManager::QueryOsAccountById(TEST_UID, osAccountInfo));
493 EXPECT_EQ(name, osAccountInfo.GetLocalName());
494 }
495
496 #ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
497 /**
498 * @tc.name: GetOsAccountName02
499 * @tc.desc: Test GetOsAccountName
500 * @tc.type: FUNC
501 * @tc.require: issueI8ZEEN
502 */
503 HWTEST_F(OsAccountInfoTest, GetOsAccountName02, TestSize.Level1)
504 {
505 OsAccountInfo osAccountInfo;
506 EXPECT_EQ(ERR_OK, OsAccountManager::CreateOsAccount("GetOsAccountName02", OsAccountType::NORMAL, osAccountInfo));
507 uint32_t localId = osAccountInfo.GetLocalId();
508 setuid(localId * UID_TRANSFORM_DIVISOR);
509 std::string name;
510 EXPECT_EQ(ERR_OK, OsAccountManager::GetOsAccountName(name));
511 EXPECT_EQ("GetOsAccountName02", name);
512 setuid(ROOT_UID);
513 EXPECT_EQ(ERR_OK, OsAccountManager::SetOsAccountName(localId, "updateName"));
514 setuid(localId * UID_TRANSFORM_DIVISOR);
515 EXPECT_EQ(ERR_OK, OsAccountManager::GetOsAccountName(name));
516 EXPECT_EQ(name, "updateName");
517 setuid(ROOT_UID);
518 EXPECT_EQ(ERR_OK, OsAccountManager::RemoveOsAccount(localId));
519 setuid(localId * UID_TRANSFORM_DIVISOR);
520 EXPECT_NE(ERR_OK, OsAccountManager::GetOsAccountName(name));
521 setuid(ROOT_UID);
522 }
523
524 /**
525 * @tc.name: CreateOsAccountWithFullInfo0100
526 * @tc.desc: Test CreateOsAccountWithFullInfo ERR_ACCOUNT_COMMON_INVALID_PARAMETER
527 * @tc.type: FUNC
528 * @tc.require:
529 */
530 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0100, TestSize.Level1)
531 {
532 OsAccountInfo osAccountInfo;
533 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
534 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
535
536 osAccountInfo.SetLocalName("test114");
537 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
538 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
539 }
540
541 /**
542 * @tc.name: CreateOsAccountWithFullInfo0101
543 * @tc.desc: Test CreateOsAccountWithFullInfo ERR_ACCOUNT_COMMON_INVALID_PARAMETER
544 * @tc.type: FUNC
545 * @tc.require:
546 */
547 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0101, TestSize.Level1)
548 {
549 OsAccountInfo osAccountInfo;
550 osAccountInfo.SetLocalName("test115");
551 osAccountInfo.SetLocalId(CREATE_LOCAL_ID);
552
553 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
554 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
555 OsAccountManager::RemoveOsAccount(CREATE_LOCAL_ID);
556 }
557
558 /**
559 * @tc.name: CreateOsAccountWithFullInfo0102
560 * @tc.desc: Test CreateOsAccountWithFullInfo ERR_ACCOUNT_COMMON_INVALID_PARAMETER
561 * @tc.type: FUNC
562 * @tc.require:
563 */
564 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0102, TestSize.Level1)
565 {
566 OsAccountInfo osAccountInfo;
567 osAccountInfo.SetLocalName("test116");
568 osAccountInfo.SetLocalId(CREATE_LOCAL_ID);
569 osAccountInfo.SetSerialNumber(2023023100000033);
570 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
571
572 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
573 OsAccountManager::RemoveOsAccount(CREATE_LOCAL_ID);
574 }
575
576 /**
577 * @tc.name: CreateOsAccountWithFullInfo0103
578 * @tc.desc: Test CreateOsAccountWithFullInfo admin success
579 * @tc.type: FUNC
580 * @tc.require:
581 */
582 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0103, TestSize.Level1)
583 {
584 OsAccountInfo osAccountInfo;
585 osAccountInfo.SetLocalName("test117");
586 osAccountInfo.SetLocalId(997);
587 osAccountInfo.SetSerialNumber(2023023100000033);
588 osAccountInfo.SetCreateTime(1695883215000);
589 osAccountInfo.SetLastLoginTime(1695863215000);
590 EXPECT_EQ(ERR_OK, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
591
592 osAccountInfo.SetLocalName("update117");
593 EXPECT_EQ(ERR_OK, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
594 OsAccountManager::RemoveOsAccount(osAccountInfo.GetLocalId());
595 }
596
597 /**
598 * @tc.name: CreateOsAccountWithFullInfo0104
599 * @tc.desc: Test CreateOsAccountWithFullInfo normal success
600 * @tc.type: FUNC
601 * @tc.require:
602 */
603 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0104, TestSize.Level1)
604 {
605 OsAccountInfo osAccountInfo;
606 osAccountInfo.SetLocalName("test118");
607 osAccountInfo.SetType(OsAccountType::NORMAL);
608 osAccountInfo.SetLocalId(998);
609 osAccountInfo.SetSerialNumber(1100);
610 osAccountInfo.SetCreateTime(1695883215000);
611 EXPECT_EQ(ERR_OK, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
612
613 osAccountInfo.SetLastLoginTime(1695863290000);
614 EXPECT_EQ(ERR_OK, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
615 OsAccountManager::RemoveOsAccount(osAccountInfo.GetLocalId());
616 }
617
618 /**
619 * @tc.name: CreateOsAccountWithFullInfo0105
620 * @tc.desc: Test CreateOsAccountWithFullInfo guest success and repeat to create fail
621 * @tc.type: FUNC
622 * @tc.require:
623 */
624 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0105, TestSize.Level1)
625 {
626 OsAccountInfo osAccountInfo;
627 osAccountInfo.SetLocalName("test119");
628 osAccountInfo.SetType(OsAccountType::GUEST);
629 osAccountInfo.SetLocalId(999);
630 osAccountInfo.SetSerialNumber(1100);
631 osAccountInfo.SetCreateTime(1695883215000);
632 EXPECT_EQ(ERR_OK, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
633
634 osAccountInfo.SetLastLoginTime(1695863290000);
635 EXPECT_EQ(ERR_OK, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
636 EXPECT_EQ(ERR_OK, OsAccountManager::CreateOsAccountWithFullInfo(osAccountInfo));
637 OsAccountManager::RemoveOsAccount(osAccountInfo.GetLocalId());
638 }
639
640 /**
641 * @tc.name: CreateOsAccountWithFullInfo0106
642 * @tc.desc: Test UpdateOsAccountWithFullInfo not exist fail
643 * @tc.type: FUNC
644 * @tc.require:
645 */
646 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0106, TestSize.Level1)
647 {
648 OsAccountInfo osAccountInfo;
649 osAccountInfo.SetLocalName("test120");
650 osAccountInfo.SetType(OsAccountType::GUEST);
651 osAccountInfo.SetLocalId(999);
652 osAccountInfo.SetSerialNumber(1100);
653 osAccountInfo.SetCreateTime(1695883215000);
654 osAccountInfo.SetLastLoginTime(1695863290000);
655 EXPECT_EQ(ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR,
656 OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
657 }
658
659 /**
660 * @tc.name: CreateOsAccountWithFullInfo0107
661 * @tc.desc: Test UpdateOsAccountWithFullInfo admin user without localName
662 * @tc.type: FUNC
663 * @tc.require: I8DBBM
664 */
665 HWTEST_F(OsAccountInfoTest, CreateOsAccountWithFullInfo0107, TestSize.Level1)
666 {
667 OsAccountInfo osAccountInfoBak;
668 OsAccountManager::QueryOsAccountById(100, osAccountInfoBak);
669
670 OsAccountInfo osAccountInfo;
671 osAccountInfo.SetLocalId(100);
672 osAccountInfo.SetLastLoginTime(1695863290000);
673 osAccountInfo.SetConstraints(VECTOR_CONSTRAINTS);
674
675 EXPECT_EQ(ERR_OK, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
676 osAccountInfo.SetType(OsAccountType::GUEST);
677 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfo));
678
679 EXPECT_EQ(ERR_OK, OsAccountManager::UpdateOsAccountWithFullInfo(osAccountInfoBak));
680 }
681
682 /**
683 * @tc.name: GetOsAccountShortName001
684 * @tc.desc: Test get os account name.
685 * @tc.type: FUNC
686 * @tc.require: I8F2PI
687 */
688 HWTEST_F(OsAccountInfoTest, GetOsAccountShortName001, TestSize.Level1)
689 {
690 std::string shortName;
691 EXPECT_EQ(ERR_OK, OsAccountManager::GetOsAccountShortName(shortName));
692 }
693
694 /**
695 * @tc.name: GetOsAccountShortName002
696 * @tc.desc: Test get os account short name by id.
697 * @tc.type: FUNC
698 * @tc.require:
699 */
700 HWTEST_F(OsAccountInfoTest, GetOsAccountShortName002, TestSize.Level1)
701 {
702 std::string shortName;
703 EXPECT_EQ(ERR_OK, OsAccountManager::GetOsAccountShortName(100, shortName));
704 EXPECT_NE(ERR_OK, OsAccountManager::GetOsAccountShortName(199, shortName));
705 }
706
707 /**
708 * @tc.name: CreateOsAccount00
709 * @tc.desc: create os account with short name
710 * @tc.type: FUNC
711 * @tc.require: I8F2PI
712 */
713 HWTEST_F(OsAccountInfoTest, CreateOsAccount00, TestSize.Level1)
714 {
715 OsAccountInfo osAccountInfoOne;
716 OsAccountInfo osAccountInfoTwo;
717 EXPECT_EQ(ERR_OK,
718 OsAccountManager::CreateOsAccount(STRING_NAME, "shortName", OsAccountType::NORMAL, osAccountInfoOne));
719 EXPECT_EQ(ERR_ACCOUNT_COMMON_NAME_HAD_EXISTED,
720 OsAccountManager::CreateOsAccount(STRING_NAME, STRING_NAME, OsAccountType::NORMAL, osAccountInfoTwo));
721 OsAccountManager::RemoveOsAccount(osAccountInfoTwo.GetLocalId());
722 EXPECT_EQ(ERR_OK, OsAccountManager::SetOsAccountName(osAccountInfoOne.GetLocalId(), "updateName"));
723 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
724 }
725
726 /**
727 * @tc.name: CreateOsAccount01
728 * @tc.desc: create os account with short name
729 * @tc.type: FUNC
730 * @tc.require: I8F2PI
731 */
732 HWTEST_F(OsAccountInfoTest, CreateOsAccount01, TestSize.Level1)
733 {
734 OsAccountInfo osAccountInfoOne;
735 OsAccountInfo osAccountInfoTwo;
736 CreateOsAccountOptions options;
737 EXPECT_EQ(ERR_OK,
738 OsAccountManager::CreateOsAccount(STRING_NAME, "shortName", OsAccountType::NORMAL, options, osAccountInfoOne));
739 EXPECT_EQ(ERR_ACCOUNT_COMMON_NAME_HAD_EXISTED,
740 OsAccountManager::CreateOsAccount(STRING_NAME, STRING_NAME, OsAccountType::NORMAL, osAccountInfoTwo));
741 EXPECT_EQ(ERR_ACCOUNT_COMMON_SHORT_NAME_HAD_EXISTED,
742 OsAccountManager::CreateOsAccount("CreateOsAccount01", "shortName", OsAccountType::NORMAL, osAccountInfoTwo));
743 EXPECT_EQ(ERR_OK, OsAccountManager::SetOsAccountName(osAccountInfoOne.GetLocalId(), "updateName"));
744 osAccountInfoOne.SetShortName(STRING_NAME);
745 osAccountInfoOne.SetCredentialId(123);
746 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
747 }
748 #endif // ENABLE_MULTIPLE_OS_ACCOUNTS
749
750 /**
751 * @tc.name: SetCredentialId01
752 * @tc.desc: Test SetCredentialId
753 * @tc.type: FUNC
754 * @tc.require: issueI8ZEEN
755 */
756 HWTEST_F(OsAccountInfoTest, SetCredentialId01, TestSize.Level1)
757 {
758 OsAccountInfo osAccountInfo;
759 osAccountInfo.SetCredentialId(0);
760 EXPECT_EQ(osAccountInfo.GetCredentialId(), 0);
761 }
762
763 /**
764 * @tc.name: CreateOsAccount02
765 * @tc.desc: create os account with short name
766 * @tc.type: FUNC
767 * @tc.require: I8F2PI
768 */
769 #ifdef ENABLE_MULTIPLE_OS_ACCOUNTS
770 HWTEST_F(OsAccountInfoTest, CreateOsAccount02, TestSize.Level1)
771 {
772 OsAccountInfo osAccountInfoOne;
773 EXPECT_EQ(ERR_OK,
774 OsAccountManager::CreateOsAccount("..", OsAccountType::NORMAL, osAccountInfoOne));
775 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
776 }
777
778 /**
779 * @tc.name: CreateOsAccount03
780 * @tc.desc: create os account with short name
781 * @tc.type: FUNC
782 * @tc.require: I8F2PI
783 */
784 HWTEST_F(OsAccountInfoTest, CreateOsAccount03, TestSize.Level1)
785 {
786 OsAccountInfo osAccountInfoOne;
787 EXPECT_EQ(ERR_OK,
788 OsAccountManager::CreateOsAccount("zsm<<zd?s>|:23\"1/bc\\d", OsAccountType::NORMAL, osAccountInfoOne));
789 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
790 }
791
792 /**
793 * @tc.name: CreateOsAccount04
794 * @tc.desc: create os account with short name
795 * @tc.type: FUNC
796 * @tc.require: I8F2PI
797 */
798 HWTEST_F(OsAccountInfoTest, CreateOsAccount04, TestSize.Level1)
799 {
800 OsAccountInfo osAccountInfoOne;
801 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER,
802 OsAccountManager::CreateOsAccount("CreateOsAccount04", OVER_LENGTH_NAME,
803 OsAccountType::NORMAL, osAccountInfoOne));
804 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
805 }
806
807 /**
808 * @tc.name: CreateOsAccount05
809 * @tc.desc: create os account with short name
810 * @tc.type: FUNC
811 * @tc.require: I8F2PI
812 */
813 HWTEST_F(OsAccountInfoTest, CreateOsAccount05, TestSize.Level1)
814 {
815 OsAccountInfo osAccountInfoOne;
816 EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER,
817 OsAccountManager::CreateOsAccount(OVER_LENGTH_NAME + OVER_LENGTH_NAME,
818 OsAccountType::NORMAL, osAccountInfoOne));
819 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
820 }
821
822 /**
823 * @tc.name: CreateOsAccount06
824 * @tc.desc: create os account with short name
825 * @tc.type: FUNC
826 * @tc.require: I8F2PI
827 */
828 HWTEST_F(OsAccountInfoTest, CreateOsAccount06, TestSize.Level1)
829 {
830 OsAccountInfo osAccountInfoOne;
831 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "shortName*", OsAccountType::NORMAL, osAccountInfoOne),
832 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
833 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
834 }
835
836 /**
837 * @tc.name: CreateOsAccount07
838 * @tc.desc: create os account with short name
839 * @tc.type: FUNC
840 * @tc.require: I8F2PI
841 */
842 HWTEST_F(OsAccountInfoTest, CreateOsAccount07, TestSize.Level1)
843 {
844 OsAccountInfo osAccountInfoOne;
845 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "123|", OsAccountType::NORMAL, osAccountInfoOne),
846 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
847 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
848 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "12*3", OsAccountType::NORMAL, osAccountInfoOne),
849 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
850 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
851 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "12?3", OsAccountType::NORMAL, osAccountInfoOne),
852 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
853 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
854 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "12\"3", OsAccountType::NORMAL, osAccountInfoOne),
855 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
856 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
857 }
858
859 /**
860 * @tc.name: CreateOsAccount08
861 * @tc.desc: create os account with short name
862 * @tc.type: FUNC
863 * @tc.require: I8F2PI
864 */
865 HWTEST_F(OsAccountInfoTest, CreateOsAccount08, TestSize.Level1)
866 {
867 OsAccountInfo osAccountInfoOne;
868 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "", OsAccountType::NORMAL, osAccountInfoOne),
869 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
870 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
871 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, ".", OsAccountType::NORMAL, osAccountInfoOne),
872 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
873 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
874 EXPECT_EQ(OsAccountManager::CreateOsAccount(STRING_NAME, "..", OsAccountType::NORMAL, osAccountInfoOne),
875 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
876 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
877 }
878
879 /**
880 * @tc.name: CreateOsAccount09
881 * @tc.desc: create os account with short name
882 * @tc.type: FUNC
883 * @tc.require: I8F2PI
884 */
885 HWTEST_F(OsAccountInfoTest, CreateOsAccount09, TestSize.Level1)
886 {
887 OsAccountInfo osAccountInfoOne;
888 EXPECT_EQ(OsAccountManager::CreateOsAccount("name1", "???", OsAccountType::NORMAL, osAccountInfoOne),
889 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
890 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
891 EXPECT_EQ(OsAccountManager::CreateOsAccount("name2", "***", OsAccountType::NORMAL, osAccountInfoOne),
892 ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
893 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
894 EXPECT_EQ(OsAccountManager::CreateOsAccount("name3", "?", OsAccountType::NORMAL, osAccountInfoOne),
895 ERR_OK);
896 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
897 EXPECT_EQ(OsAccountManager::CreateOsAccount("name4", ":", OsAccountType::NORMAL, osAccountInfoOne),
898 ERR_OK);
899 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
900 }
901
902 HWTEST_F(OsAccountInfoTest, CreateOsAccount10, TestSize.Level1)
903 {
904 OsAccountInfo osAccountInfoOne;
905 EXPECT_NE(OsAccountManager::CreateOsAccount(OVER_LENGTH_ACCOUNT_NAME, OsAccountType::NORMAL, osAccountInfoOne),
906 ERR_OK);
907 OsAccountManager::RemoveOsAccount(osAccountInfoOne.GetLocalId());
908 OsAccountInfo osAccountInfoTwo;
909 EXPECT_NE(OsAccountManager::CreateOsAccount(OVER_LENGTH_ACCOUNT_NAME, "sn",
910 OsAccountType::NORMAL, osAccountInfoTwo), ERR_OK);
911 OsAccountManager::RemoveOsAccount(osAccountInfoTwo.GetLocalId());
912 }
913 #endif // ENABLE_MULTIPLE_OS_ACCOUNTS
914