Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/chromeos/login/multi_profile_user_controller_unittest.cc

Issue 117263002: Prevent ONC-pushed certificates from being used with multiprofiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Philipps suggestion, another test Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium 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 "chrome/browser/chromeos/login/multi_profile_user_controller.h" 5 #include "chrome/browser/chromeos/login/multi_profile_user_controller.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/login/fake_user_manager.h" 10 #include "chrome/browser/chromeos/login/fake_user_manager.h"
10 #include "chrome/browser/chromeos/login/multi_profile_user_controller_delegate.h " 11 #include "chrome/browser/chromeos/login/multi_profile_user_controller_delegate.h "
11 #include "chrome/browser/chromeos/login/user_manager.h" 12 #include "chrome/browser/chromeos/login/user_manager.h"
13 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
14 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
15 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
12 #include "chrome/browser/prefs/browser_prefs.h" 16 #include "chrome/browser/prefs/browser_prefs.h"
13 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/scoped_testing_local_state.h" 18 #include "chrome/test/base/scoped_testing_local_state.h"
15 #include "chrome/test/base/testing_browser_process.h" 19 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h" 20 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/testing_profile_manager.h" 22 #include "chrome/test/base/testing_profile_manager.h"
23 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "net/cert/x509_certificate.h"
19 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
20 26
21 namespace chromeos { 27 namespace chromeos {
22 28
23 namespace { 29 namespace {
24 30
25 const char* kUsers[] = {"a@gmail.com", "b@gmail.com" }; 31 const char* kUsers[] = {"a@gmail.com", "b@gmail.com" };
26 32
27 struct BehaviorTestCase { 33 struct BehaviorTestCase {
28 const char* primary; 34 const char* primary;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 MultiProfileUserController::kBehaviorPrimaryOnly, 77 MultiProfileUserController::kBehaviorPrimaryOnly,
72 false, 78 false,
73 }, 79 },
74 { 80 {
75 MultiProfileUserController::kBehaviorNotAllowed, 81 MultiProfileUserController::kBehaviorNotAllowed,
76 MultiProfileUserController::kBehaviorNotAllowed, 82 MultiProfileUserController::kBehaviorNotAllowed,
77 false, 83 false,
78 }, 84 },
79 }; 85 };
80 86
87 policy::PolicyCertVerifier* g_policy_cert_verifier_for_factory = NULL;
88
89 BrowserContextKeyedService* TestPolicyCertServiceFactory(
90 content::BrowserContext* context) {
91 return policy::PolicyCertService::CreateForTesting(
92 kUsers[0], g_policy_cert_verifier_for_factory, UserManager::Get())
93 .release();
94 }
95
81 } // namespace 96 } // namespace
82 97
83 class MultiProfileUserControllerTest 98 class MultiProfileUserControllerTest
84 : public testing::Test, 99 : public testing::Test,
85 public MultiProfileUserControllerDelegate { 100 public MultiProfileUserControllerDelegate {
86 public: 101 public:
87 MultiProfileUserControllerTest() 102 MultiProfileUserControllerTest()
88 : profile_manager_(TestingBrowserProcess::GetGlobal()), 103 : profile_manager_(TestingBrowserProcess::GetGlobal()),
89 fake_user_manager_(new FakeUserManager), 104 fake_user_manager_(new FakeUserManager),
90 user_manager_enabler_(fake_user_manager_), 105 user_manager_enabler_(fake_user_manager_),
91 user_not_allowed_count_(0) {} 106 user_not_allowed_count_(0) {}
92 virtual ~MultiProfileUserControllerTest() {} 107 virtual ~MultiProfileUserControllerTest() {}
93 108
94 virtual void SetUp() OVERRIDE { 109 virtual void SetUp() OVERRIDE {
95 ASSERT_TRUE(profile_manager_.SetUp()); 110 ASSERT_TRUE(profile_manager_.SetUp());
96 controller_.reset(new MultiProfileUserController( 111 controller_.reset(new MultiProfileUserController(
97 this, TestingBrowserProcess::GetGlobal()->local_state())); 112 this, TestingBrowserProcess::GetGlobal()->local_state()));
98 113
99 for (size_t i = 0; i < arraysize(kUsers); ++i) { 114 for (size_t i = 0; i < arraysize(kUsers); ++i) {
100 const std::string user_email(kUsers[i]); 115 const std::string user_email(kUsers[i]);
101 fake_user_manager_->AddUser(user_email); 116 const User* user = fake_user_manager_->AddUser(user_email);
102 117
103 // Note that user profiles are created after user login in reality. 118 // Note that user profiles are created after user login in reality.
104 TestingProfile* user_profile = 119 TestingProfile* user_profile =
105 profile_manager_.CreateTestingProfile(user_email); 120 profile_manager_.CreateTestingProfile(user_email);
106 user_profile->set_profile_name(user_email); 121 user_profile->set_profile_name(user_email);
107 user_profiles_.push_back(user_profile); 122 user_profiles_.push_back(user_profile);
123
124 fake_user_manager_->SetProfileForUser(user, user_profile);
108 } 125 }
109 } 126 }
110 127
111 void LoginUser(size_t user_index) { 128 void LoginUser(size_t user_index) {
112 ASSERT_LT(user_index, arraysize(kUsers)); 129 ASSERT_LT(user_index, arraysize(kUsers));
113 fake_user_manager_->LoginUser(kUsers[user_index]); 130 fake_user_manager_->LoginUser(kUsers[user_index]);
114 controller_->StartObserving(user_profiles_[user_index]); 131 controller_->StartObserving(user_profiles_[user_index]);
115 } 132 }
116 133
117 void SetOwner(size_t user_index) { 134 void SetOwner(size_t user_index) {
(...skipping 23 matching lines...) Expand all
141 } 158 }
142 159
143 // MultiProfileUserControllerDeleagte overrides: 160 // MultiProfileUserControllerDeleagte overrides:
144 virtual void OnUserNotAllowed() OVERRIDE { 161 virtual void OnUserNotAllowed() OVERRIDE {
145 ++user_not_allowed_count_; 162 ++user_not_allowed_count_;
146 } 163 }
147 164
148 MultiProfileUserController* controller() { return controller_.get(); } 165 MultiProfileUserController* controller() { return controller_.get(); }
149 int user_not_allowed_count() const { return user_not_allowed_count_; } 166 int user_not_allowed_count() const { return user_not_allowed_count_; }
150 167
168 TestingProfile* profile(int index) {
169 return user_profiles_[index];
170 }
171
151 private: 172 private:
173 content::TestBrowserThreadBundle threads_;
152 TestingProfileManager profile_manager_; 174 TestingProfileManager profile_manager_;
153 FakeUserManager* fake_user_manager_; // Not owned 175 FakeUserManager* fake_user_manager_; // Not owned
154 ScopedUserManagerEnabler user_manager_enabler_; 176 ScopedUserManagerEnabler user_manager_enabler_;
155 177
156 scoped_ptr<MultiProfileUserController> controller_; 178 scoped_ptr<MultiProfileUserController> controller_;
157 179
158 std::vector<TestingProfile*> user_profiles_; 180 std::vector<TestingProfile*> user_profiles_;
159 181
160 int user_not_allowed_count_; 182 int user_not_allowed_count_;
161 183
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 LoginUser(0); 278 LoginUser(0);
257 SetOwner(1); 279 SetOwner(1);
258 280
259 EXPECT_FALSE(controller()->IsUserAllowedInSession(kUsers[1])); 281 EXPECT_FALSE(controller()->IsUserAllowedInSession(kUsers[1]));
260 282
261 EXPECT_EQ(0, user_not_allowed_count()); 283 EXPECT_EQ(0, user_not_allowed_count());
262 LoginUser(1); 284 LoginUser(1);
263 EXPECT_EQ(1, user_not_allowed_count()); 285 EXPECT_EQ(1, user_not_allowed_count());
264 } 286 }
265 287
288 TEST_F(MultiProfileUserControllerTest,
289 UsedPolicyCertificatesAllowedForPrimary) {
290 // Verifies that any user can sign-in as the primary user, regardless of the
291 // tainted state.
292 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(kUsers[0]);
293 EXPECT_TRUE(controller()->IsUserAllowedInSession(kUsers[0]));
294 EXPECT_TRUE(controller()->IsUserAllowedInSession(kUsers[1]));
295 }
296
297 TEST_F(MultiProfileUserControllerTest,
298 UsedPolicyCertificatesDisallowedForSecondary) {
299 // Verifies that if a regular user is signed-in then other regular users can
300 // be added but tainted users can't.
301 LoginUser(1);
302 EXPECT_TRUE(controller()->IsUserAllowedInSession(kUsers[0]));
303 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(kUsers[0]);
304 EXPECT_FALSE(controller()->IsUserAllowedInSession(kUsers[0]));
305 }
306
307 TEST_F(MultiProfileUserControllerTest,
308 UsedPolicyCertificatesDisallowsSecondaries) {
309 // Verifies that if a tainted user is signed-in then no other users can
310 // be added.
311 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(kUsers[0]);
312 LoginUser(0);
313
314 // Double parenthesis to avoid http://en.wikipedia.org/wiki/Most_vexing_parse.
315 policy::PolicyCertVerifier verifier((base::Closure()));
pneubeck (no reviews) 2013/12/19 11:35:09 nit: PolicyCertVerifier not required in this test
316 g_policy_cert_verifier_for_factory = &verifier;
317 ASSERT_TRUE(
318 policy::PolicyCertServiceFactory::GetInstance()->SetTestingFactoryAndUse(
319 profile(0), TestPolicyCertServiceFactory));
320
321 EXPECT_FALSE(controller()->IsUserAllowedInSession(kUsers[1]));
322 policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(kUsers[1]);
323 EXPECT_FALSE(controller()->IsUserAllowedInSession(kUsers[1]));
324
325 // Flush tasks posted to IO.
326 base::RunLoop().RunUntilIdle();
327 }
328
329 TEST_F(MultiProfileUserControllerTest,
330 PolicyCertificatesInMemoryDisallowsSecondaries) {
331 // Verifies that if a user is signed-in and has policy certificates installed
332 // then no other users can be added.
333 LoginUser(0);
334
335 // Double parenthesis to avoid http://en.wikipedia.org/wiki/Most_vexing_parse.
336 policy::PolicyCertVerifier verifier((base::Closure()));
337 g_policy_cert_verifier_for_factory = &verifier;
338 ASSERT_TRUE(
339 policy::PolicyCertServiceFactory::GetInstance()->SetTestingFactoryAndUse(
340 profile(0), TestPolicyCertServiceFactory));
341 policy::PolicyCertService* service =
342 policy::PolicyCertServiceFactory::GetForProfile(profile(0));
343 ASSERT_TRUE(service);
344
345 EXPECT_FALSE(service->has_policy_certificates());
346 EXPECT_TRUE(controller()->IsUserAllowedInSession(kUsers[1]));
347
348 net::CertificateList certificates;
349 certificates.push_back(new net::X509Certificate(
350 "subject", "issuer", base::Time(), base::Time()));
351 service->OnTrustAnchorsChanged(certificates);
352 EXPECT_TRUE(service->has_policy_certificates());
353 EXPECT_FALSE(controller()->IsUserAllowedInSession(kUsers[1]));
354
355 // Flush tasks posted to IO.
356 base::RunLoop().RunUntilIdle();
357 }
358
266 } // namespace chromeos 359 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/multi_profile_user_controller.cc ('k') | chrome/browser/chromeos/login/user_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698