Merge branch 'master' into SYNERGY-509-sonarcloud-critical-bugs-in-synergy-core

This commit is contained in:
Ignacio Rodríguez
2020-11-03 18:00:09 +07:00
committed by GitHub
7 changed files with 56 additions and 10 deletions

View File

@ -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()

View File

@ -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
===========

View File

@ -21,6 +21,7 @@
#include <stdexcept>
#include <utility>
#include <QThread>
#include <QTimer>
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();
}
}

View File

@ -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;

View File

@ -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<std::chrono::milliseconds>(expire - target);
}
return timeLeft;
}
std::string
SerialKey::email() const
{

View File

@ -19,6 +19,7 @@
#include <string>
#include <ctime>
#include <chrono>
#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);

View File

@ -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));
}