Limit expired time to trial version #4716

This commit is contained in:
Jerry (Xinyu Hou) 2015-10-30 11:41:51 -07:00
parent 068b3b98ed
commit 73ac3df22d
3 changed files with 27 additions and 9 deletions

View File

@ -150,12 +150,14 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
sscanf(parts.at(5).c_str(), "%d", &key.m_expireTime); sscanf(parts.at(5).c_str(), "%d", &key.m_expireTime);
// TODO: use Arch time // 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( throw XSubscription(synergy::string::sprintf(
"%s subscription has expired", "%s subscription has expired",
key.m_type.c_str())); 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", LOG((CLOG_WARN "%s subscription will expire soon",
key.m_type.c_str())); key.m_type.c_str()));
} }

View File

@ -41,8 +41,9 @@ private:
FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText); FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText);
FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException);
FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException);
FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey);
FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException);
FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey);
private: private:
String decode(const String& input); String decode(const String& input);

View File

@ -54,21 +54,22 @@ TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException)
EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription); EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription);
} }
TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException) TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey)
{ {
// valid until 2 March 2049
SubscriptionManager subscriptionManager; SubscriptionManager subscriptionManager;
String painText("{v1;trial;Bob;1;1498297600;1498384000}"); String painText("{v1;trial;Bob;1;2147483647;2147483647}");
SubscriptionKey key; SubscriptionKey key;
subscriptionManager.parsePlainSerial(painText, key); subscriptionManager.parsePlainSerial(painText, key);
EXPECT_EQ("trial", key.m_type); EXPECT_EQ("trial", key.m_type);
EXPECT_EQ("Bob", key.m_name); EXPECT_EQ("Bob", key.m_name);
EXPECT_EQ(1, key.m_userLimit); EXPECT_EQ(1, key.m_userLimit);
EXPECT_EQ(1498297600, key.m_warnTime); EXPECT_EQ(2147483647, key.m_warnTime);
EXPECT_EQ(1498384000, key.m_expireTime); EXPECT_EQ(2147483647, key.m_expireTime);
} }
TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException) TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException)
{ {
SubscriptionManager subscriptionManager; SubscriptionManager subscriptionManager;
String painText("{v1;trial;Bob;1;1398297600;1398384000}"); String painText("{v1;trial;Bob;1;1398297600;1398384000}");
@ -76,3 +77,17 @@ TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException)
EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription); 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);
}