Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ public static bool IsInAppContainer
}
}

public static bool CanRunImpersonatedTests => PlatformDetection.IsNotWindowsNanoServer && PlatformDetection.IsWindowsAndElevated;

private static int s_isWindowsElevated = -1;
public static bool IsWindowsAndElevated
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;
using Xunit;

namespace System
{
Expand Down Expand Up @@ -37,6 +38,8 @@ public sealed partial class WindowsTestAccount : IDisposable

public WindowsTestAccount(string userName)
{
Assert.True(PlatformDetection.IsWindowsAndElevated);

_userName = userName;
CreateUser();
}
Expand Down Expand Up @@ -77,6 +80,10 @@ private void CreateUser()
throw new Win32Exception((int)result);
}
}
else if (result != 0)
{
throw new Win32Exception((int)result);
}

const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -63,19 +64,21 @@ public async Task OpenOrCreate_DeleteOnClose_UsableAsMutex()
}
};

var sw = Stopwatch.StartNew();
var tasks = new Task[50];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = Task.Run(lockFile);
}

// Wait for 1000 locks.
cts.CancelAfter(TimeSpan.FromSeconds(120)); // Test timeout (reason for outerloop)
cts.CancelAfter(TimeSpan.FromSeconds(240)); // Test timeout (reason for outerloop)
Volatile.Write(ref locksRemaining, 500);
await Task.WhenAll(tasks);
sw.Stop();

Assert.True(exclusive, "Exclusive");
Assert.False(cts.IsCancellationRequested, "Test cancelled");
Assert.False(cts.IsCancellationRequested, $"Test cancelled with {locksRemaining}/500 locks remaining after {sw.Elapsed.TotalSeconds} seconds");
Assert.False(File.Exists(path), "File exists");
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace System.IO.Ports.Tests
Expand Down Expand Up @@ -127,14 +128,20 @@ private static char[] CallQueryDosDevice(string name, out int dataSize)
buffer = new char[buffer.Length * 2];
dataSize = QueryDosDevice(null, buffer, buffer.Length);
}
else if (lastError == ERROR_ACCESS_DENIED) // Access denied eg for "MSSECFLTSYS" - just skip
{
dataSize = 0;
break;
}
else
{
throw new Exception("Unknown Win32 Error: " + lastError);
throw new Exception($"Error {lastError} calling QueryDosDevice for '{name}' with buffer size {buffer.Length}. {new Win32Exception((int)lastError).Message}");
}
}
return buffer;
}

public const int ERROR_ACCESS_DENIED = 5;
public const int ERROR_INSUFFICIENT_BUFFER = 122;
public const int ERROR_MORE_DATA = 234;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace System.Net.Http.Functional.Tests
{
public class ImpersonatedAuthTests: IClassFixture<WindowsIdentityFixture>
{
public static bool CanRunImpersonatedTests = PlatformDetection.IsWindows && PlatformDetection.IsNotWindowsNanoServer;
private readonly WindowsIdentityFixture _fixture;
private readonly ITestOutputHelper _output;

Expand All @@ -28,11 +27,11 @@ public ImpersonatedAuthTests(WindowsIdentityFixture windowsIdentityFixture, ITe
}

[OuterLoop]
[ConditionalTheory(nameof(CanRunImpersonatedTests))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
[InlineData(true)]
[InlineData(false)]
[PlatformSpecific(TestPlatforms.Windows)]
public async Task DefaultHandler_ImpersonificatedUser_Success(bool useNtlm)
public async Task DefaultHandler_ImpersonatedUser_Success(bool useNtlm)
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ public async Task SendPingToExternalHostWithLowTtlTest()
options.Ttl = 1;
// This should always fail unless host is one IP hop away.
pingReply = await ping.SendPingAsync(host, TestSettings.PingTimeout, TestSettings.PayloadAsBytesShort, options);
Assert.Equal(IPStatus.TimeExceeded, pingReply.Status);
Assert.True(pingReply.Status == IPStatus.TimeExceeded || pingReply.Status == IPStatus.TtlExpired);
Assert.NotEqual(IPAddress.Any, pingReply.Address);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public WindowsIdentityImpersonatedTests(WindowsIdentityFixture windowsIdentityFi
Assert.False(string.IsNullOrEmpty(_fixture.TestAccount.AccountName));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
[OuterLoop]
public async Task RunImpersonatedAsync_TaskAndTaskOfT()
{
Expand Down Expand Up @@ -60,7 +60,7 @@ void Asserts(WindowsIdentity currentWindowsIdentity)
}
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
[OuterLoop]
public void RunImpersonated_NameResolution()
{
Expand All @@ -78,7 +78,7 @@ public void RunImpersonated_NameResolution()
});
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.CanRunImpersonatedTests))]
[OuterLoop]
public async Task RunImpersonatedAsync_NameResolution()
{
Expand Down