aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2016-03-03 16:01:50 -0800
committerVitaly Buka <vitalybuka@google.com>2016-03-04 18:43:11 +0000
commit63feef5cad7104f3cd4a6e09adc1d5460c83e72c (patch)
tree3b214095d6adaf82f420f43eea6f3242d06c25fb /src
parent86e8f6303fefe0c48d93beefff016ea6e830a5a2 (diff)
downloadlibweave-63feef5cad7104f3cd4a6e09adc1d5460c83e72c.tar.gz
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>
Diffstat (limited to 'src')
-rw-r--r--src/privet/auth_manager.cc9
-rw-r--r--src/privet/auth_manager_unittest.cc9
2 files changed, 17 insertions, 1 deletions
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 @@ std::vector<uint8_t> AuthManager::GetRootClientAuthToken(
}
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 @@ TEST_F(AuthManagerTest, AccessTokenAfterReset) {
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(