fix bug where inheritance is incorrectly allowed on nodes under the root node after deserializing

This commit is contained in:
David Sparer
2018-03-10 16:37:54 -06:00
parent 6a5f65c018
commit 5076f1354c
7 changed files with 45 additions and 16 deletions

View File

@@ -19,20 +19,20 @@ namespace mRemoteNGTests.Config.Serializers.ConnectionSerializers.Csv
public class CsvConnectionsDeserializerMremotengFormatTests
{
private CsvConnectionsDeserializerMremotengFormat _deserializer;
private ICredentialRepositoryList _credentialRepositoryList;
private CsvConnectionsSerializerMremotengFormat _serializer;
[SetUp]
public void Setup()
{
_deserializer = new CsvConnectionsDeserializerMremotengFormat();
_credentialRepositoryList = Substitute.For<ICredentialRepositoryList>();
var credentialRepositoryList = Substitute.For<ICredentialRepositoryList>();
_serializer = new CsvConnectionsSerializerMremotengFormat(new SaveFilter(), credentialRepositoryList);
}
[TestCaseSource(typeof(DeserializationTestSource), nameof(DeserializationTestSource.ConnectionPropertyTestCases))]
public object ConnectionPropertiesDeserializedCorrectly(string propertyToCheck)
{
var serializer = new CsvConnectionsSerializerMremotengFormat(new SaveFilter(), _credentialRepositoryList);
var csv = serializer.Serialize(GetTestConnection());
var csv = _serializer.Serialize(GetTestConnection());
var deserializedConnections = _deserializer.Deserialize(csv);
var connection = deserializedConnections.GetRecursiveChildList().FirstOrDefault();
var propertyValue = typeof(ConnectionInfo).GetProperty(propertyToCheck)?.GetValue(connection);
@@ -42,10 +42,10 @@ namespace mRemoteNGTests.Config.Serializers.ConnectionSerializers.Csv
[TestCaseSource(typeof(DeserializationTestSource), nameof(DeserializationTestSource.InheritanceTestCases))]
public object InheritancePropertiesDeserializedCorrectly(string propertyToCheck)
{
var serializer = new CsvConnectionsSerializerMremotengFormat(new SaveFilter(), _credentialRepositoryList);
var csv = serializer.Serialize(GetTestConnectionWithAllInherited());
var csv = _serializer.Serialize(GetTestConnectionWithAllInherited());
var deserializedConnections = _deserializer.Deserialize(csv);
var connection = deserializedConnections.GetRecursiveChildList().FirstOrDefault();
connection?.RemoveParent();
var propertyValue = typeof(ConnectionInfoInheritance).GetProperty(propertyToCheck)?.GetValue(connection?.Inheritance);
return propertyValue;
}
@@ -58,8 +58,7 @@ namespace mRemoteNGTests.Config.Serializers.ConnectionSerializers.Csv
// | |- Con1
// |- Con2
var treeModel = new ConnectionTreeModelBuilder().Build();
var serializer = new CsvConnectionsSerializerMremotengFormat(new SaveFilter(), _credentialRepositoryList);
var csv = serializer.Serialize(treeModel);
var csv = _serializer.Serialize(treeModel);
var deserializedConnections = _deserializer.Deserialize(csv);
var con1 = deserializedConnections.GetRecursiveChildList().First(info => info.Name == "Con1");
var folder1 = deserializedConnections.GetRecursiveChildList().First(info => info.Name == "folder1");

View File

@@ -0,0 +1,18 @@
using mRemoteNG.Connection;
using mRemoteNG.Tree.Root;
using NUnit.Framework;
namespace mRemoteNGTests.Container
{
public class RootNodeInfoTests
{
[Test]
public void InheritanceIsDisabledForNodesDirectlyUnderRootNode()
{
var rootNode = new RootNodeInfo(RootNodeType.Connection);
var con1 = new ConnectionInfo { Inheritance = { Password = true } };
rootNode.AddChild(con1);
Assert.That(con1.Inheritance.Password, Is.False);
}
}
}

View File

@@ -146,6 +146,7 @@
<Compile Include="Connection\ConnectionInfoComparerTests.cs" />
<Compile Include="Connection\Protocol\IntegratedProgramTests.cs" />
<Compile Include="Connection\Protocol\ProtocolListTests.cs" />
<Compile Include="Container\RootNodeInfoTests.cs" />
<Compile Include="Credential\CompositeRepositoryUnlockerTests.cs" />
<Compile Include="Credential\CredentialChangedEventArgsTests.cs" />
<Compile Include="Credential\CredentialDeletionMsgBoxConfirmerTests.cs" />

View File

@@ -48,7 +48,10 @@ namespace mRemoteNG.Config.Serializers.Csv
{
// no parent mapped, add to root
if (string.IsNullOrEmpty(node.Value))
{
root.AddChild(node.Key);
continue;
}
// search for parent in the list by GUID
var parent = parentMapping

View File

@@ -131,15 +131,10 @@ namespace mRemoteNG.Connection
{
RemoveParent();
newParent?.AddChild(this);
if (newParent is RootNodeInfo)
Inheritance.DisableInheritance();
}
public void RemoveParent()
{
if (Parent is RootNodeInfo)
Inheritance.EnableInheritance();
Parent?.RemoveChild(this);
}

View File

@@ -63,7 +63,7 @@ namespace mRemoteNG.Container
AddChildAt(newChildItem, newChildIndex);
}
public void AddChildAt(ConnectionInfo newChildItem, int index)
public virtual void AddChildAt(ConnectionInfo newChildItem, int index)
{
if (Children.Contains(newChildItem)) return;
newChildItem.Parent?.RemoveChild(newChildItem);
@@ -81,7 +81,7 @@ namespace mRemoteNG.Container
}
}
public void RemoveChild(ConnectionInfo removalTarget)
public virtual void RemoveChild(ConnectionInfo removalTarget)
{
if (!Children.Contains(removalTarget)) return;
removalTarget.Parent = null;

View File

@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using mRemoteNG.Connection;
using mRemoteNG.Container;
using mRemoteNG.Tools;
@@ -68,5 +69,17 @@ namespace mRemoteNG.Tree.Root
return TreeNodeType.Root;
}
#endregion
}
public override void AddChildAt(ConnectionInfo newChildItem, int index)
{
newChildItem.Inheritance.DisableInheritance();
base.AddChildAt(newChildItem, index);
}
public override void RemoveChild(ConnectionInfo removalTarget)
{
removalTarget.Inheritance.EnableInheritance();
base.RemoveChild(removalTarget);
}
}
}