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 250594b47..84e1e6aef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ Bug fixes: - #6817 Configure requires dns_sd.h for enterprise version - #6821 Blocker bugs found by sonar - #6826 SonarCloud Critical bugs +- #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 @@ -22,6 +23,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)); +} +