Skip to content

Commit 6dc654d

Browse files
authored
DynamicDependencies: Change IsElevated check from FAIL_FAST to RETURN(ErrorNotSupported) (#1563)
* Fixed powershell command line to not rely on system configuration * Fix misspelled name * Can't check for MddTryCreate...() failure due to elevation in a test method as the setup fixed called MddBootstrapInitialize and would have failed if elevated, or if different user context the setup fix wouldn't be right for it. That's OK. Bootstrap has an explicit test for the expected error so we're good * Tweaked test execution for GetCurrentPackageInfoTests to avoid false errors. Lacking this if you ran all the dyndep tests some of the others could color the process space distorting these tests behavior/results * Restored BootstrapTests to IsolationLevel=Method and moved the elevated tests to a separate class * Refactored Bootstrap tests fixtures for sharing/reuse. More to come * Cleanup up bootstrap tests fixtures' redundancy * Missed the help call; thanks Rohan!
1 parent 905cc0b commit 6dc654d

9 files changed

Lines changed: 74 additions & 34 deletions

File tree

dev/DynamicDependency/API/DataStore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "DataStore.h"
77

88
#include "DynamicDependencyDataStore_h.h"
9-
#include "winrt_msixdynamicdepednency.h"
9+
#include "winrt_msixdynamicdependency.h"
1010

1111
#include <wil/winrt.h>
1212

dev/DynamicDependency/API/DynamicDependency.vcxitems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTInprocModule.h" />
6161
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTModuleManager.h" />
6262
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTPackage.h" />
63-
<ClInclude Include="$(MSBuildThisFileDirectory)winrt_msixdynamicdepednency.h" />
63+
<ClInclude Include="$(MSBuildThisFileDirectory)winrt_msixdynamicdependency.h" />
6464
<ClInclude Include="$(MSBuildThisFileDirectory)winrt_namespaces.h" />
6565
</ItemGroup>
6666
<ItemGroup>

dev/DynamicDependency/API/DynamicDependency.vcxitems.filters

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@
4141
<ClInclude Include="$(MSBuildThisFileDirectory)MddCore.Architecture.h" />
4242
<ClInclude Include="$(MSBuildThisFileDirectory)PackageGraphManager.h" />
4343
<ClInclude Include="$(MSBuildThisFileDirectory)DataStore.h" />
44-
<ClInclude Include="$(MSBuildThisFileDirectory)winrt_msixdynamicdepednency.h" />
4544
<ClInclude Include="$(MSBuildThisFileDirectory)MddWinRT.h" />
4645
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTInprocModule.h" />
4746
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTModuleManager.h" />
4847
<ClInclude Include="$(MSBuildThisFileDirectory)WinRTPackage.h" />
4948
<ClInclude Include="$(MSBuildThisFileDirectory)MddLifetimeManagement.h" />
5049
<ClInclude Include="$(MSBuildThisFileDirectory)MddLifetimeManagementTest.h" />
5150
<ClInclude Include="$(MSBuildThisFileDirectory)appmodel_packageinfo.h" />
52-
<ClInclude Include="$(MSBuildThisFileDirectory)utf8.h" />
51+
<ClInclude Include="$(MSBuildThisFileDirectory)winrt_msixdynamicdepednency.h" />
5352
</ItemGroup>
5453
<ItemGroup>
5554
<Midl Include="$(MSBuildThisFileDirectory)M.AM.DynamicDependency.idl" />

dev/DynamicDependency/API/MsixDynamicDependency.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace MddCore
1313
{
1414
// Temporary check to prevent accidental misuse and false bug reports until we address Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
15-
void FailFastIfElevated()
15+
HRESULT FailIfElevated()
1616
{
17-
FAIL_FAST_HR_IF_MSG(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), Security::IntegrityLevel::IsElevated() || Security::IntegrityLevel::IsElevated(GetCurrentProcessToken()),
18-
"DynamicDependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567");
17+
RETURN_HR_IF_MSG(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), Security::IntegrityLevel::IsElevated() || Security::IntegrityLevel::IsElevated(GetCurrentProcessToken()),
18+
"DynamicDependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567");
19+
return S_OK;
1920
}
2021
}
2122

@@ -30,7 +31,7 @@ STDAPI MddTryCreatePackageDependency(
3031
_Outptr_result_maybenull_ PWSTR* packageDependencyId) noexcept try
3132
{
3233
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
33-
MddCore::FailFastIfElevated();
34+
THROW_IF_FAILED(MddCore::FailIfElevated());
3435

3536
*packageDependencyId = nullptr;
3637

@@ -46,7 +47,7 @@ STDAPI_(void) MddDeletePackageDependency(
4647
_In_ PCWSTR packageDependencyId) noexcept try
4748
{
4849
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
49-
MddCore::FailFastIfElevated();
50+
THROW_IF_FAILED(MddCore::FailIfElevated());
5051

5152
// Dynamic Dependencies requires a non-packaged process
5253
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
@@ -63,7 +64,7 @@ STDAPI MddAddPackageDependency(
6364
_Outptr_opt_result_maybenull_ PWSTR* packageFullName) noexcept try
6465
{
6566
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
66-
MddCore::FailFastIfElevated();
67+
THROW_IF_FAILED(MddCore::FailIfElevated());
6768

6869
*packageDependencyContext = nullptr;
6970
if (packageFullName)
@@ -83,7 +84,7 @@ STDAPI_(void) MddRemovePackageDependency(
8384
_In_ MDD_PACKAGEDEPENDENCY_CONTEXT packageDependencyContext) noexcept try
8485
{
8586
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
86-
MddCore::FailFastIfElevated();
87+
THROW_IF_FAILED(MddCore::FailIfElevated());
8788

8889
// Dynamic Dependencies requires a non-packaged process
8990
LOG_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
@@ -97,7 +98,7 @@ STDAPI MddGetResolvedPackageFullNameForPackageDependency(
9798
_Outptr_result_maybenull_ PWSTR* packageFullName) noexcept try
9899
{
99100
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
100-
MddCore::FailFastIfElevated();
101+
THROW_IF_FAILED(MddCore::FailIfElevated());
101102

102103
*packageFullName = nullptr;
103104

@@ -119,7 +120,7 @@ STDAPI MddGetIdForPackageDependencyContext(
119120
_Outptr_result_maybenull_ PWSTR* packageDependencyId) noexcept try
120121
{
121122
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
122-
MddCore::FailFastIfElevated();
123+
THROW_IF_FAILED(MddCore::FailIfElevated());
123124

124125
*packageDependencyId = nullptr;
125126

dev/DynamicDependency/API/winrt_msixdynamicdepednency.h renamed to dev/DynamicDependency/API/winrt_msixdynamicdependency.h

File renamed without changes.

dev/WindowsAppRuntime_BootstrapDLL/MddBootstrap.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ static std::wstring g_test_ddlmPackagePublisherId;
3030
namespace MddCore
3131
{
3232
// Temporary check to prevent accidental misuse and false bug reports until we address Issue #567 https://github.com/microsoft/WindowsAppSdk/issues/567
33-
void FailFastIfElevated()
33+
HRESULT FailIfElevated()
3434
{
35-
FAIL_FAST_HR_IF_MSG(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), Security::IntegrityLevel::IsElevated() || Security::IntegrityLevel::IsElevated(GetCurrentProcessToken()),
36-
"DynamicDependencies Bootstrap doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567");
35+
RETURN_HR_IF_MSG(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), Security::IntegrityLevel::IsElevated() || Security::IntegrityLevel::IsElevated(GetCurrentProcessToken()),
36+
"DynamicDependencies Bootstrap doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567");
37+
return S_OK;
3738
}
3839
}
3940

@@ -43,7 +44,7 @@ STDAPI MddBootstrapInitialize(
4344
PACKAGE_VERSION minVersion) noexcept try
4445
{
4546
// Dynamic Dependencies doesn't support elevation. See Issue #567 https://github.com/microsoft/WindowsAppSDK/issues/567
46-
MddCore::FailFastIfElevated();
47+
THROW_IF_FAILED(MddCore::FailIfElevated());
4748

4849
// Dynamic Dependencies Bootstrap API requires a non-packaged process
4950
LOG_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());

test/DynamicDependency/Test_Win32/TestMddBootstrap.cpp

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@ namespace TP = ::Test::Packages;
1010

1111
namespace Test::DynamicDependency
1212
{
13-
class BootstrapTests
13+
class BootstrapFixtures
1414
{
1515
public:
16-
BEGIN_TEST_CLASS(BootstrapTests)
17-
TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method")
18-
TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA")
19-
//TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser")
20-
END_TEST_CLASS()
21-
22-
TEST_CLASS_SETUP(Setup)
16+
static bool Setup()
2317
{
2418
// We need to find Microsoft.WindowsAppRuntime.Bootstrap.dll.
2519
// Normally it's colocated with the application (i.e. same dir as the exe)
@@ -47,7 +41,7 @@ namespace Test::DynamicDependency
4741
return true;
4842
}
4943

50-
TEST_CLASS_CLEANUP(Cleanup)
44+
static bool Cleanup()
5145
{
5246
m_bootstrapDll.reset();
5347

@@ -57,6 +51,56 @@ namespace Test::DynamicDependency
5751
return true;
5852
}
5953

54+
private:
55+
static wil::unique_hmodule m_bootstrapDll;
56+
};
57+
58+
wil::unique_hmodule Test::DynamicDependency::BootstrapFixtures::m_bootstrapDll;
59+
60+
class ElevatedBootstrapTests
61+
{
62+
public:
63+
BEGIN_TEST_CLASS(ElevatedBootstrapTests)
64+
TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method")
65+
TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA")
66+
TEST_METHOD_PROPERTY(L"RunAs", L"ElevatedUser")
67+
END_TEST_CLASS()
68+
69+
TEST_METHOD(Initialize_Elevated)
70+
{
71+
BootstrapFixtures::Setup();
72+
auto cleanup = wil::scope_exit([&]{
73+
BootstrapFixtures::Cleanup();
74+
});
75+
76+
VERIFY_ARE_EQUAL(S_OK, MddBootstrapTestInitialize(Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId));
77+
78+
// Major.Minor version, MinVersion=0 to find any framework package for this major.minor version
79+
const UINT32 c_Version_MajorMinor{ Test::Packages::DynamicDependencyLifetimeManager::c_Version_MajorMinor };
80+
const PACKAGE_VERSION minVersion{};
81+
VERIFY_ARE_EQUAL(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), MddBootstrapInitialize(c_Version_MajorMinor, nullptr, minVersion));
82+
}
83+
};
84+
85+
class BootstrapTests
86+
{
87+
public:
88+
BEGIN_TEST_CLASS(BootstrapTests)
89+
TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method")
90+
TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA")
91+
//TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser")
92+
END_TEST_CLASS()
93+
94+
TEST_CLASS_SETUP(Setup)
95+
{
96+
return BootstrapFixtures::Setup();
97+
}
98+
99+
TEST_CLASS_CLEANUP(Cleanup)
100+
{
101+
return BootstrapFixtures::Cleanup();
102+
}
103+
60104
TEST_METHOD(Initialize_DDLMNotFound)
61105
{
62106
VERIFY_ARE_EQUAL(S_OK, MddBootstrapTestInitialize(Test::Packages::DynamicDependencyLifetimeManager::c_PackageNamePrefix, Test::Packages::DynamicDependencyLifetimeManager::c_PackagePublisherId));
@@ -186,10 +230,5 @@ namespace Test::DynamicDependency
186230
VERIFY_ARE_EQUAL(0u, bufferLength);
187231
}
188232
}
189-
190-
private:
191-
static wil::unique_hmodule m_bootstrapDll;
192233
};
193234
}
194-
195-
wil::unique_hmodule Test::DynamicDependency::BootstrapTests::m_bootstrapDll;

test/DynamicDependency/Test_Win32/Test_GetCurrentPackageInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Test::DynamicDependency
1717
{
1818
public:
1919
BEGIN_TEST_CLASS(GetCurrentPackageInfoTests)
20-
//TEST_CLASS_PROPERTY(L"IsolationLevel", L"Method")
20+
TEST_CLASS_PROPERTY(L"IsolationLevel", L"Class")
2121
TEST_CLASS_PROPERTY(L"ThreadingModel", L"MTA")
2222
//TEST_CLASS_PROPERTY(L"RunFixtureAs:Class", L"RestrictedUser")
2323
END_TEST_CLASS()

tools/DevCheck.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ SETLOCAL
44
IF /I "%1" == "-help" GOTO Help
55
IF /I "%1" == "--help" GOTO Help
66

7-
powershell %~dpn0.ps1 %*
7+
powershell -ExecutionPolicy Unrestricted -NoLogo -NoProfile %~dpn0.ps1 %*
88
GOTO TheEnd
99

1010
:Help
11-
powershell -c Get-Help %~dpn0.ps1 -full
11+
powershell -ExecutionPolicy Unrestricted -NoLogo -NoProfile -c Get-Help %~dpn0.ps1 -full
1212

1313
:TheEnd
1414
ENDLOCAL

0 commit comments

Comments
 (0)