From 73ac3df22d9799ac8ddcbea79c24aa456d57a56c Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 11:41:51 -0700 Subject: [PATCH] Limit expired time to trial version #4716 --- src/lib/synergy/SubscriptionManager.cpp | 6 +++-- src/lib/synergy/SubscriptionManager.h | 5 ++-- .../unittests/synergy/SubscriptionTests.cpp | 25 +++++++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/lib/synergy/SubscriptionManager.cpp b/src/lib/synergy/SubscriptionManager.cpp index 2b51e17d..ecc272c3 100644 --- a/src/lib/synergy/SubscriptionManager.cpp +++ b/src/lib/synergy/SubscriptionManager.cpp @@ -150,12 +150,14 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& sscanf(parts.at(5).c_str(), "%d", &key.m_expireTime); // TODO: use Arch time - if (time(0) > key.m_expireTime) { + if (time(0) > key.m_expireTime && + key.m_type == "trial") { throw XSubscription(synergy::string::sprintf( "%s subscription has expired", key.m_type.c_str())); } - else if (time(0) > key.m_warnTime) { + else if (time(0) > key.m_warnTime && + key.m_type == "trial") { LOG((CLOG_WARN "%s subscription will expire soon", key.m_type.c_str())); } diff --git a/src/lib/synergy/SubscriptionManager.h b/src/lib/synergy/SubscriptionManager.h index 1f08006b..2817f768 100644 --- a/src/lib/synergy/SubscriptionManager.h +++ b/src/lib/synergy/SubscriptionManager.h @@ -41,8 +41,9 @@ private: FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText); FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException); - FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException); - FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey); private: String decode(const String& input); diff --git a/src/test/unittests/synergy/SubscriptionTests.cpp b/src/test/unittests/synergy/SubscriptionTests.cpp index 3e2c9dc9..368542ae 100644 --- a/src/test/unittests/synergy/SubscriptionTests.cpp +++ b/src/test/unittests/synergy/SubscriptionTests.cpp @@ -54,21 +54,22 @@ TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException) EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription); } -TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException) +TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey) { + // valid until 2 March 2049 SubscriptionManager subscriptionManager; - String painText("{v1;trial;Bob;1;1498297600;1498384000}"); + String painText("{v1;trial;Bob;1;2147483647;2147483647}"); SubscriptionKey key; subscriptionManager.parsePlainSerial(painText, key); EXPECT_EQ("trial", key.m_type); EXPECT_EQ("Bob", key.m_name); EXPECT_EQ(1, key.m_userLimit); - EXPECT_EQ(1498297600, key.m_warnTime); - EXPECT_EQ(1498384000, key.m_expireTime); + EXPECT_EQ(2147483647, key.m_warnTime); + EXPECT_EQ(2147483647, key.m_expireTime); } -TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException) +TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException) { SubscriptionManager subscriptionManager; String painText("{v1;trial;Bob;1;1398297600;1398384000}"); @@ -76,3 +77,17 @@ TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException) EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription); } + +TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey) +{ + SubscriptionManager subscriptionManager; + String painText("{v1;basic;Bob;1;1398297600;1398384000}"); + SubscriptionKey key; + subscriptionManager.parsePlainSerial(painText, key); + + EXPECT_EQ("basic", key.m_type); + EXPECT_EQ("Bob", key.m_name); + EXPECT_EQ(1, key.m_userLimit); + EXPECT_EQ(1398297600, key.m_warnTime); + EXPECT_EQ(1398384000, key.m_expireTime); +}