-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathTestSettings.h
More file actions
94 lines (78 loc) · 4.39 KB
/
TestSettings.h
File metadata and controls
94 lines (78 loc) · 4.39 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include <winget/Settings.h>
#include <winget/UserSettings.h>
#include <wil/resource.h>
#include <string>
namespace TestCommon
{
// Repeat the policy values here so we can catch unintended changes in the source.
const std::wstring WinGetPolicyValueName = L"EnableAppInstaller";
const std::wstring WinGetSettingsPolicyValueName = L"EnableSettings";
const std::wstring ExperimentalFeaturesPolicyValueName = L"EnableExperimentalFeatures";
const std::wstring LocalManifestsPolicyValueName = L"EnableLocalManifestFiles";
const std::wstring EnableHashOverridePolicyValueName = L"EnableHashOverride";
const std::wstring EnableLocalArchiveMalwareScanOverridePolicyValueName = L"EnableLocalArchiveMalwareScanOverride";
const std::wstring DefaultSourcePolicyValueName = L"EnableDefaultSource";
const std::wstring MSStoreSourcePolicyValueName = L"EnableMicrosoftStoreSource";
const std::wstring AdditionalSourcesPolicyValueName = L"EnableAdditionalSources";
const std::wstring AllowedSourcesPolicyValueName = L"EnableAllowedSources";
const std::wstring BypassCertificatePinningForMicrosoftStoreValueName = L"EnableBypassCertificatePinningForMicrosoftStore";
const std::wstring EnableWindowsPackageManagerCommandLineInterfaces = L"EnableWindowsPackageManagerCommandLineInterfaces";
const std::wstring ConfigurationPolicyValueName = L"EnableWindowsPackageManagerConfiguration";
const std::wstring ProxyCommandLineOptionsPolicyValueName = L"EnableWindowsPackageManagerProxyCommandLineOptions";
const std::wstring EnableExperimentsPolicyValueName = L"EnableExperiments";
const std::wstring SourceUpdateIntervalPolicyValueName = L"SourceAutoUpdateInterval";
const std::wstring SourceUpdateIntervalPolicyOldValueName = L"SourceAutoUpdateIntervalInMinutes";
const std::wstring AdditionalSourcesPolicyKeyName = L"AdditionalSources";
const std::wstring AllowedSourcesPolicyKeyName = L"AllowedSources";
void SetSetting(const AppInstaller::Settings::StreamDefinition& stream, std::string_view value);
void RemoveSetting(const AppInstaller::Settings::StreamDefinition& stream);
std::filesystem::path GetPathTo(const AppInstaller::Settings::StreamDefinition& stream);
// This type removes the settings file on creation and destruction to ensure that a test that modifies them can do so cleanly.
struct UserSettingsFileGuard
{
UserSettingsFileGuard();
~UserSettingsFileGuard();
};
[[nodiscard]] UserSettingsFileGuard DeleteUserSettingsFiles();
struct UserSettingsTest : AppInstaller::Settings::UserSettings
{
};
struct GroupPolicyTestOverride : AppInstaller::Settings::GroupPolicy
{
GroupPolicyTestOverride() : GroupPolicyTestOverride(RegCreateVolatileTestRoot().get()) {}
GroupPolicyTestOverride(const AppInstaller::Registry::Key& key);
~GroupPolicyTestOverride();
template<AppInstaller::Settings::ValuePolicy P>
void SetValue(const ValueType<P>& value)
{
m_values.Add<P>(value);
}
template<AppInstaller::Settings::ValuePolicy P>
void SetValue(ValueType<P> &&value)
{
m_values.Add<P>(std::move(value));
}
void SetState(AppInstaller::Settings::TogglePolicy::Policy policy, AppInstaller::Settings::PolicyState state);
};
// Matcher that lets us verify GroupPolicyExceptions.
struct GroupPolicyExceptionMatcher : public Catch::MatcherBase<AppInstaller::Settings::GroupPolicyException>
{
GroupPolicyExceptionMatcher(AppInstaller::Settings::TogglePolicy::Policy policy) : m_expectedPolicy(policy) {}
bool match(const AppInstaller::Settings::GroupPolicyException& e) const override
{
return e.Policy() == m_expectedPolicy;
}
std::string describe() const override
{
std::ostringstream result;
result << "has policy == " << m_expectedPolicy;
return result.str();
}
private:
AppInstaller::Settings::TogglePolicy::Policy m_expectedPolicy;
};
#define REQUIRE_POLICY_EXCEPTION(_expr_, _policy_) REQUIRE_THROWS_MATCHES(_expr_, AppInstaller::Settings::GroupPolicyException, TestCommon::GroupPolicyExceptionMatcher(_policy_))
}