#5657 Use SerialKey class in ServerArgs

This commit is contained in:
Andrew Nelless 2016-10-17 17:38:05 +01:00
parent 88c59b4ca6
commit 99dbdc5eb3
5 changed files with 37 additions and 57 deletions

View File

@ -455,13 +455,9 @@ Server::switchScreen(BaseClientProxy* dst,
assert(dst != NULL);
// if trial is expired, exit the process
if (!m_args.m_serial.empty()) {
SerialKey serial(m_args.m_serial);
if (!serial.isValid(std::time(0))) {
if (!m_args.m_serial.isExpired(std::time(0))) {
LOG((CLOG_ERR "trial is expired, aborting server"));
exit(kExitSuccess);
return;
}
}
#ifndef NDEBUG

View File

@ -48,9 +48,6 @@ private:
#ifdef TEST_ENV
private:
FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString);
FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString);
FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText);
FRIEND_TEST(SerialKeyTests, parse_noParty_invalid);
FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid);
FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid);

View File

@ -71,7 +71,7 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
DpiHelper::s_primaryHeightCenter = synergy::string::stringToSizeType(argv[++i]);
}
else if (isArg(i, argc, argv, "", "--serial-key", 1)) {
args.m_serial = argv[++i];
args.m_serial = SerialKey(argv[++i]);
}
else {
LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE, args.m_pname, argv[i], args.m_pname));

View File

@ -18,6 +18,7 @@
#pragma once
#include "synergy/ArgsBase.h"
#include "shared/SerialKey.h"
class NetworkAddress;
class Config;
@ -28,6 +29,6 @@ public:
public:
String m_configFile;
String m_serial;
SerialKey m_serial;
Config* m_config;
};

View File

@ -64,17 +64,3 @@ TEST(ServerArgsParsingTests, parseServerArgs_configArg_setConfigFile)
EXPECT_EQ("mock_configFile", serverArgs.m_configFile);
}
TEST(ServerArgsParsingTests, parseServerArgs_serialArg_setSerial)
{
NiceMock<MockArgParser> argParser;
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(server_stubParseGenericArgs));
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(server_stubCheckUnexpectedArgs));
ServerArgs serverArgs;
const int argc = 3;
const char* kSerialCmd[argc] = { "stub", "--serial-key", "mock_serial" };
argParser.parseServerArgs(serverArgs, argc, kSerialCmd);
EXPECT_EQ("mock_serial", serverArgs.m_serial);
}