<commit_before>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Security.Principal;
using Xunit;

public class SecurityIdentifierTests
{
    [Fact]
    public void ValidateGetCurrentUser()
    {
        using (WindowsIdentity identity = WindowsIdentity.GetCurrent(false))
        {
            Assert.NotNull(identity.User);
        }
    }

    [Fact]
    public void ValidateToString()
    {
        string sddl = null;
        using (WindowsIdentity me = WindowsIdentity.GetCurrent(false))
        {
            sddl = me.User.ToString();
        }

        Assert.NotNull(sddl);
        Assert.NotEmpty(sddl);
        Assert.StartsWith("S-1-5-", sddl); // sid prefix, version 1, user account type
        Assert.NotEqual('-', sddl[sddl.Length - 1]);

        string[] parts = sddl.Substring(6).Split('-');

        Assert.NotNull(parts);
        Assert.NotEmpty(parts);

        Assert.All(parts, part => uint.TryParse(part, out uint _));
    }

    [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer), nameof(PlatformDetection.IsNotWindowsServerCore))]
    public void ValidateToStringUsingWhoami()
    {
        string librarySid = null;
        using (WindowsIdentity me = WindowsIdentity.GetCurrent(false))
        {
            librarySid = me.User.ToString();
        }

        string windowsSid = null;
        string processArguments = " /user";
        // Call whois to get current sid
        Process whoamiProcess = new Process();<commit_msg>Disable failing ValidateToStringUsingWhoami/ValidateToString tests (#34396)<commit_after>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;
using System.Security.Principal;
using Xunit;

public class SecurityIdentifierTests
{
    [Fact]
    public void ValidateGetCurrentUser()
    {
        using (WindowsIdentity identity = WindowsIdentity.GetCurrent(false))
        {
            Assert.NotNull(identity.User);
        }
    }
    
    [ActiveIssue(34395)]
    [Fact]
    public void ValidateToString()
    {
        string sddl = null;
        using (WindowsIdentity me = WindowsIdentity.GetCurrent(false))
        {
            sddl = me.User.ToString();
        }

        Assert.NotNull(sddl);
        Assert.NotEmpty(sddl);
        Assert.StartsWith("S-1-5-", sddl); // sid prefix, version 1, user account type
        Assert.NotEqual('-', sddl[sddl.Length - 1]);

        string[] parts = sddl.Substring(6).Split('-');

        Assert.NotNull(parts);
        Assert.NotEmpty(parts);

        Assert.All(parts, part => uint.TryParse(part, out uint _));
    }

    [ActiveIssue(34395)]
    [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer), nameof(PlatformDetection.IsNotWindowsServerCore))]
    public void ValidateToStringUsingWhoami()
    {
        string librarySid = null;
        using (WindowsIdentity me = WindowsIdentity.GetCurrent(false))
        {
            librarySid = me.User.ToString();
        }

        string windowsSid = null;
        string processArguments = " /user";
        // Call whois to get current sid
        Process whoamiProcess = new Process();
{'fraction_non_alphanumeric': 0.10305775764439411, 'fraction_numerical': 0.007078142695356738, 'mean_word_length': 2.6649377593360994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4045896', 'n_tokens_mistral': 988, 'n_tokens_neox': 967, 'n_words': 249}