1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#define CATCH_CONFIG_MAIN
// clazy:excludeall=non-pod-global-static
#include "pluginloader.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);
}
SCENARIO("PluginLoader")
{
GIVEN("no plugin") {
const auto state = PluginLoader::signature_state(false, false, false);
PluginLoader loader("", state);
CHECK_FALSE(loader.verify());
CHECK_FALSE(loader.errorString().isEmpty());
}
GIVEN("A plugin with no signature")
{
const auto f = qgetenv("UNSIGNEDFILE");
REQUIRE(!f.isEmpty());
WHEN("sig is ignored") {
const auto state = PluginLoader::signature_state(true, false, false);
PluginLoader loader(f, state);
THEN("verify ok") {
REQUIRE(loader.verify());
}
}
}
GIVEN("A signed plugin")
{
REQUIRE(qEnvironmentVariableIsSet("SIGNEDFILE"));
}
GIVEN("A badly signed plugin")
{
REQUIRE(qEnvironmentVariableIsSet("BADSIGNEDFILE"));
}
}
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);
REQUIRE_FALSE(loader.verify());
REQUIRE_FALSE(loader.errorString().isEmpty());
}
TEST_CASE("PluginLoader::verify signature enforced [bad]")
{
const auto state = PluginLoader::signature_state(false, false, true);
PluginLoader loader(qgetenv("BADSIGNEDFILE"), state);
REQUIRE_FALSE(loader.verify());
REQUIRE_FALSE(loader.errorString().isEmpty());
}
|