When running tests, don't actually send http requests from version checker, but mock the http service.
This commit is contained in:
parent
80c00974e2
commit
c4d975260e
@ -48,6 +48,7 @@ using cpputils::RandomGenerator;
|
|||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
using cpputils::SCryptSettings;
|
using cpputils::SCryptSettings;
|
||||||
using cpputils::Console;
|
using cpputils::Console;
|
||||||
|
using cpputils::HttpClient;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@ -72,8 +73,8 @@ using boost::chrono::milliseconds;
|
|||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
Cli::Cli(RandomGenerator &keyGenerator, const SCryptSettings &scryptSettings, shared_ptr<Console> console):
|
Cli::Cli(RandomGenerator &keyGenerator, const SCryptSettings &scryptSettings, shared_ptr<Console> console, shared_ptr<HttpClient> httpClient):
|
||||||
_keyGenerator(keyGenerator), _scryptSettings(scryptSettings), _console(console) {}
|
_keyGenerator(keyGenerator), _scryptSettings(scryptSettings), _console(console), _httpClient(httpClient) {}
|
||||||
|
|
||||||
void Cli::_showVersion() {
|
void Cli::_showVersion() {
|
||||||
cout << "CryFS Version " << version::VERSION_STRING << endl;
|
cout << "CryFS Version " << version::VERSION_STRING << endl;
|
||||||
@ -89,7 +90,7 @@ namespace cryfs {
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
cout << "WARNING! This is a debug build. Performance might be slow." << endl;
|
cout << "WARNING! This is a debug build. Performance might be slow." << endl;
|
||||||
#endif
|
#endif
|
||||||
VersionChecker versionChecker;
|
VersionChecker versionChecker(_httpClient);
|
||||||
optional<string> newestVersion = versionChecker.newestVersion();
|
optional<string> newestVersion = versionChecker.newestVersion();
|
||||||
if (newestVersion == none) {
|
if (newestVersion == none) {
|
||||||
cout << "Could not connect to cryfs.org to check for updates." << endl;
|
cout << "Could not connect to cryfs.org to check for updates." << endl;
|
||||||
|
@ -8,12 +8,13 @@
|
|||||||
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
||||||
#include <messmer/cpp-utils/io/Console.h>
|
#include <messmer/cpp-utils/io/Console.h>
|
||||||
#include <messmer/cpp-utils/random/RandomGenerator.h>
|
#include <messmer/cpp-utils/random/RandomGenerator.h>
|
||||||
|
#include <messmer/cpp-utils/network/HttpClient.h>
|
||||||
#include "CallAfterTimeout.h"
|
#include "CallAfterTimeout.h"
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
class Cli final {
|
class Cli final {
|
||||||
public:
|
public:
|
||||||
Cli(cpputils::RandomGenerator &keyGenerator, const cpputils::SCryptSettings &scryptSettings, std::shared_ptr<cpputils::Console> console);
|
Cli(cpputils::RandomGenerator &keyGenerator, const cpputils::SCryptSettings &scryptSettings, std::shared_ptr<cpputils::Console> console, std::shared_ptr<cpputils::HttpClient> httpClient);
|
||||||
int main(int argc, char *argv[]);
|
int main(int argc, char *argv[]);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -38,6 +39,7 @@ namespace cryfs {
|
|||||||
cpputils::RandomGenerator &_keyGenerator;
|
cpputils::RandomGenerator &_keyGenerator;
|
||||||
cpputils::SCryptSettings _scryptSettings;
|
cpputils::SCryptSettings _scryptSettings;
|
||||||
std::shared_ptr<cpputils::Console> _console;
|
std::shared_ptr<cpputils::Console> _console;
|
||||||
|
std::shared_ptr<cpputils::HttpClient> _httpClient;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Cli);
|
DISALLOW_COPY_AND_ASSIGN(Cli);
|
||||||
};
|
};
|
||||||
|
@ -18,10 +18,6 @@ using namespace cpputils::logging;
|
|||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
VersionChecker::VersionChecker()
|
|
||||||
:VersionChecker(make_shared<CurlHttpClient>()) {
|
|
||||||
}
|
|
||||||
|
|
||||||
VersionChecker::VersionChecker(shared_ptr<HttpClient> httpClient)
|
VersionChecker::VersionChecker(shared_ptr<HttpClient> httpClient)
|
||||||
: _versionInfo(_getVersionInfo(std::move(httpClient))) {
|
: _versionInfo(_getVersionInfo(std::move(httpClient))) {
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
class VersionChecker final {
|
class VersionChecker final {
|
||||||
public:
|
public:
|
||||||
VersionChecker();
|
|
||||||
//TODO Write a cpputils::shared_ref and use it
|
//TODO Write a cpputils::shared_ref and use it
|
||||||
VersionChecker(std::shared_ptr<cpputils::HttpClient> httpClient);
|
VersionChecker(std::shared_ptr<cpputils::HttpClient> httpClient);
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#include "cli/Cli.h"
|
#include "cli/Cli.h"
|
||||||
#include <messmer/cpp-utils/random/Random.h>
|
#include <messmer/cpp-utils/random/Random.h>
|
||||||
#include <messmer/cpp-utils/crypto/kdf/Scrypt.h>
|
#include <messmer/cpp-utils/crypto/kdf/Scrypt.h>
|
||||||
|
#include <messmer/cpp-utils/network/CurlHttpClient.h>
|
||||||
|
|
||||||
using namespace cryfs;
|
using namespace cryfs;
|
||||||
using cpputils::Random;
|
using cpputils::Random;
|
||||||
using cpputils::SCrypt;
|
using cpputils::SCrypt;
|
||||||
|
using cpputils::CurlHttpClient;
|
||||||
using std::make_shared;
|
using std::make_shared;
|
||||||
using cpputils::IOStreamConsole;
|
using cpputils::IOStreamConsole;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
auto &keyGenerator = Random::OSRandom();
|
auto &keyGenerator = Random::OSRandom();
|
||||||
return Cli(keyGenerator, SCrypt::DefaultSettings, make_shared<IOStreamConsole>()).main(argc, argv);
|
return Cli(keyGenerator, SCrypt::DefaultSettings, make_shared<IOStreamConsole>(), make_shared<CurlHttpClient>()).main(argc, argv);
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,10 @@
|
|||||||
#include <messmer/cpp-utils/tempfile/TempDir.h>
|
#include <messmer/cpp-utils/tempfile/TempDir.h>
|
||||||
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
||||||
#include "../../../src/cli/Cli.h"
|
#include "../../../src/cli/Cli.h"
|
||||||
|
#include "../../../src/cli/VersionChecker.h"
|
||||||
#include <messmer/cpp-utils/logging/logging.h>
|
#include <messmer/cpp-utils/logging/logging.h>
|
||||||
#include <messmer/cpp-utils/process/subprocess.h>
|
#include <messmer/cpp-utils/process/subprocess.h>
|
||||||
|
#include <messmer/cpp-utils/network/FakeHttpClient.h>
|
||||||
#include "../../testutils/MockConsole.h"
|
#include "../../testutils/MockConsole.h"
|
||||||
|
|
||||||
class CliTest : public ::testing::Test {
|
class CliTest : public ::testing::Test {
|
||||||
@ -23,6 +25,12 @@ public:
|
|||||||
cpputils::TempFile configfile;
|
cpputils::TempFile configfile;
|
||||||
std::shared_ptr<MockConsole> console;
|
std::shared_ptr<MockConsole> console;
|
||||||
|
|
||||||
|
std::shared_ptr<cpputils::HttpClient> _httpClient() {
|
||||||
|
std::shared_ptr<cpputils::FakeHttpClient> httpClient = std::make_shared<cpputils::FakeHttpClient>();
|
||||||
|
httpClient->addWebsite("https://www.cryfs.org/version_info.json", "{\"version_info\":{\"current\":\"0.8.5\"}}");
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
void run(std::vector<const char*> args) {
|
void run(std::vector<const char*> args) {
|
||||||
std::vector<char*> _args;
|
std::vector<char*> _args;
|
||||||
_args.reserve(args.size()+1);
|
_args.reserve(args.size()+1);
|
||||||
@ -31,7 +39,7 @@ public:
|
|||||||
_args.push_back(const_cast<char*>(arg));
|
_args.push_back(const_cast<char*>(arg));
|
||||||
}
|
}
|
||||||
auto &keyGenerator = cpputils::Random::PseudoRandom();
|
auto &keyGenerator = cpputils::Random::PseudoRandom();
|
||||||
cryfs::Cli(keyGenerator, cpputils::SCrypt::TestSettings, console).main(_args.size(), _args.data());
|
cryfs::Cli(keyGenerator, cpputils::SCrypt::TestSettings, console, _httpClient()).main(_args.size(), _args.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_EXIT_WITH_HELP_MESSAGE(std::vector<const char*> args, const std::string &message = "") {
|
void EXPECT_EXIT_WITH_HELP_MESSAGE(std::vector<const char*> args, const std::string &message = "") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user