dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.75k stars 190 forks source link

DOSvc unit test fails with 0x80010123 #465

Closed pl4nty closed 1 month ago

pl4nty commented 2 months ago

Describe the bug and how to reproduce

I've cloned the repo and targeted net6.0 on Windows 22631.3527, then modified DoSvcTests.cs to import System.Threading.Tasks and return a Task as required by NUnit.

dotnet test UnitTests\PInvoke\DOSvc fails with the following stack trace, running with admin or SYSTEM permissions. Apologies for the screenshot, it's on a VM without copy/paste:

image

What code is involved

UnitTests\PInvoke\DOSvc

Expected behavior

Test passes successfully. I can't find a successful CI run though, so this might be a regression.

pl4nty commented 1 month ago

Seems like CoSetProxyBlanket doesn't handle auth properly, so we need to initialize manually before IDOManager.

CoInitializeSecurity(
    PSECURITY_DESCRIPTOR.NULL,
    -1,
    [],
    (IntPtr)null,
    Rpc.RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_DEFAULT,
    Rpc.RPC_C_IMP_LEVEL.RPC_C_IMP_LEVEL_IMPERSONATE,
    dwCapabilities: EOLE_AUTHENTICATION_CAPABILITIES.EOAC_STATIC_CLOAKING
);

This starts a download, but the temp file remains empty until timeout. Get-DeliveryOptimizationStatus shows the download has completed though. I suspect an issue with the lock

dahall commented 1 month ago

Fixed test definition and support class