RootNodeInfo.PasswordString will now return either a custom password (if one is set) otherwise the default password

This commit is contained in:
David Sparer
2016-10-24 11:24:35 -06:00
parent ba878c7587
commit a0a92b9b40
2 changed files with 26 additions and 15 deletions

View File

@@ -1,5 +1,4 @@
using mRemoteNG.Security;
using mRemoteNG.Tree.Root;
using mRemoteNG.Tree.Root;
using NUnit.Framework;
@@ -18,12 +17,12 @@ namespace mRemoteNGTests.Tree
[Test]
public void DefaultPasswordReturnsExpectedValue()
{
var defaultPassword = _rootNodeInfo.DefaultPassword.ConvertToUnsecureString();
var defaultPassword = _rootNodeInfo.DefaultPassword;
Assert.That(defaultPassword, Is.EqualTo("mR3m"));
}
[TestCase("a", true)]
[TestCase("mR3m", true)]
[TestCase("mR3m", false)]
[TestCase("", false)]
[TestCase(null, false)]
public void PasswordPropertyReflectsWhetherACustomPasswordIsInUse(string password, bool expected)
@@ -31,5 +30,21 @@ namespace mRemoteNGTests.Tree
_rootNodeInfo.PasswordString = password;
Assert.That(_rootNodeInfo.Password, Is.EqualTo(expected));
}
[TestCase("")]
[TestCase(null)]
public void PasswordStringReturnsDefaultPasswordWhenNoCustomOneIsSet(string password)
{
_rootNodeInfo.PasswordString = password;
Assert.That(_rootNodeInfo.PasswordString, Is.EqualTo(_rootNodeInfo.DefaultPassword));
}
[TestCase("a")]
[TestCase("1234")]
public void PasswordStringReturnsCustomPassword(string password)
{
_rootNodeInfo.PasswordString = password;
Assert.That(_rootNodeInfo.PasswordString, Is.EqualTo(password));
}
}
}

View File

@@ -41,23 +41,19 @@ namespace mRemoteNG.Tree.Root
[Browsable(false)]
public string PasswordString
{
get { return _customPassword; }
get
{
return Password ? _customPassword : DefaultPassword;
}
set
{
if (!string.IsNullOrEmpty(value))
{
_customPassword = value;
Password = true;
}
else
{
Password = false;
}
_customPassword = value;
Password = !string.IsNullOrEmpty(value) && _customPassword != DefaultPassword;
}
}
[Browsable(false)]
public SecureString DefaultPassword { get; } = "mR3m".ConvertToSecureString();
public string DefaultPassword { get; } = "mR3m";
[Browsable(false)]
public RootNodeType Type {get; set;}