aboutsummaryrefslogtreecommitdiff
path: root/lib/pluginloader/test/pluginloader-sigmatch.cpp
blob: 0f4789a8348ed0d33fb88f2d0065e0e42719bb97 (plain)
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
#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);
}

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

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