mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 14:07:46 +08:00
Add tests for Password property edge cases
Added tests to verify that full file encryption works correctly when Password property is set directly without setting PasswordString, ensuring the fix prevents encryption failures. Co-authored-by: Kvarkas <3611964+Kvarkas@users.noreply.github.com>
This commit is contained in:
@@ -97,6 +97,36 @@ public class XmlRootNodeSerializerTests
|
||||
Assert.That(attributeValuePlainText, Is.EqualTo(expectedPlainText));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProtectedStringSerializedWhenPasswordPropertySetDirectly()
|
||||
{
|
||||
// Simulate edge case where Password property is set to true directly
|
||||
// without setting PasswordString (leaving _customPassword empty)
|
||||
_rootNodeInfo.Password = true;
|
||||
var element = _rootNodeSerializer.SerializeRootNodeInfo(_rootNodeInfo, _cryptographyProvider, _version);
|
||||
var attributeValue = element.Attribute(XName.Get("Protected"))?.Value;
|
||||
// Should use default password and serialize as "ThisIsNotProtected"
|
||||
var attributeValuePlainText =
|
||||
_cryptographyProvider.Decrypt(attributeValue, _rootNodeInfo.PasswordString.ConvertToSecureString());
|
||||
Assert.That(attributeValuePlainText, Is.EqualTo("ThisIsNotProtected"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FullFileEncryptionWorksWithPasswordPropertySetDirectly()
|
||||
{
|
||||
// Simulate edge case where Password property is set to true directly
|
||||
// This should not cause encryption to fail
|
||||
_rootNodeInfo.Password = true;
|
||||
var element = _rootNodeSerializer.SerializeRootNodeInfo(_rootNodeInfo, _cryptographyProvider, _version, fullFileEncryption: true);
|
||||
var fullFileEncryptionValue = element.Attribute(XName.Get("FullFileEncryption"))?.Value;
|
||||
Assert.That(bool.Parse(fullFileEncryptionValue), Is.True);
|
||||
// Verify Protected attribute can be decrypted successfully
|
||||
var protectedValue = element.Attribute(XName.Get("Protected"))?.Value;
|
||||
Assert.That(protectedValue, Is.Not.Null.And.Not.Empty);
|
||||
var decryptedProtected = _cryptographyProvider.Decrypt(protectedValue, _rootNodeInfo.PasswordString.ConvertToSecureString());
|
||||
Assert.That(decryptedProtected, Is.EqualTo("ThisIsNotProtected"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConfVersionSerialized()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user