diff options
Diffstat (limited to 'lib/pluginloader/test')
-rw-r--r-- | lib/pluginloader/test/pluginloader-load.cpp | 22 | ||||
-rw-r--r-- | lib/pluginloader/test/pluginloader-sigmatch.cpp | 98 |
2 files changed, 111 insertions, 9 deletions
diff --git a/lib/pluginloader/test/pluginloader-load.cpp b/lib/pluginloader/test/pluginloader-load.cpp new file mode 100644 index 0000000..9c329a3 --- /dev/null +++ b/lib/pluginloader/test/pluginloader-load.cpp @@ -0,0 +1,22 @@ +#include "pluginloader.h" +#include <spdlog/spdlog.h> + +int main(int argc, char **argv) +{ + if(argc != 2) { + spdlog::error("usage: {} path/to/plugin.so", argv[0]); + return -1; + } + + const auto state = PluginLoader::signature_state(false, true, false); + PluginLoader loader(argv[1], state); + if(loader.load()) { + spdlog::info("Loaded plugin {}", argv[1]); + } else { + spdlog::error("Failed loading plugin {}", argv[1]); + spdlog::error(qUtf8Printable(loader.errorString())); + return -1; + } + + return 0; +} diff --git a/lib/pluginloader/test/pluginloader-sigmatch.cpp b/lib/pluginloader/test/pluginloader-sigmatch.cpp index 2e5a1ff..991d9bc 100644 --- a/lib/pluginloader/test/pluginloader-sigmatch.cpp +++ b/lib/pluginloader/test/pluginloader-sigmatch.cpp @@ -1,17 +1,97 @@ +#define CATCH_CONFIG_MAIN + #include "pluginloader.h" -#include <gtest/gtest.h> +#include <catch2/catch.hpp> + +TEST_CASE("PluginLoader::signature_state") +{ + // ignore + REQUIRE(PluginLoader::signature_state(true, false, false) == PluginLoader::SigIgnored); + + // check + REQUIRE(PluginLoader::signature_state(false, true, false) >= PluginLoader::SigChecked); + REQUIRE(PluginLoader::signature_state(false, true, false) < PluginLoader::SigEnforced); + REQUIRE(PluginLoader::signature_state(true, true, false) >= PluginLoader::SigChecked); + REQUIRE(PluginLoader::signature_state(true, true, false) < PluginLoader::SigEnforced); + + // enfore + REQUIRE(PluginLoader::signature_state(false, false, true) >= PluginLoader::SigEnforced); + REQUIRE(PluginLoader::signature_state(true, false, true) >= PluginLoader::SigEnforced); + REQUIRE(PluginLoader::signature_state(false, true, true) >= PluginLoader::SigEnforced); + REQUIRE(PluginLoader::signature_state(true, true, true) >= PluginLoader::SigEnforced); +} + +TEST_CASE("files") +{ + REQUIRE(qEnvironmentVariableIsSet("UNSIGNEDFILE")); + REQUIRE(qEnvironmentVariableIsSet("SIGNEDFILE")); + REQUIRE(qEnvironmentVariableIsSet("BADSIGNEDFILE")); +} + +TEST_CASE("PluginLoader::verify missing plugin") +{ + const auto state = PluginLoader::signature_state(false, false, false); + PluginLoader loader("", state); + + REQUIRE_FALSE(loader.verify()); + REQUIRE_FALSE(loader.errorString().isEmpty()); +} + +TEST_CASE("PluginLoader::verify signature ignored") +{ + const auto state = PluginLoader::signature_state(true, false, false); + PluginLoader loader(qgetenv("UNSIGNEDFILE"), state); + + REQUIRE(loader.verify()); +} -PluginLoader *loader = nullptr; +TEST_CASE("PluginLoader::verify signature checked [avialable]") +{ + const auto state = PluginLoader::signature_state(false, true, false); + PluginLoader loader(qgetenv("SIGNEDFILE"), state); + + REQUIRE(loader.verify()); +} + +TEST_CASE("PluginLoader::verify signature checked [missing]") +{ + const auto state = PluginLoader::signature_state(false, true, false); + PluginLoader loader(qgetenv("UNSIGNEDFILE"), state); + + REQUIRE(loader.verify()); +} + +TEST_CASE("PluginLoader::verify signature checked [bad]") +{ + const auto state = PluginLoader::signature_state(false, true, false); + PluginLoader loader(qgetenv("BADSIGNEDFILE"), state); + + REQUIRE_FALSE(loader.verify()); + REQUIRE_FALSE(loader.errorString().isEmpty()); +} + +TEST_CASE("PluginLoader::verify signature enforced [avialable]") +{ + const auto state = PluginLoader::signature_state(false, false, true); + PluginLoader loader(qgetenv("SIGNEDFILE"), state); + + REQUIRE(loader.verify()); +} + +TEST_CASE("PluginLoader::verify signature enforced [missing]") +{ + const auto state = PluginLoader::signature_state(false, false, true); + PluginLoader loader(qgetenv("UNSIGNEDFILE"), state); -TEST(PluginLoader, SignatureMatcher) { - EXPECT_TRUE(loader->verify()); + REQUIRE_FALSE(loader.verify()); + REQUIRE_FALSE(loader.errorString().isEmpty()); } -int main(int argc, char **argv) +TEST_CASE("PluginLoader::verify signature enforced [bad]") { - const PluginLoader::SignatureState state(false, true, false); - loader = new PluginLoader(qgetenv("SIGNEDFILE"), state); + const auto state = PluginLoader::signature_state(false, false, true); + PluginLoader loader(qgetenv("BADSIGNEDFILE"), state); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + REQUIRE_FALSE(loader.verify()); + REQUIRE_FALSE(loader.errorString().isEmpty()); } |