File: src\Servers\IIS\IIS\test\Common.FunctionalTests\Infrastructure\SkipIfNotAdminAttribute.cs
Web Access
Project: src\src\Servers\IIS\IIS\test\IIS.NewHandler.FunctionalTests\IIS.NewHandler.FunctionalTests.csproj (IIS.NewHandler.FunctionalTests)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System;
using System.Security.Principal;
using Microsoft.AspNetCore.InternalTesting;
 
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests;
 
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class SkipIfNotAdminAttribute : Attribute, ITestCondition
{
    public bool IsMet
    {
        get
        {
            var identity = WindowsIdentity.GetCurrent();
            var principal = new WindowsPrincipal(identity);
            return principal.IsInRole(WindowsBuiltInRole.Administrator) || SkipInVSTSAttribute.RunningInVSTS;
        }
    }
 
    public string SkipReason => "The current process is not running as admin.";
}