diff --git a/mRemoteNGTests/Tree/RootNodeInfoTests.cs b/mRemoteNGTests/Tree/RootNodeInfoTests.cs index 447314671..355a73338 100644 --- a/mRemoteNGTests/Tree/RootNodeInfoTests.cs +++ b/mRemoteNGTests/Tree/RootNodeInfoTests.cs @@ -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)); + } } } \ No newline at end of file diff --git a/mRemoteV1/Tree/Root/RootNodeInfo.cs b/mRemoteV1/Tree/Root/RootNodeInfo.cs index 2158f1c06..12701795f 100644 --- a/mRemoteV1/Tree/Root/RootNodeInfo.cs +++ b/mRemoteV1/Tree/Root/RootNodeInfo.cs @@ -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;}