OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/cryptauth/cryptauth_enrollment_manager.h" | 5 #include "components/cryptauth/cryptauth_enrollment_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 clock_->SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds)); | 163 clock_->SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds)); |
164 enrollment_manager_.AddObserver(this); | 164 enrollment_manager_.AddObserver(this); |
165 | 165 |
166 private_key_ = | 166 private_key_ = |
167 secure_message_delegate_->GetPrivateKeyForPublicKey(public_key_); | 167 secure_message_delegate_->GetPrivateKeyForPublicKey(public_key_); |
168 secure_message_delegate_->set_next_public_key(public_key_); | 168 secure_message_delegate_->set_next_public_key(public_key_); |
169 | 169 |
170 CryptAuthEnrollmentManager::RegisterPrefs(pref_service_.registry()); | 170 CryptAuthEnrollmentManager::RegisterPrefs(pref_service_.registry()); |
171 pref_service_.SetUserPref( | 171 pref_service_.SetUserPref( |
172 prefs::kCryptAuthEnrollmentIsRecoveringFromFailure, | 172 prefs::kCryptAuthEnrollmentIsRecoveringFromFailure, |
173 new base::Value(false)); | 173 base::MakeUnique<base::Value>(false)); |
174 pref_service_.SetUserPref( | 174 pref_service_.SetUserPref( |
175 prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds, | 175 prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds, |
176 new base::Value(kLastEnrollmentTimeSeconds)); | 176 base::MakeUnique<base::Value>(kLastEnrollmentTimeSeconds)); |
177 pref_service_.SetUserPref(prefs::kCryptAuthEnrollmentReason, | 177 pref_service_.SetUserPref( |
178 new base::Value(INVOCATION_REASON_UNKNOWN)); | 178 prefs::kCryptAuthEnrollmentReason, |
| 179 base::MakeUnique<base::Value>(INVOCATION_REASON_UNKNOWN)); |
179 | 180 |
180 std::string public_key_b64, private_key_b64; | 181 std::string public_key_b64, private_key_b64; |
181 base::Base64UrlEncode(public_key_, | 182 base::Base64UrlEncode(public_key_, |
182 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 183 base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
183 &public_key_b64); | 184 &public_key_b64); |
184 base::Base64UrlEncode(private_key_, | 185 base::Base64UrlEncode(private_key_, |
185 base::Base64UrlEncodePolicy::INCLUDE_PADDING, | 186 base::Base64UrlEncodePolicy::INCLUDE_PADDING, |
186 &private_key_b64); | 187 &private_key_b64); |
187 pref_service_.SetString(prefs::kCryptAuthEnrollmentUserPublicKey, | 188 pref_service_.SetString(prefs::kCryptAuthEnrollmentUserPublicKey, |
188 public_key_b64); | 189 public_key_b64); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 329 |
329 enrollment_manager_.Start(); | 330 enrollment_manager_.Start(); |
330 EXPECT_TRUE(enrollment_manager_.IsEnrollmentValid()); | 331 EXPECT_TRUE(enrollment_manager_.IsEnrollmentValid()); |
331 EXPECT_EQ(base::Time::FromDoubleT(kLastEnrollmentTimeSeconds), | 332 EXPECT_EQ(base::Time::FromDoubleT(kLastEnrollmentTimeSeconds), |
332 enrollment_manager_.GetLastEnrollmentTime()); | 333 enrollment_manager_.GetLastEnrollmentTime()); |
333 } | 334 } |
334 | 335 |
335 TEST_F(CryptAuthEnrollmentManagerTest, InitWithExpiredEnrollment) { | 336 TEST_F(CryptAuthEnrollmentManagerTest, InitWithExpiredEnrollment) { |
336 pref_service_.SetUserPref( | 337 pref_service_.SetUserPref( |
337 prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds, | 338 prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds, |
338 new base::Value(kLastExpiredEnrollmentTimeSeconds)); | 339 base::MakeUnique<base::Value>(kLastExpiredEnrollmentTimeSeconds)); |
339 | 340 |
340 EXPECT_CALL(*sync_scheduler(), | 341 EXPECT_CALL(*sync_scheduler(), |
341 Start(clock_->Now() - base::Time::FromDoubleT( | 342 Start(clock_->Now() - base::Time::FromDoubleT( |
342 kLastExpiredEnrollmentTimeSeconds), | 343 kLastExpiredEnrollmentTimeSeconds), |
343 SyncScheduler::Strategy::AGGRESSIVE_RECOVERY)); | 344 SyncScheduler::Strategy::AGGRESSIVE_RECOVERY)); |
344 | 345 |
345 enrollment_manager_.Start(); | 346 enrollment_manager_.Start(); |
346 EXPECT_FALSE(enrollment_manager_.IsEnrollmentValid()); | 347 EXPECT_FALSE(enrollment_manager_.IsEnrollmentValid()); |
347 EXPECT_EQ(base::Time::FromDoubleT(kLastExpiredEnrollmentTimeSeconds), | 348 EXPECT_EQ(base::Time::FromDoubleT(kLastExpiredEnrollmentTimeSeconds), |
348 enrollment_manager_.GetLastEnrollmentTime()); | 349 enrollment_manager_.GetLastEnrollmentTime()); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // Simulate receiving a GCM push message, forcing the device to re-enroll. | 461 // Simulate receiving a GCM push message, forcing the device to re-enroll. |
461 gcm_manager_.PushReenrollMessage(); | 462 gcm_manager_.PushReenrollMessage(); |
462 auto completion_callback = | 463 auto completion_callback = |
463 FireSchedulerForEnrollment(INVOCATION_REASON_SERVER_INITIATED); | 464 FireSchedulerForEnrollment(INVOCATION_REASON_SERVER_INITIATED); |
464 | 465 |
465 EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true)); | 466 EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true)); |
466 completion_callback.Run(true); | 467 completion_callback.Run(true); |
467 } | 468 } |
468 | 469 |
469 } // namespace cryptauth | 470 } // namespace cryptauth |
OLD | NEW |