Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 14 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | 14 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" |
| 15 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 15 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
| 16 #include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h" | 16 #include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h" |
| 17 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" | 17 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" |
| 18 #include "chrome/browser/chromeos/login/authenticator.h" | 18 #include "chrome/browser/chromeos/login/authenticator.h" |
| 19 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 19 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
| 20 #include "chrome/browser/chromeos/login/user_manager.h" | 20 #include "chrome/browser/chromeos/login/user_manager.h" |
| 21 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
| 22 #include "chrome/browser/net/predictor.h" | 22 #include "chrome/browser/net/predictor.h" |
| 23 #include "chrome/browser/policy/browser_policy_connector.h" | 23 #include "chrome/browser/policy/browser_policy_connector.h" |
| 24 #include "chrome/browser/policy/cloud_policy_data_store.h" | |
| 24 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 25 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/net/gaia/gaia_urls.h" | 29 #include "chrome/common/net/gaia/gaia_urls.h" |
| 29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 31 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
| 31 #include "chrome/test/base/testing_browser_process.h" | 32 #include "chrome/test/base/testing_browser_process.h" |
| 32 #include "chrome/test/base/testing_pref_service.h" | 33 #include "chrome/test/base/testing_pref_service.h" |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 47 | 48 |
| 48 using ::testing::DoAll; | 49 using ::testing::DoAll; |
| 49 using ::testing::Return; | 50 using ::testing::Return; |
| 50 using ::testing::SetArgPointee; | 51 using ::testing::SetArgPointee; |
| 51 using ::testing::_; | 52 using ::testing::_; |
| 52 using content::BrowserThread; | 53 using content::BrowserThread; |
| 53 | 54 |
| 54 const char kTrue[] = "true"; | 55 const char kTrue[] = "true"; |
| 55 const char kDomain[] = "domain.com"; | 56 const char kDomain[] = "domain.com"; |
| 56 const char kUsername[] = "user@domain.com"; | 57 const char kUsername[] = "user@domain.com"; |
| 58 const char kMode[] = "enterprise"; | |
| 59 const char kDeviceId[] = "100200300"; | |
| 57 const char kUsernameOtherDomain[] = "user@other.com"; | 60 const char kUsernameOtherDomain[] = "user@other.com"; |
| 58 const char kAttributeOwned[] = "enterprise.owned"; | 61 const char kAttributeOwned[] = "enterprise.owned"; |
| 59 const char kAttributeOwner[] = "enterprise.user"; | 62 const char kAttributeOwner[] = "enterprise.user"; |
| 63 const char kAttrEnterpriseDomain[] = "enterprise.domain"; | |
| 64 const char kAttrEnterpriseMode[] = "enterprise.mode"; | |
| 65 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id"; | |
| 60 | 66 |
| 61 const char kOAuthTokenCookie[] = "oauth_token=1234"; | 67 const char kOAuthTokenCookie[] = "oauth_token=1234"; |
| 62 const char kOAuthGetAccessTokenData[] = | 68 const char kOAuthGetAccessTokenData[] = |
| 63 "oauth_token=1234&oauth_token_secret=1234"; | 69 "oauth_token=1234&oauth_token_secret=1234"; |
| 64 const char kOAuthServiceTokenData[] = | 70 const char kOAuthServiceTokenData[] = |
| 65 "wrap_access_token=1234&wrap_access_token_expires_in=123456789"; | 71 "wrap_access_token=1234&wrap_access_token_expires_in=123456789"; |
| 66 | 72 |
| 67 const char kDMServer[] = "http://server/device_management"; | 73 const char kDMServer[] = "http://server/device_management"; |
| 68 const char kDMRegisterRequest[] = | 74 const char kDMRegisterRequest[] = |
| 69 "http://server/device_management?request=register"; | 75 "http://server/device_management?request=register"; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 .WillRepeatedly(Return(true)); | 149 .WillRepeatedly(Return(true)); |
| 144 EXPECT_CALL(*cryptohome_, TpmIsEnabled()) | 150 EXPECT_CALL(*cryptohome_, TpmIsEnabled()) |
| 145 .WillRepeatedly(Return(false)); | 151 .WillRepeatedly(Return(false)); |
| 146 EXPECT_CALL(*cryptohome_, IsMounted()) | 152 EXPECT_CALL(*cryptohome_, IsMounted()) |
| 147 .WillRepeatedly(Return(true)); | 153 .WillRepeatedly(Return(true)); |
| 148 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue)) | 154 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue)) |
| 149 .WillRepeatedly(Return(true)); | 155 .WillRepeatedly(Return(true)); |
| 150 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner, | 156 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner, |
| 151 kUsername)) | 157 kUsername)) |
| 152 .WillRepeatedly(Return(true)); | 158 .WillRepeatedly(Return(true)); |
| 159 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttrEnterpriseDomain, | |
| 160 kDomain)) | |
| 161 .WillRepeatedly(Return(true)); | |
| 162 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttrEnterpriseMode, | |
| 163 kMode)) | |
| 164 .WillRepeatedly(Return(true)); | |
| 165 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttrEnterpriseDeviceId, | |
| 166 kDeviceId)) | |
| 167 .WillRepeatedly(Return(true)); | |
| 153 EXPECT_CALL(*cryptohome_, InstallAttributesFinalize()) | 168 EXPECT_CALL(*cryptohome_, InstallAttributesFinalize()) |
| 154 .WillRepeatedly(Return(true)); | 169 .WillRepeatedly(Return(true)); |
| 155 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwned, _)) | 170 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwned, _)) |
| 156 .WillRepeatedly(DoAll(SetArgPointee<1>(kTrue), | 171 .WillRepeatedly(DoAll(SetArgPointee<1>(kTrue), |
| 157 Return(true))); | 172 Return(true))); |
| 158 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwner, _)) | 173 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwner, _)) |
| 159 .WillRepeatedly(DoAll(SetArgPointee<1>(kUsername), | 174 .WillRepeatedly(DoAll(SetArgPointee<1>(kUsername), |
| 160 Return(true))); | 175 Return(true))); |
| 176 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDomain, _)) | |
| 177 .WillRepeatedly(DoAll(SetArgPointee<1>(kDomain), | |
| 178 Return(true))); | |
| 179 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseMode, _)) | |
| 180 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), | |
| 181 Return(true))); | |
| 182 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) | |
| 183 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), | |
| 184 Return(true))); | |
| 161 test_api->SetCryptohomeLibrary(cryptohome_, true); | 185 test_api->SetCryptohomeLibrary(cryptohome_, true); |
| 162 | 186 |
| 163 browser_process_->SetProfileManager( | 187 browser_process_->SetProfileManager( |
| 164 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); | 188 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); |
| 165 connector_ = browser_process_->browser_policy_connector(); | 189 connector_ = browser_process_->browser_policy_connector(); |
| 166 connector_->Init(); | 190 connector_->Init(); |
| 167 | 191 |
| 168 loop_.RunAllPending(); | 192 loop_.RunAllPending(); |
| 169 } | 193 } |
| 170 | 194 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 const GaiaAuthConsumer::ClientLoginResult& creds, | 247 const GaiaAuthConsumer::ClientLoginResult& creds, |
| 224 bool pending_requests, | 248 bool pending_requests, |
| 225 bool using_oauth) OVERRIDE { | 249 bool using_oauth) OVERRIDE { |
| 226 FAIL() << "OnLoginSuccess not expected"; | 250 FAIL() << "OnLoginSuccess not expected"; |
| 227 } | 251 } |
| 228 | 252 |
| 229 void LockDevice(const std::string& username) { | 253 void LockDevice(const std::string& username) { |
| 230 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall()) | 254 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall()) |
| 231 .WillOnce(Return(true)) | 255 .WillOnce(Return(true)) |
| 232 .WillRepeatedly(Return(false)); | 256 .WillRepeatedly(Return(false)); |
| 257 policy::CloudPolicyDataStore* device_data_store = | |
| 258 const_cast<policy::CloudPolicyDataStore*>( | |
| 259 connector_->GetDeviceCloudPolicyDataStore()); | |
|
Mattias Nissler (ping if slow)
2012/02/20 12:22:54
can't you just call connector_->LockDevice()?
pastarmovj
2012/02/20 14:26:30
Done. As discussed offline made the accessors non-
| |
| 260 device_data_store->set_device_mode( | |
| 261 policy::CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE); | |
| 262 device_data_store->set_device_id(kDeviceId); | |
| 233 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, | 263 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, |
| 234 connector_->LockDevice(username)); | 264 connector_->LockDevice(username)); |
| 235 loop_.RunAllPending(); | 265 loop_.RunAllPending(); |
| 236 } | 266 } |
| 237 | 267 |
| 238 void PrepareProfile(const std::string& username) { | 268 void PrepareProfile(const std::string& username) { |
| 239 MockSessionManagerClient* session_managed_client = | 269 MockSessionManagerClient* session_managed_client = |
| 240 mock_dbus_thread_manager_.mock_session_manager_client(); | 270 mock_dbus_thread_manager_.mock_session_manager_client(); |
| 241 EXPECT_CALL(*session_managed_client, StartSession(_)); | 271 EXPECT_CALL(*session_managed_client, StartSession(_)); |
| 242 EXPECT_CALL(*cryptohome_, GetSystemSalt()) | 272 EXPECT_CALL(*cryptohome_, GetSystemSalt()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 EXPECT_TRUE(response.SerializeToString(&data)); | 315 EXPECT_TRUE(response.SerializeToString(&data)); |
| 286 fetcher->SetResponseString(data); | 316 fetcher->SetResponseString(data); |
| 287 return fetcher; | 317 return fetcher; |
| 288 } | 318 } |
| 289 | 319 |
| 290 TestURLFetcher* PrepareDMRegisterFetcher() { | 320 TestURLFetcher* PrepareDMRegisterFetcher() { |
| 291 em::DeviceManagementResponse response; | 321 em::DeviceManagementResponse response; |
| 292 em::DeviceRegisterResponse* register_response = | 322 em::DeviceRegisterResponse* register_response = |
| 293 response.mutable_register_response(); | 323 response.mutable_register_response(); |
| 294 register_response->set_device_management_token(kDMToken); | 324 register_response->set_device_management_token(kDMToken); |
| 325 register_response->set_enrollment_type( | |
| 326 em::DeviceRegisterResponse::ENTERPRISE); | |
| 295 return PrepareDMServiceFetcher(kDMRegisterRequest, response); | 327 return PrepareDMServiceFetcher(kDMRegisterRequest, response); |
| 296 } | 328 } |
| 297 | 329 |
| 298 TestURLFetcher* PrepareDMPolicyFetcher() { | 330 TestURLFetcher* PrepareDMPolicyFetcher() { |
| 299 em::DeviceManagementResponse response; | 331 em::DeviceManagementResponse response; |
| 300 response.mutable_policy_response()->add_response(); | 332 response.mutable_policy_response()->add_response(); |
| 301 return PrepareDMServiceFetcher(kDMPolicyRequest, response); | 333 return PrepareDMServiceFetcher(kDMPolicyRequest, response); |
| 302 } | 334 } |
| 303 | 335 |
| 304 protected: | 336 protected: |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 } | 487 } |
| 456 | 488 |
| 457 INSTANTIATE_TEST_CASE_P( | 489 INSTANTIATE_TEST_CASE_P( |
| 458 LoginUtilsBlockingLoginTestInstance, | 490 LoginUtilsBlockingLoginTestInstance, |
| 459 LoginUtilsBlockingLoginTest, | 491 LoginUtilsBlockingLoginTest, |
| 460 testing::Values(0, 1, 2, 3, 4, 5)); | 492 testing::Values(0, 1, 2, 3, 4, 5)); |
| 461 | 493 |
| 462 } // namespace | 494 } // namespace |
| 463 | 495 |
| 464 } | 496 } |
| OLD | NEW |