public void AddToPasswordHistory(string computerName) { IComputer computer = directory.GetComputer(computerName); provider.ClearPassword(computer); provider.ClearPasswordHistory(computer); CollectionAssert.IsEmpty(provider.GetPasswordHistory(computer)); DateTime firstCreated = DateTime.UtcNow.Trim(TimeSpan.TicksPerSecond); DateTime firstExpiry = DateTime.UtcNow.AddDays(-3).Trim(TimeSpan.TicksPerSecond); string firstPassword = Guid.NewGuid().ToString(); provider.UpdateCurrentPassword(computer, firstPassword, firstCreated, firstExpiry, 0, MsMcsAdmPwdBehaviour.Ignore); DateTime secondCreated = DateTime.UtcNow.AddDays(2).Trim(TimeSpan.TicksPerSecond); DateTime secondExpiry = DateTime.UtcNow.AddDays(-5).Trim(TimeSpan.TicksPerSecond); string secondPassword = Guid.NewGuid().ToString(); provider.UpdateCurrentPassword(computer, secondPassword, secondCreated, secondExpiry, 30, MsMcsAdmPwdBehaviour.Ignore); System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create(); ps.AddCommand(new CmdletInfo("Get-LithnetLocalAdminPasswordHistory", typeof(GetLocalAdminPasswordHistory))); ps.AddParameter("ComputerName", computerName); var output = ps.Invoke(); Assert.AreEqual(1, output.Count); var passwords = output.Select(t => t.Properties["Password"].Value as string).ToList(); CollectionAssert.AreEquivalent(new[] { firstPassword }, passwords); }
public void AddToPasswordHistory(string computerName) { IComputer computer = directory.GetComputer(computerName); provider.ClearPassword(computer); provider.ClearPasswordHistory(computer); CollectionAssert.IsEmpty(provider.GetPasswordHistory(computer)); DateTime firstCreated = DateTime.UtcNow.Trim(TimeSpan.TicksPerSecond); DateTime firstExpiry = DateTime.UtcNow.AddDays(-3).Trim(TimeSpan.TicksPerSecond); string firstPassword = "******"; provider.UpdateCurrentPassword(computer, firstPassword, firstCreated, firstExpiry, 0); IReadOnlyList <ProtectedPasswordHistoryItem> history = provider.GetPasswordHistory(computer); ProtectedPasswordHistoryItem currentPassword = provider.GetCurrentPassword(computer, null); DateTime?currentExpiry = provider.GetExpiry(computer); Assert.IsNotNull(currentExpiry); Assert.AreEqual(0, history.Count); Assert.AreEqual(firstCreated, currentPassword.Created); Assert.AreEqual(null, currentPassword.Retired); Assert.AreEqual(firstPassword, currentPassword.EncryptedData); Assert.AreEqual(firstExpiry.Ticks, currentExpiry.Value.Ticks); Assert.AreEqual(firstExpiry, currentExpiry); DateTime secondCreated = DateTime.UtcNow.AddDays(2).Trim(TimeSpan.TicksPerSecond); DateTime secondExpiry = DateTime.UtcNow.AddDays(-5).Trim(TimeSpan.TicksPerSecond); string secondPassword = "******"; provider.UpdateCurrentPassword(computer, secondPassword, secondCreated, secondExpiry, 30); history = provider.GetPasswordHistory(computer); currentPassword = provider.GetCurrentPassword(computer, null); currentExpiry = provider.GetExpiry(computer); Assert.IsNotNull(currentExpiry); Assert.AreEqual(1, history.Count); ProtectedPasswordHistoryItem firstHistoryItem = history.First(); Assert.AreEqual(firstCreated, firstHistoryItem.Created); Assert.AreEqual(firstPassword, firstHistoryItem.EncryptedData); Assert.AreEqual(secondCreated, firstHistoryItem.Retired); Assert.AreEqual(secondExpiry, currentExpiry); Assert.AreEqual(secondPassword, currentPassword.EncryptedData); Assert.AreEqual(secondCreated, currentPassword.Created); Assert.AreEqual(null, currentPassword.Retired); }