From 261b1f422dabef8c6efd590d6753c0d0239aa0a5 Mon Sep 17 00:00:00 2001 From: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Date: Mon, 2 Nov 2020 18:11:03 +0300 Subject: [PATCH 1/2] SYNERGY-362 Improve license validation (#6816) * SYNERGY-362 Improve license validation * Update ChangeLog * SYNERGY-362 Improve license validation --- ChangeLog | 1 + src/gui/src/LicenseManager.cpp | 19 +++++++++++++++---- src/gui/src/LicenseManager.h | 4 +++- src/lib/shared/SerialKey.cpp | 14 ++++++++++++++ src/lib/shared/SerialKey.h | 10 ++++++---- src/test/unittests/shared/SerialKeyTests.cpp | 15 +++++++++++++++ 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93764d75d..5d9232f5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ Enhancements: - #6803 Update Synergy icons - #6800 Update behaviour when unregistered - #6806 Move to Github Action for general PR builds and tests +- #6816 Improve license validation v1.12.0-stable =========== diff --git a/src/gui/src/LicenseManager.cpp b/src/gui/src/LicenseManager.cpp index ee52f9a3a..3b7a3aef6 100644 --- a/src/gui/src/LicenseManager.cpp +++ b/src/gui/src/LicenseManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include LicenseManager::LicenseManager(AppConfig* appConfig) : m_AppConfig(appConfig), @@ -44,12 +45,9 @@ LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired) swap (serialKey, m_serialKey); m_AppConfig->setSerialKey(QString::fromStdString (m_serialKey.toString())); - emit serialKeyChanged(m_serialKey); emit showLicenseNotice(getLicenseNotice()); - if (!m_serialKey.isValid()) { - emit InvalidLicense(); - } + validateSerialKey(); if (m_serialKey.edition() != serialKey.edition()) { m_AppConfig->setEdition(m_serialKey.edition()); @@ -228,3 +226,16 @@ LicenseManager::getTemporaryNotice() const return Notice; } + +void +LicenseManager::validateSerialKey() const +{ + if (m_serialKey.isValid()) { + if (m_serialKey.isTemporary()){ + QTimer::singleShot(m_serialKey.getSpanLeft(), this, SLOT(validateSerialKey())); + } + } + else{ + emit InvalidLicense(); + } +} diff --git a/src/gui/src/LicenseManager.h b/src/gui/src/LicenseManager.h index d0401a5a3..9f8ec705e 100644 --- a/src/gui/src/LicenseManager.h +++ b/src/gui/src/LicenseManager.h @@ -47,8 +47,10 @@ private: AppConfig* m_AppConfig; SerialKey m_serialKey; +public slots: + void validateSerialKey() const; + signals: - void serialKeyChanged (SerialKey) const; void editionChanged (Edition) const; void InvalidLicense () const; void showLicenseNotice(const QString& notice) const; diff --git a/src/lib/shared/SerialKey.cpp b/src/lib/shared/SerialKey.cpp index 1db94308e..ed1854198 100644 --- a/src/lib/shared/SerialKey.cpp +++ b/src/lib/shared/SerialKey.cpp @@ -171,6 +171,20 @@ SerialKey::daysLeft(time_t currentTime) const return timeLeft / day + daysLeft; } +std::chrono::milliseconds +SerialKey::getSpanLeft(time_t time) const +{ + std::chrono::milliseconds timeLeft{-1}; + + if (isTemporary()){ + auto expire{std::chrono::system_clock::from_time_t(m_expireTime)}; + auto target{std::chrono::system_clock::from_time_t(time)}; + timeLeft = std::chrono::duration_cast(expire - target); + } + + return timeLeft; +} + std::string SerialKey::email() const { diff --git a/src/lib/shared/SerialKey.h b/src/lib/shared/SerialKey.h index cfaf19da6..77f03ce01 100644 --- a/src/lib/shared/SerialKey.h +++ b/src/lib/shared/SerialKey.h @@ -19,6 +19,7 @@ #include #include +#include #include "EditionType.h" #include "SerialKeyType.h" #include "SerialKeyEdition.h" @@ -38,10 +39,11 @@ public: bool isTrial() const; bool isTemporary() const; bool isValid() const; - time_t daysLeft(time_t currentTime) const; - std::string email() const; - Edition edition() const; - std::string toString() const; + time_t daysLeft(time_t currentTime) const; + std::chrono::milliseconds getSpanLeft(time_t time = ::time(0)) const; + std::string email() const; + Edition edition() const; + std::string toString() const; static std::string decode(const std::string& serial); diff --git a/src/test/unittests/shared/SerialKeyTests.cpp b/src/test/unittests/shared/SerialKeyTests.cpp index 4c7b09f12..cd34bdd37 100644 --- a/src/test/unittests/shared/SerialKeyTests.cpp +++ b/src/test/unittests/shared/SerialKeyTests.cpp @@ -226,4 +226,19 @@ TEST(SerialKeyTests, IsValidExpiredKey_false) EXPECT_EQ(false, serial.isValid()); } +TEST(SerialKeyTests, test_getSpanLeft) +{ + SerialKey key; + std::chrono::milliseconds expected{-1}; + EXPECT_EQ(expected, key.getSpanLeft()); +} + +TEST(SerialKeyTests, test_getSpanLeft_subscription) +{ + // {v2;subscription;basic;Bob;1;email;company name;0;86400} + SerialKey key("7B76323B737562736372697074696F6E3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D"); + std::chrono::milliseconds expected{1000}; + EXPECT_EQ(expected, key.getSpanLeft(86399)); +} + From 43ba3814968bb7ca73856b5fb77ff4706f1e771f Mon Sep 17 00:00:00 2001 From: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Date: Tue, 3 Nov 2020 11:41:12 +0300 Subject: [PATCH 2/2] =?UTF-8?q?SYNERGY-316=20Requires=20google=20test=20ev?= =?UTF-8?q?en=20when=20tests=20are=20disabled=20with=20BUI=E2=80=A6=20(#68?= =?UTF-8?q?25)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SYNERGY-316 Requires googletest even when tests are disabled with BUILD_TESTS=OFF * Update ChangeLog --- CMakeLists.txt | 2 +- ChangeLog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a1ff16aa..f5647f26c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -350,7 +350,7 @@ endif() # # Google Test # -if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ext/googletest/CMakeLists.txt") +if(BUILD_TESTS AND NOT EXISTS "${PROJECT_SOURCE_DIR}/ext/googletest/CMakeLists.txt") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() diff --git a/ChangeLog b/ChangeLog index 5d9232f5c..2613a021e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ Bug fixes: - #6814 The system asks to save twice. - #6817 Configure requires dns_sd.h for enterprise version - #6821 Blocker bugs found by sonar +- #6825 The system requires google test even when tests are disabled with BUILD_TESTS=OFF Enhancements: - #6750 Integrate SonarCloud for static analysis and test coverage