Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport removing dead pwd code #48544

Merged
merged 2 commits into from
Mar 10, 2021
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 @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.ComponentModel;
Expand Down Expand Up @@ -351,11 +352,13 @@ public void TestWorkingDirectoryPropertyInChildProcess()
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/18978")]
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported)), PlatformSpecific(TestPlatforms.Windows), OuterLoop] // Uses P/Invokes, Requires admin privileges
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported)), PlatformSpecific(TestPlatforms.Windows), OuterLoop] // Uses P/Invokes, Requires admin privileges
public void TestUserCredentialsPropertiesOnWindows()
{
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Unit test dummy credentials.")]
string username = "test", password = "PassWord123!!";
const string username = "testForDotnetRuntime";
var bytes = new byte[33];
RandomNumberGenerator.Fill(bytes);
string password = Convert.ToBase64String(bytes) + "_-As@!%*(1)4#2";
try
{
Interop.NetUserAdd(username, password);
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;
using System.Collections.Generic;
using System.Security.Principal;
using Xunit;
Expand All @@ -15,8 +16,7 @@ public abstract class PrincipalTest : IDisposable

private void RefreshContext()
{
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Unit test dummy credentials.")]
string username = "Administrator", password = "Adrumble@6";
string username = "Administrator", password = Environment.GetEnvironmentVariable("TESTPASSWORD");

string OU = "Tests";
string baseDomain = WindowsIdentity.GetCurrent().Name.Split(new char[] { '\\' })[1] + "-TEST";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,5 @@ public void UserPrincipalConstructorTest()
UserPrincipal user = new UserPrincipal(DomainContext);
user.Dispose();
}

public void ComputedUACCheck()
{
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Unit test dummy credentials.")]
string username = "Administrator", password = "Adrumble@6";
//TODO: don't assume it exists, create it if its not
string OU = "TestNull";
string baseDomain =WindowsIdentity.GetCurrent().Name.Split(new char[] { '\\' })[1] + "-TEST";
string domain = $"{baseDomain}.nttest.microsoft.com";
string container = $"ou={OU},dc={baseDomain},dc=nttest,dc=microsoft,dc=com";

PrincipalContext context = new PrincipalContext(ContextType.Domain, domain, container, username, password);
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "good");

// set the wrong password to force account lockout
// Is there a way of doing it programmatically except for NetUserSetInfo? (managed code)
context.ValidateCredentials("good", "wrong password");

//verify that the account is locked out
Assert.True(user.IsAccountLockedOut(), "trying wrong credentials did not lock the account");

// if uac is not set correctly, this call might clear the lockout
user.SmartcardLogonRequired = false;
user.Save();

//verify that the account is still locked out
Assert.True(user.IsAccountLockedOut(), "the account is no longer locked out after writing setting SmartCardLogonRequired");
}
}
}