summaryrefslogtreecommitdiff
path: root/Externals/WIL/tests/WinVerifyTrustTest.cpp
blob: b132d4ae564cf0fd779ce4137964e104bb0040f1 (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

#include <Windows.h>
#include <wincrypt.h>
#include <mscat.h>
#include <softpub.h>

#include <memory>
#include <wintrust.h>

#include <wil/resource.h>

#include "common.h"

#pragma comment(lib, "Wintrust.lib")

TEST_CASE("WilWintrustWrapperTest::VerifyWintrustDataAllocateAndFree", "[resource][wintrust]")
{
    wil::unique_wintrust_data uwvtData;
    uwvtData.cbStruct = sizeof(WINTRUST_DATA);
    DWORD zero = 0;
    REQUIRE(sizeof(WINTRUST_DATA) == uwvtData.cbStruct);

    uwvtData.reset();
    REQUIRE(zero == uwvtData.cbStruct);
}

TEST_CASE("WilWintrustWrapperTest::VerifyUniqueHCATADMINAllocateAndFree", "[resource][wintrust]")
{
    wil::unique_hcatadmin hCatAdmin;

    REQUIRE(
        CryptCATAdminAcquireContext2(
        hCatAdmin.addressof(),
        nullptr,
        BCRYPT_SHA256_ALGORITHM,
        nullptr,
        0));

    REQUIRE(hCatAdmin.get() != nullptr);
    hCatAdmin.reset();
    REQUIRE(hCatAdmin.get() == nullptr);
}

#ifdef WIL_ENABLE_EXCEPTIONS
TEST_CASE("WilWintrustWrapperTest::VerifyUnqiueHCATINFOAllocate", "[resource][wintrust]")
{
    wil::shared_hcatadmin hCatAdmin;
    HCATINFO hCatInfo = nullptr;

    REQUIRE(
        CryptCATAdminAcquireContext2(
        hCatAdmin.addressof(),
        nullptr,
        BCRYPT_SHA256_ALGORITHM,
        nullptr,
        0));

    wil::unique_hcatinfo hCatInfoWrapper(hCatInfo, hCatAdmin);
    REQUIRE(hCatInfoWrapper.get() == nullptr);
}
#endif