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