OLD | NEW |
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "login_manager/session_manager_service.h" | 5 #include "login_manager/session_manager_service.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "login_manager/mock_nss_util.h" | 33 #include "login_manager/mock_nss_util.h" |
34 #include "login_manager/mock_owner_key.h" | 34 #include "login_manager/mock_owner_key.h" |
35 #include "login_manager/mock_pref_store.h" | 35 #include "login_manager/mock_pref_store.h" |
36 #include "login_manager/mock_system_utils.h" | 36 #include "login_manager/mock_system_utils.h" |
37 #include "login_manager/mock_upstart_signal_emitter.h" | 37 #include "login_manager/mock_upstart_signal_emitter.h" |
38 #include "login_manager/system_utils.h" | 38 #include "login_manager/system_utils.h" |
39 | 39 |
40 namespace login_manager { | 40 namespace login_manager { |
41 | 41 |
42 using ::testing::AnyNumber; | 42 using ::testing::AnyNumber; |
| 43 using ::testing::AtMost; |
43 using ::testing::DoAll; | 44 using ::testing::DoAll; |
44 using ::testing::Invoke; | 45 using ::testing::Invoke; |
45 using ::testing::Eq; | 46 using ::testing::Eq; |
46 using ::testing::Return; | 47 using ::testing::Return; |
47 using ::testing::SetArgumentPointee; | 48 using ::testing::SetArgumentPointee; |
48 using ::testing::StrEq; | 49 using ::testing::StrEq; |
49 using ::testing::_; | 50 using ::testing::_; |
50 | 51 |
51 static const char kCheckedFile[] = "/tmp/checked_file"; | 52 static const char kCheckedFile[] = "/tmp/checked_file"; |
52 static const char kUptimeFile[] = "/tmp/uptime-chrome-exec"; | 53 static const char kUptimeFile[] = "/tmp/uptime-chrome-exec"; |
53 static const char kDiskFile[] = "/tmp/disk-chrome-exec"; | 54 static const char kDiskFile[] = "/tmp/disk-chrome-exec"; |
54 | 55 |
| 56 // compatible with void Run() |
| 57 static void BadExit() { _exit(1); } |
| 58 static void BadExitAfterSleep() { sleep(1); _exit(1); } |
| 59 static void RunAndSleep() { while (true) { sleep(1); } }; |
| 60 static void CleanExit() { _exit(0); } |
| 61 |
55 // Used as a base class for the tests in this file. | 62 // Used as a base class for the tests in this file. |
56 // Gives useful shared functionality. | 63 // Gives useful shared functionality. |
57 class SessionManagerTest : public ::testing::Test { | 64 class SessionManagerTest : public ::testing::Test { |
58 public: | 65 public: |
59 SessionManagerTest() | 66 SessionManagerTest() |
60 : manager_(NULL), | 67 : manager_(NULL), |
61 utils_(new MockSystemUtils), | 68 utils_(new MockSystemUtils), |
62 file_checker_(new MockFileChecker(kCheckedFile)), | 69 file_checker_(new MockFileChecker(kCheckedFile)), |
63 mitigator_(new MockMitigator), | 70 mitigator_(new MockMitigator), |
64 upstart_(new MockUpstartSignalEmitter), | 71 upstart_(new MockUpstartSignalEmitter), |
65 must_destroy_mocks_(true), | 72 must_destroy_mocks_(true) { |
66 fake_key_(CreateArray("dummy", strlen("dummy"))) { | |
67 } | 73 } |
68 | 74 |
69 virtual ~SessionManagerTest() { | 75 virtual ~SessionManagerTest() { |
70 if (must_destroy_mocks_) { | 76 if (must_destroy_mocks_) { |
71 delete file_checker_; | 77 delete file_checker_; |
72 delete mitigator_; | 78 delete mitigator_; |
73 delete upstart_; | 79 delete upstart_; |
74 } | 80 } |
75 FilePath uptime(kUptimeFile); | 81 FilePath uptime(kUptimeFile); |
76 FilePath disk(kDiskFile); | 82 FilePath disk(kDiskFile); |
77 file_util::Delete(uptime, false); | 83 file_util::Delete(uptime, false); |
78 file_util::Delete(disk, false); | 84 file_util::Delete(disk, false); |
79 | |
80 g_array_free(fake_key_, TRUE); | |
81 } | 85 } |
82 | 86 |
83 virtual void SetUp() { | 87 virtual void SetUp() { |
84 property_ = StringPrintf("%s=%s", kPropName, kPropValue); | 88 property_ = StringPrintf("%s=%s", kPropName, kPropValue); |
85 char sig[] = "signature"; | 89 char sig[] = "signature"; |
86 int len = strlen(sig); | 90 int len = strlen(sig); |
87 sig[2] = '\0'; // to make sure we can handle NULL inside a signature. | 91 sig[2] = '\0'; // to make sure we can handle NULL inside a signature. |
88 fake_sig_ = CreateArray(sig, len); | 92 fake_sig_ = CreateArray(sig, len); |
89 ASSERT_TRUE(base::Base64Encode(std::string(fake_sig_->data, fake_sig_->len), | 93 ASSERT_TRUE(base::Base64Encode(std::string(fake_sig_->data, fake_sig_->len), |
90 &fake_sig_encoded_)); | 94 &fake_sig_encoded_)); |
(...skipping 13 matching lines...) Expand all Loading... |
104 manager_->test_api().set_prefstore(store); | 108 manager_->test_api().set_prefstore(store); |
105 manager_->Run(); | 109 manager_->Run(); |
106 } | 110 } |
107 | 111 |
108 protected: | 112 protected: |
109 // NOT const so that they can be passed to methods that implement dbus calls, | 113 // NOT const so that they can be passed to methods that implement dbus calls, |
110 // which (of necessity) take bare gchar*. | 114 // which (of necessity) take bare gchar*. |
111 static char kFakeEmail[]; | 115 static char kFakeEmail[]; |
112 static char kPropName[]; | 116 static char kPropName[]; |
113 static char kPropValue[]; | 117 static char kPropValue[]; |
| 118 static const pid_t kDummyPid; |
114 | 119 |
115 // Creates the manager with the jobs. Mocks the file checker. | 120 // Creates the manager with the jobs. Mocks the file checker. |
116 // The second job can be NULL. | 121 // The second job can be NULL. |
117 void InitManager(MockChildJob* job1, MockChildJob* job2) { | 122 void InitManager(MockChildJob* job1, MockChildJob* job2) { |
118 std::vector<ChildJobInterface*> jobs; | 123 std::vector<ChildJobInterface*> jobs; |
119 EXPECT_CALL(*job1, GetName()) | 124 EXPECT_CALL(*job1, GetName()) |
120 .WillRepeatedly(Return(std::string("job1"))); | 125 .WillRepeatedly(Return(std::string("job1"))); |
121 EXPECT_CALL(*job1, IsDesiredUidSet()) | 126 EXPECT_CALL(*job1, IsDesiredUidSet()) |
122 .WillRepeatedly(Return(false)); | 127 .WillRepeatedly(Return(false)); |
123 jobs.push_back(job1); | 128 jobs.push_back(job1); |
(...skipping 30 matching lines...) Expand all Loading... |
154 .WillOnce(Return(false)); | 159 .WillOnce(Return(false)); |
155 manager_->test_api().set_ownerkey(key); | 160 manager_->test_api().set_ownerkey(key); |
156 // Now, expect an attempt to check whether this user is the owner; respond | 161 // Now, expect an attempt to check whether this user is the owner; respond |
157 // as though he is not. | 162 // as though he is not. |
158 std::string other_user("notme"); | 163 std::string other_user("notme"); |
159 EXPECT_CALL(*store, Get(_, _, _)) | 164 EXPECT_CALL(*store, Get(_, _, _)) |
160 .WillOnce(DoAll(SetArgumentPointee<1>(other_user), | 165 .WillOnce(DoAll(SetArgumentPointee<1>(other_user), |
161 Return(true))); | 166 Return(true))); |
162 EXPECT_CALL(*key, Verify(_, _, _, _)) | 167 EXPECT_CALL(*key, Verify(_, _, _, _)) |
163 .WillOnce(Return(true)); | 168 .WillOnce(Return(true)); |
| 169 // Confirm that the device is owned. |
| 170 EXPECT_CALL(*key, HaveCheckedDisk()) |
| 171 .WillOnce(Return(true)); |
| 172 EXPECT_CALL(*key, IsPopulated()) |
| 173 .WillOnce(Return(true)); |
164 } | 174 } |
165 | 175 |
166 void ExpectStartSessionUnowned(const std::string& email_string, | 176 void ExpectStartSessionUnowned(const std::string& email_string, |
167 MockChildJob* job, | |
168 MockPrefStore* store) { | 177 MockPrefStore* store) { |
| 178 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); |
169 EXPECT_CALL(*job, StartSession(email_string)) | 179 EXPECT_CALL(*job, StartSession(email_string)) |
170 .Times(1); | 180 .Times(1); |
| 181 |
| 182 MockChildJob* k_job = new MockChildJob; |
| 183 EXPECT_CALL(*k_job, SetDesiredUid(getuid())) |
| 184 .Times(1); |
| 185 EXPECT_CALL(*k_job, GetDesiredUid()) |
| 186 .Times(1) |
| 187 .WillRepeatedly(Return(getuid())); |
| 188 EXPECT_CALL(*k_job, IsDesiredUidSet()) |
| 189 .WillRepeatedly(Return(true)); |
| 190 ON_CALL(*k_job, Run()) |
| 191 .WillByDefault(Invoke(CleanExit)); |
| 192 int keygen_pid = kDummyPid + 1; |
| 193 |
171 MockOwnerKey* key = new MockOwnerKey; | 194 MockOwnerKey* key = new MockOwnerKey; |
172 EXPECT_CALL(*key, PopulateFromDiskIfPossible()) | 195 EXPECT_CALL(*key, PopulateFromDiskIfPossible()) |
173 .WillRepeatedly(Return(true)); | 196 .WillRepeatedly(Return(true)); |
174 // First, expect an attempt to set the device owner property, but | 197 EXPECT_CALL(*key, StartGeneration(k_job)) |
| 198 .WillOnce(Return(keygen_pid)); |
175 // act like this user isn't the owner. | 199 // act like this user isn't the owner. |
176 EXPECT_CALL(*key, Sign(_, _, _)) | 200 EXPECT_CALL(*key, Sign(_, _, _)) |
177 .WillOnce(Return(false)); | 201 .WillOnce(Return(false)); |
178 manager_->test_api().set_ownerkey(key); | 202 |
179 // Now, expect an attempt to check whether this user is the owner; respond | 203 // Now, expect an attempt to check whether this user is the owner; respond |
180 // as though there isn't one. | 204 // as though there isn't one. |
181 EXPECT_CALL(*store, Get(_, _, _)) | 205 EXPECT_CALL(*store, Get(_, _, _)) |
182 .WillOnce(Return(false)); | 206 .WillOnce(Return(false)); |
| 207 // Confirm that the device is NOT owned. |
| 208 EXPECT_CALL(*key, HaveCheckedDisk()) |
| 209 .WillOnce(Return(true)); |
| 210 EXPECT_CALL(*key, IsPopulated()) |
| 211 .WillOnce(Return(false)); |
| 212 |
| 213 manager_->test_api().set_keygen_job(k_job); // manager_ takes ownership. |
| 214 manager_->set_uid(getuid()); |
| 215 manager_->test_api().set_ownerkey(key); |
| 216 manager_->test_api().set_prefstore(store); |
| 217 |
| 218 EXPECT_CALL(*(utils_.get()), kill(keygen_pid, getuid(), SIGTERM)) |
| 219 .WillOnce(Return(0)); |
| 220 EXPECT_CALL(*(utils_.get()), ChildIsGone(keygen_pid, _)) |
| 221 .WillOnce(Return(true)); |
| 222 MockUtils(); |
183 } | 223 } |
184 | 224 |
185 void ExpectStartSessionForOwner(const std::string& email_string, | 225 void ExpectStartSessionForOwner(const std::string& email_string, |
186 MockOwnerKey* key, | 226 MockOwnerKey* key, |
187 MockPrefStore* store) { | 227 MockPrefStore* store) { |
188 ON_CALL(*key, PopulateFromDiskIfPossible()) | 228 ON_CALL(*key, PopulateFromDiskIfPossible()) |
189 .WillByDefault(Return(true)); | 229 .WillByDefault(Return(true)); |
190 // First, mimic attempt to whitelist the owner and set a the | 230 // First, mimic attempt to whitelist the owner and set a the |
191 // device owner pref. | 231 // device owner pref. |
192 EXPECT_CALL(*key, Sign(_, _, _)) | 232 EXPECT_CALL(*key, Sign(_, _, _)) |
(...skipping 10 matching lines...) Expand all Loading... |
203 .WillOnce(Return(true)) | 243 .WillOnce(Return(true)) |
204 .WillOnce(Return(true)) | 244 .WillOnce(Return(true)) |
205 .WillOnce(Return(true)); | 245 .WillOnce(Return(true)); |
206 // Now, expect an attempt to check whether this user is the owner; | 246 // Now, expect an attempt to check whether this user is the owner; |
207 // respond as though he is. | 247 // respond as though he is. |
208 EXPECT_CALL(*store, Get(_, _, _)) | 248 EXPECT_CALL(*store, Get(_, _, _)) |
209 .WillOnce(DoAll(SetArgumentPointee<1>(email_string), | 249 .WillOnce(DoAll(SetArgumentPointee<1>(email_string), |
210 Return(true))); | 250 Return(true))); |
211 EXPECT_CALL(*key, Verify(_, _, _, _)) | 251 EXPECT_CALL(*key, Verify(_, _, _, _)) |
212 .WillOnce(Return(true)); | 252 .WillOnce(Return(true)); |
| 253 // Confirm that the device is owned. |
| 254 EXPECT_CALL(*key, HaveCheckedDisk()) |
| 255 .Times(AtMost(1)) |
| 256 .WillRepeatedly(Return(true)); |
| 257 EXPECT_CALL(*key, IsPopulated()) |
| 258 .Times(AtMost(1)) |
| 259 .WillRepeatedly(Return(true)); |
213 } | 260 } |
214 | 261 |
215 void StartFakeSession() { | 262 void StartFakeSession() { |
216 manager_->test_api().set_session_started(true, kFakeEmail); | 263 manager_->test_api().set_session_started(true, kFakeEmail); |
217 } | 264 } |
218 | 265 |
219 enum ChildRuns { | 266 enum ChildRuns { |
220 ALWAYS, NEVER, ONCE, EXACTLY_ONCE, TWICE, MAYBE_NEVER | 267 ALWAYS, NEVER, ONCE, EXACTLY_ONCE, TWICE, MAYBE_NEVER |
221 }; | 268 }; |
222 | 269 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return output; | 321 return output; |
275 } | 322 } |
276 | 323 |
277 scoped_refptr<SessionManagerService> manager_; | 324 scoped_refptr<SessionManagerService> manager_; |
278 scoped_ptr<MockSystemUtils> utils_; | 325 scoped_ptr<MockSystemUtils> utils_; |
279 MockFileChecker* file_checker_; | 326 MockFileChecker* file_checker_; |
280 MockMitigator* mitigator_; | 327 MockMitigator* mitigator_; |
281 MockUpstartSignalEmitter* upstart_; | 328 MockUpstartSignalEmitter* upstart_; |
282 bool must_destroy_mocks_; | 329 bool must_destroy_mocks_; |
283 std::string property_; | 330 std::string property_; |
284 GArray* fake_key_; | |
285 GArray* fake_sig_; | 331 GArray* fake_sig_; |
286 std::string fake_sig_encoded_; | 332 std::string fake_sig_encoded_; |
287 }; | 333 }; |
288 | 334 |
289 // static | 335 // static |
290 char SessionManagerTest::kFakeEmail[] = "cmasone@whaaat.org"; | 336 char SessionManagerTest::kFakeEmail[] = "cmasone@whaaat.org"; |
291 char SessionManagerTest::kPropName[] = "name"; | 337 char SessionManagerTest::kPropName[] = "name"; |
292 char SessionManagerTest::kPropValue[] = "value"; | 338 char SessionManagerTest::kPropValue[] = "value"; |
| 339 const pid_t SessionManagerTest::kDummyPid = 4; |
293 | 340 |
294 | 341 |
295 // compatible with void Run() | |
296 static void BadExit() { _exit(1); } | |
297 static void BadExitAfterSleep() { sleep(1); _exit(1); } | |
298 static void RunAndSleep() { while (true) { sleep(1); } }; | |
299 static void CleanExit() { _exit(0); } | |
300 | |
301 TEST_F(SessionManagerTest, NoLoopTest) { | 342 TEST_F(SessionManagerTest, NoLoopTest) { |
302 MockChildJob* job = CreateTrivialMockJob(NEVER); | 343 MockChildJob* job = CreateTrivialMockJob(NEVER); |
303 SimpleRunManager(new MockPrefStore); | 344 SimpleRunManager(new MockPrefStore); |
304 } | 345 } |
305 | 346 |
306 TEST_F(SessionManagerTest, BadExitChild) { | 347 TEST_F(SessionManagerTest, BadExitChild) { |
307 MockChildJob* job = CreateTrivialMockJob(ONCE); | 348 MockChildJob* job = CreateTrivialMockJob(ONCE); |
308 EXPECT_CALL(*job, RecordTime()) | 349 EXPECT_CALL(*job, RecordTime()) |
309 .Times(1); | 350 .Times(1); |
310 EXPECT_CALL(*job, ShouldStop()) | 351 EXPECT_CALL(*job, ShouldStop()) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 508 |
468 ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0); | 509 ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0); |
469 ASSERT_TRUE(file_util::PathExists(key_file_path)); | 510 ASSERT_TRUE(file_util::PathExists(key_file_path)); |
470 | 511 |
471 SystemUtils utils; | 512 SystemUtils utils; |
472 int32 file_size = 0; | 513 int32 file_size = 0; |
473 ASSERT_TRUE(utils.EnsureAndReturnSafeFileSize(key_file_path, &file_size)); | 514 ASSERT_TRUE(utils.EnsureAndReturnSafeFileSize(key_file_path, &file_size)); |
474 ASSERT_GT(file_size, 0); | 515 ASSERT_GT(file_size, 0); |
475 } | 516 } |
476 | 517 |
477 static const pid_t kDummyPid = 4; | |
478 TEST_F(SessionManagerTest, SessionNotStartedCleanup) { | 518 TEST_F(SessionManagerTest, SessionNotStartedCleanup) { |
479 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | 519 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); |
480 manager_->test_api().set_child_pid(0, kDummyPid); | 520 manager_->test_api().set_child_pid(0, kDummyPid); |
481 | 521 |
482 int timeout = 3; | 522 int timeout = 3; |
483 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGKILL)) | 523 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGKILL)) |
484 .WillOnce(Return(0)); | 524 .WillOnce(Return(0)); |
485 EXPECT_CALL(*(utils_.get()), ChildIsGone(kDummyPid, timeout)) | 525 EXPECT_CALL(*(utils_.get()), ChildIsGone(kDummyPid, timeout)) |
486 .WillOnce(Return(true)); | 526 .WillOnce(Return(true)); |
487 MockUtils(); | 527 MockUtils(); |
(...skipping 28 matching lines...) Expand all Loading... |
516 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGTERM)) | 556 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGTERM)) |
517 .WillOnce(Return(0)); | 557 .WillOnce(Return(0)); |
518 EXPECT_CALL(*(utils_.get()), ChildIsGone(kDummyPid, timeout)) | 558 EXPECT_CALL(*(utils_.get()), ChildIsGone(kDummyPid, timeout)) |
519 .WillOnce(Return(true)); | 559 .WillOnce(Return(true)); |
520 MockUtils(); | 560 MockUtils(); |
521 | 561 |
522 MockPrefStore* store = new MockPrefStore; | 562 MockPrefStore* store = new MockPrefStore; |
523 ExpectStartSession(email, job, store); | 563 ExpectStartSession(email, job, store); |
524 manager_->test_api().set_prefstore(store); | 564 manager_->test_api().set_prefstore(store); |
525 manager_->StartSession(email, nothing, &out, NULL); | 565 manager_->StartSession(email, nothing, &out, NULL); |
526 manager_->test_api().CleanupChildren(timeout); | 566 SimpleRunManager(store); |
527 } | 567 } |
528 | 568 |
529 TEST_F(SessionManagerTest, SessionStartedSlowKillCleanup) { | 569 TEST_F(SessionManagerTest, SessionStartedSlowKillCleanup) { |
530 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | 570 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); |
531 SessionManagerService::TestApi test_api = manager_->test_api(); | 571 manager_->test_api().set_child_pid(0, kDummyPid); |
532 test_api.set_child_pid(0, kDummyPid); | |
533 | 572 |
| 573 gboolean out; |
| 574 gchar email[] = "user@somewhere"; |
| 575 gchar nothing[] = ""; |
534 int timeout = 3; | 576 int timeout = 3; |
535 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGTERM)) | 577 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGTERM)) |
536 .WillOnce(Return(0)); | 578 .WillOnce(Return(0)); |
537 EXPECT_CALL(*(utils_.get()), ChildIsGone(kDummyPid, timeout)) | 579 EXPECT_CALL(*(utils_.get()), ChildIsGone(kDummyPid, timeout)) |
538 .WillOnce(Return(false)); | 580 .WillOnce(Return(false)); |
539 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGABRT)) | 581 EXPECT_CALL(*(utils_.get()), kill(kDummyPid, getuid(), SIGABRT)) |
540 .WillOnce(Return(0)); | 582 .WillOnce(Return(0)); |
541 MockUtils(); | 583 MockUtils(); |
542 | 584 |
543 gboolean out; | |
544 gchar email[] = "user@somewhere"; | |
545 gchar nothing[] = ""; | |
546 | |
547 MockPrefStore* store = new MockPrefStore; | 585 MockPrefStore* store = new MockPrefStore; |
548 ExpectStartSession(email, job, store); | 586 ExpectStartSession(email, job, store); |
549 manager_->test_api().set_prefstore(store); | 587 manager_->test_api().set_prefstore(store); |
550 manager_->StartSession(email, nothing, &out, NULL); | 588 manager_->StartSession(email, nothing, &out, NULL); |
551 test_api.CleanupChildren(timeout); | 589 SimpleRunManager(store); |
552 } | 590 } |
553 | 591 |
554 // Test that we avoid killing jobs that return true from their ShouldNeverKill() | 592 // Test that we avoid killing jobs that return true from their ShouldNeverKill() |
555 // methods. | 593 // methods. |
556 TEST_F(SessionManagerTest, HonorShouldNeverKill) { | 594 TEST_F(SessionManagerTest, HonorShouldNeverKill) { |
557 const int kNormalPid = 100; | 595 const int kNormalPid = 100; |
558 const int kShouldNeverKillPid = 101; | 596 const int kShouldNeverKillPid = 101; |
559 const int kTimeout = 3; | 597 const int kTimeout = 3; |
560 | 598 |
561 MockChildJob* normal_job = new MockChildJob; | 599 MockChildJob* normal_job = new MockChildJob; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 gboolean out; | 632 gboolean out; |
595 gchar email[] = "user@somewhere"; | 633 gchar email[] = "user@somewhere"; |
596 gchar nothing[] = ""; | 634 gchar nothing[] = ""; |
597 MockPrefStore* store = new MockPrefStore; | 635 MockPrefStore* store = new MockPrefStore; |
598 ExpectStartSession(email, job, store); | 636 ExpectStartSession(email, job, store); |
599 manager_->test_api().set_prefstore(store); | 637 manager_->test_api().set_prefstore(store); |
600 manager_->StartSession(email, nothing, &out, NULL); | 638 manager_->StartSession(email, nothing, &out, NULL); |
601 } | 639 } |
602 | 640 |
603 TEST_F(SessionManagerTest, StartSessionNew) { | 641 TEST_F(SessionManagerTest, StartSessionNew) { |
604 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | |
605 | |
606 gboolean out; | 642 gboolean out; |
607 gchar email[] = "user@somewhere"; | 643 gchar email[] = "user@somewhere"; |
608 gchar nothing[] = ""; | 644 gchar nothing[] = ""; |
609 MockPrefStore* store = new MockPrefStore; | 645 MockPrefStore* store = new MockPrefStore; |
610 ExpectStartSessionUnowned(email, job, store); | 646 ExpectStartSessionUnowned(email, store); |
611 manager_->test_api().set_prefstore(store); | |
612 chromeos::glib::ScopedError error; | 647 chromeos::glib::ScopedError error; |
613 EXPECT_EQ(TRUE, manager_->StartSession(email, | 648 EXPECT_EQ(TRUE, manager_->StartSession(email, |
614 nothing, | 649 nothing, |
615 &out, | 650 &out, |
616 &chromeos::Resetter(&error).lvalue())); | 651 &chromeos::Resetter(&error).lvalue())); |
| 652 |
| 653 SimpleRunManager(store); |
617 } | 654 } |
618 | 655 |
619 TEST_F(SessionManagerTest, StartOwnerSession) { | 656 TEST_F(SessionManagerTest, StartOwnerSession) { |
620 MockFactory<KeyCheckUtil> factory; | 657 MockFactory<KeyCheckUtil> factory; |
621 NssUtil::set_factory(&factory); | 658 NssUtil::set_factory(&factory); |
622 | 659 |
623 gboolean out; | 660 gboolean out; |
624 gchar email[] = "user@somewhere"; | 661 gchar email[] = "user@somewhere"; |
625 gchar nothing[] = ""; | 662 gchar nothing[] = ""; |
626 | 663 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 EXPECT_CALL(*job, ShouldStop()) | 750 EXPECT_CALL(*job, ShouldStop()) |
714 .WillOnce(Return(false)); | 751 .WillOnce(Return(false)); |
715 ON_CALL(*job, GetName()) | 752 ON_CALL(*job, GetName()) |
716 .WillByDefault(Return(std::string("foo"))); | 753 .WillByDefault(Return(std::string("foo"))); |
717 SimpleRunManager(new MockPrefStore); | 754 SimpleRunManager(new MockPrefStore); |
718 LOG(INFO) << "Finished the run!"; | 755 LOG(INFO) << "Finished the run!"; |
719 EXPECT_TRUE(file_util::PathExists(uptime)); | 756 EXPECT_TRUE(file_util::PathExists(uptime)); |
720 EXPECT_TRUE(file_util::PathExists(disk)); | 757 EXPECT_TRUE(file_util::PathExists(disk)); |
721 } | 758 } |
722 | 759 |
723 TEST_F(SessionManagerTest, SetOwnerKeyNoSession) { | 760 TEST_F(SessionManagerTest, SetOwnerKeyShouldFail) { |
724 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | 761 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); |
| 762 EXPECT_CALL(*(utils_.get()), |
| 763 SendSignalToChromium(chromium::kOwnerKeySetSignal, |
| 764 StrEq("failure"))) |
| 765 .Times(1); |
725 MockUtils(); | 766 MockUtils(); |
726 | 767 |
727 GError* error = NULL; | 768 GError* error = NULL; |
728 EXPECT_EQ(FALSE, manager_->SetOwnerKey(fake_key_, &error)); | 769 GArray* fake_key = CreateArray(kPropValue, strlen(kPropValue)); |
| 770 EXPECT_EQ(FALSE, manager_->SetOwnerKey(fake_key, &error)); |
729 EXPECT_EQ(CHROMEOS_LOGIN_ERROR_ILLEGAL_PUBKEY, error->code); | 771 EXPECT_EQ(CHROMEOS_LOGIN_ERROR_ILLEGAL_PUBKEY, error->code); |
| 772 g_array_free(fake_key, TRUE); |
730 g_error_free(error); | 773 g_error_free(error); |
731 } | 774 } |
732 | 775 |
733 TEST_F(SessionManagerTest, SetOwnerKeyNssDbFail) { | 776 TEST_F(SessionManagerTest, ValidateAndStoreOwnerKey) { |
734 MockFactory<SadNssUtil> factory; | |
735 NssUtil::set_factory(&factory); | |
736 | |
737 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | |
738 MockUtils(); | |
739 StartFakeSession(); | |
740 | |
741 GError* error = NULL; | |
742 EXPECT_EQ(FALSE, manager_->SetOwnerKey(fake_key_, &error)); | |
743 EXPECT_EQ(CHROMEOS_LOGIN_ERROR_NO_USER_NSSDB, error->code); | |
744 g_error_free(error); | |
745 } | |
746 | |
747 TEST_F(SessionManagerTest, SetOwnerKeyCheckFail) { | |
748 MockFactory<KeyFailUtil> factory; | |
749 NssUtil::set_factory(&factory); | |
750 | |
751 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | |
752 MockUtils(); | |
753 StartFakeSession(); | |
754 | |
755 GError* error = NULL; | |
756 EXPECT_EQ(FALSE, manager_->SetOwnerKey(fake_key_, &error)); | |
757 EXPECT_EQ(CHROMEOS_LOGIN_ERROR_ILLEGAL_PUBKEY, error->code); | |
758 g_error_free(error); | |
759 } | |
760 | |
761 TEST_F(SessionManagerTest, SetOwnerKeyPopulateFail) { | |
762 MockFactory<KeyCheckUtil> factory; | 777 MockFactory<KeyCheckUtil> factory; |
763 NssUtil::set_factory(&factory); | 778 NssUtil::set_factory(&factory); |
764 | 779 |
765 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | |
766 MockUtils(); | |
767 StartFakeSession(); | |
768 | |
769 std::vector<uint8> pub_key; | |
770 NssUtil::KeyFromBuffer(fake_key_, &pub_key); | |
771 | |
772 MockOwnerKey* key = new MockOwnerKey; | |
773 EXPECT_CALL(*key, PopulateFromBuffer(pub_key)) | |
774 .WillOnce(Return(false)); | |
775 manager_->test_api().set_ownerkey(key); | |
776 | |
777 GError* error = NULL; | |
778 EXPECT_EQ(FALSE, manager_->SetOwnerKey(fake_key_, &error)); | |
779 EXPECT_EQ(CHROMEOS_LOGIN_ERROR_ILLEGAL_PUBKEY, error->code); | |
780 g_error_free(error); | |
781 } | |
782 | |
783 TEST_F(SessionManagerTest, SetOwnerKey) { | |
784 MockFactory<KeyCheckUtil> factory; | |
785 NssUtil::set_factory(&factory); | |
786 | |
787 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | 780 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); |
788 EXPECT_CALL(*(utils_.get()), | 781 EXPECT_CALL(*(utils_.get()), |
789 SendSignalToChromium(chromium::kOwnerKeySetSignal, | 782 SendSignalToChromium(chromium::kOwnerKeySetSignal, |
790 StrEq("success"))) | 783 StrEq("success"))) |
791 .Times(1); | 784 .Times(1); |
792 EXPECT_CALL(*(utils_.get()), | 785 EXPECT_CALL(*(utils_.get()), |
793 SendSignalToChromium(chromium::kPropertyChangeCompleteSignal, | 786 SendSignalToChromium(chromium::kPropertyChangeCompleteSignal, |
794 StrEq("success"))) | 787 StrEq("success"))) |
795 .Times(1); | 788 .Times(1); |
796 EXPECT_CALL(*(utils_.get()), | 789 EXPECT_CALL(*(utils_.get()), |
797 SendSignalToChromium(chromium::kWhitelistChangeCompleteSignal, | 790 SendSignalToChromium(chromium::kWhitelistChangeCompleteSignal, |
798 StrEq("success"))) | 791 StrEq("success"))) |
799 .Times(1); | 792 .Times(1); |
800 MockUtils(); | 793 MockUtils(); |
801 StartFakeSession(); | |
802 | 794 |
803 std::vector<uint8> pub_key; | 795 std::vector<uint8> pub_key; |
804 NssUtil::KeyFromBuffer(fake_key_, &pub_key); | 796 NssUtil::KeyFromBuffer(kPropValue, &pub_key); |
805 | 797 |
806 MockPrefStore* store = new MockPrefStore; | 798 MockPrefStore* store = new MockPrefStore; |
807 MockOwnerKey* key = new MockOwnerKey; | 799 MockOwnerKey* key = new MockOwnerKey; |
808 EXPECT_CALL(*key, PopulateFromDiskIfPossible()) | 800 EXPECT_CALL(*key, PopulateFromDiskIfPossible()) |
809 .WillOnce(Return(true)); | 801 .WillOnce(Return(true)); |
810 EXPECT_CALL(*key, PopulateFromBuffer(pub_key)) | 802 EXPECT_CALL(*key, PopulateFromBuffer(pub_key)) |
811 .WillOnce(Return(true)); | 803 .WillOnce(Return(true)); |
812 EXPECT_CALL(*key, Sign(_, _, _)) | 804 EXPECT_CALL(*key, Sign(_, _, _)) |
813 .WillOnce(Return(true)) | 805 .WillOnce(Return(true)) |
814 .WillOnce(Return(true)); | 806 .WillOnce(Return(true)); |
815 EXPECT_CALL(*key, Persist()) | 807 EXPECT_CALL(*key, Persist()) |
816 .WillOnce(Return(true)); | 808 .WillOnce(Return(true)); |
817 | |
818 manager_->test_api().set_ownerkey(key); | 809 manager_->test_api().set_ownerkey(key); |
819 | 810 |
820 EXPECT_CALL(*store, Whitelist(kFakeEmail, _)) | 811 EXPECT_CALL(*store, Whitelist(kFakeEmail, _)) |
821 .Times(1); | 812 .Times(1); |
822 EXPECT_CALL(*store, Set(_, kFakeEmail, _)) | 813 EXPECT_CALL(*store, Set(_, kFakeEmail, _)) |
823 .Times(1); | 814 .Times(1); |
824 EXPECT_CALL(*store, Persist()) | 815 EXPECT_CALL(*store, Persist()) |
825 .WillOnce(Return(true)) | 816 .WillOnce(Return(true)) |
826 .WillOnce(Return(true)) | 817 .WillOnce(Return(true)) |
827 .WillOnce(Return(true)); | 818 .WillOnce(Return(true)); |
828 | 819 |
829 manager_->test_api().set_prefstore(store); | 820 manager_->test_api().set_prefstore(store); |
830 EXPECT_EQ(TRUE, manager_->SetOwnerKey(fake_key_, NULL)); | 821 StartFakeSession(); |
| 822 manager_->ValidateAndStoreOwnerKey(kPropValue); |
831 manager_->Run(); | 823 manager_->Run(); |
832 } | 824 } |
833 | 825 |
834 TEST_F(SessionManagerTest, WhitelistNoKey) { | 826 TEST_F(SessionManagerTest, WhitelistNoKey) { |
835 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); | 827 MockChildJob* job = CreateTrivialMockJob(MAYBE_NEVER); |
836 MockUtils(); | 828 MockUtils(); |
837 | 829 |
838 MockOwnerKey* key = new MockOwnerKey; | 830 MockOwnerKey* key = new MockOwnerKey; |
839 EXPECT_CALL(*key, PopulateFromDiskIfPossible()) | 831 EXPECT_CALL(*key, PopulateFromDiskIfPossible()) |
840 .WillOnce(Return(true)); | 832 .WillOnce(Return(true)); |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 } | 1329 } |
1338 | 1330 |
1339 TEST(SessionManagerTestStatic, GetArgLists3_InitialDashes) { | 1331 TEST(SessionManagerTestStatic, GetArgLists3_InitialDashes) { |
1340 const char* c_args[] = {"--", "a", "b", "c", NULL}; | 1332 const char* c_args[] = {"--", "a", "b", "c", NULL}; |
1341 std::vector<std::vector<std::string> > arg_lists = GetArgs(c_args); | 1333 std::vector<std::vector<std::string> > arg_lists = GetArgs(c_args); |
1342 EXPECT_EQ(1, arg_lists.size()); | 1334 EXPECT_EQ(1, arg_lists.size()); |
1343 EXPECT_EQ(3, arg_lists[0].size()); | 1335 EXPECT_EQ(3, arg_lists[0].size()); |
1344 } | 1336 } |
1345 | 1337 |
1346 } // namespace login_manager | 1338 } // namespace login_manager |
OLD | NEW |