Fixed issues configuring devices with date before 2000.

BUG: 27484275
Change-Id: Ia7158fdea6cac60d8b99630b4cb43b5e368c3776
Reviewed-on: https://weave-review.googlesource.com/2817
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/src/privet/auth_manager.cc b/src/privet/auth_manager.cc
index d905a45..52d3a43 100644
--- a/src/privet/auth_manager.cc
+++ b/src/privet/auth_manager.cc
@@ -447,7 +447,14 @@
 }
 
 base::Time AuthManager::Now() const {
-  return clock_->Now();
+  base::Time now = clock_->Now();
+  static const base::Time k2010 = base::Time::FromTimeT(1262304000);
+  if (now >= k2010)
+    return now;
+  // Slowdown time before 1 Jan 2010. This will increase expiration time of
+  // access tokens but allow to handle dates which can not be handled by
+  // macaroon library.
+  return k2010 - base::TimeDelta::FromSeconds((k2010 - now).InSeconds() / 10);
 }
 
 bool AuthManager::IsValidAuthToken(const std::vector<uint8_t>& token,
diff --git a/src/privet/auth_manager_unittest.cc b/src/privet/auth_manager_unittest.cc
index 648027d..ba1862c 100644
--- a/src/privet/auth_manager_unittest.cc
+++ b/src/privet/auth_manager_unittest.cc
@@ -222,6 +222,15 @@
   EXPECT_TRUE(auth_.ParseAccessToken(token2, &user_info, nullptr));
 }
 
+TEST_F(AuthManagerTest, AccessTokenBeforeJ2000) {
+  EXPECT_CALL(clock_, Now())
+      .WillRepeatedly(Return(base::Time::FromTimeT(5678)));
+  UserInfo user_info;
+  auto token1 = auth_.CreateAccessToken(
+      UserInfo{AuthScope::kViewer, TestUserId{"555"}}, {});
+  EXPECT_TRUE(auth_.ParseAccessToken(token1, &user_info, nullptr));
+}
+
 TEST_F(AuthManagerTest, GetRootClientAuthToken) {
   EXPECT_EQ("WCCDQxkgAUYIGhudoQBCDABQX3fPR5zsPnrs9aOSvS7/eQ==",
             Base64Encode(