Ejemplo n.º 1
0
        public void TestRootOfNonExistantPropertyReturnsNotNull() {
            IConfig config = new Config().Create<MockSimpleConcrete>();

            var root = config.RootOf<TestRootOf>();

            Assert.IsNotNull(root);
        }
Ejemplo n.º 2
0
        public void TestExplicitTypeRootOfSingleProperty() {
            IConfig config = new Config().Create<MockSimpleConcrete>();

            var root = config.RootOf(typeof(MockSimpleConcrete));

            Assert.AreEqual("Potato.Core.Shared.Test.TestConfig.Mocks.MockSimpleConcrete", ((JProperty)root.Parent).Name);
        }
Ejemplo n.º 3
0
        public void TestRootOfNotCreatedForProperty() {
            IConfig config = new Config().Create<MockSimpleConcrete>();
            config.Document.Add(new JProperty("Potato.Core.Shared.Test.TestConfig.TestRootOf", new JArray()));

            var root = config.RootOf<TestRootOf>();

            Assert.AreEqual("Potato.Core.Shared.Test.TestConfig.TestRootOf", ((JProperty)root.Parent).Name);
        }
Ejemplo n.º 4
0
        public void TestRootOfMultipleProperties() {
            IConfig config = new Config().Create<MockSimpleConcrete>();
            config.Document.Add(new JProperty("Potato.Core.Shared.Test.TestConfig.Mocks.DoesNotExist", new JArray()));

            var root = config.RootOf<MockSimpleConcrete>();

            Assert.AreEqual("Potato.Core.Shared.Test.TestConfig.Mocks.MockSimpleConcrete", ((JProperty)root.Parent).Name);
        }
Ejemplo n.º 5
0
        public void TestPotatoConfigWritten() {
            var instance = (PotatoController)new PotatoController() {
                Shared = {
                    Variables = new VariableController().Execute() as VariableController,
                    Security = new SecurityController().Execute() as SecurityController,
                    Events = new EventsController().Execute() as EventsController,
                    Languages = new LanguageController().Execute() as LanguageController
                }
            }.Execute();

            instance.Shared.Variables.Tunnel(CommandBuilder.VariablesSet(CommonVariableNames.PotatoConfigPassword, "PotatoConfigurationPassword").SetOrigin(CommandOrigin.Local));

            instance.Connections.Add(new ConnectionController() {
                ConnectionModel = new ConnectionModel() {
                    ProtocolType = new ProtocolType() {
                        Name = "Mock Protocol",
                        Provider = "Myrcon",
                        Type = "MockProtocol"
                    },
                    Hostname = "1.1.1.1",
                    Port = 27516,
                    Arguments = "",
                    Password = "******"
                }
            });

            instance.WriteConfig();

            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);
            
            var configCommand = loadConfig.RootOf<PotatoController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList().Last();

            configCommand.Decrypt("PotatoConfigurationPassword");

            Assert.AreEqual("PotatoAddConnection", configCommand.Command.Name);
            Assert.AreEqual("Myrcon", configCommand.Command.Parameters[0].First<String>());
            Assert.AreEqual("MockProtocol", configCommand.Command.Parameters[1].First<String>());
            Assert.AreEqual("1.1.1.1", configCommand.Command.Parameters[2].First<String>());
            Assert.AreEqual("27516", configCommand.Command.Parameters[3].First<String>());
            Assert.AreEqual("password", configCommand.Command.Parameters[4].First<String>());
            Assert.AreEqual("", configCommand.Command.Parameters[5].First<String>());

            instance.Dispose();
        }
Ejemplo n.º 6
0
        public void TestEnabledPluginSavedToConfig() {
            Guid connectionGuid = Guid.NewGuid();
            Guid onePluginGuid = Guid.NewGuid();
            Guid twoPluginGuid = Guid.NewGuid();

            ICorePluginController plugins = new CorePluginController() {
                Connection = new ConnectionController() {
                    ConnectionModel = new ConnectionModel() {
                        ConnectionGuid = connectionGuid
                    }
                },
                LoadedPlugins = new List<PluginModel>() {
                    new PluginModel() {
                        Name = "One",
                        IsEnabled = false,
                        PluginGuid = onePluginGuid
                    },
                    new PluginModel() {
                        Name = "Two",
                        IsEnabled = true,
                        PluginGuid = twoPluginGuid
                    }
                }
            };

            IConfig config = new Config().Create<CorePluginController>();

            plugins.WriteConfig(config);

            config.Save(this.ConfigFile);

            // Now load up the config and ensure it saved what we wanted it too.

            var loadConfig = new Config();
            loadConfig.Load(this.ConfigFile);

            var commands = loadConfig.RootOf<CorePluginController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();

            Assert.AreEqual("PluginsEnable", commands[0].Command.Name);
            Assert.AreEqual(connectionGuid, commands[0].Command.Scope.ConnectionGuid);
            Assert.AreEqual(twoPluginGuid, commands[0].Command.Scope.PluginGuid);
        }
Ejemplo n.º 7
0
        public void TestSecurityWriteConfig() {
            var security = new SecurityController();
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAddGroup,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName"
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    "CustomPermission",
                    22
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    CommandType.VariablesSet,
                    77
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    CommandType.VariablesSetA,
                    88
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupAddAccount,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    "Phogue"
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountSetPassword,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    "password"
                })
            });

            security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.Parse("f380eb1e-1438-48c0-8c3d-ad55f2d40538"), "Token Hash", DateTime.Parse("2024-04-14 20:51:00 PM")).SetOrigin(CommandOrigin.Local));

            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountSetPreferredLanguageCode,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    "de-DE"
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountAddPlayer,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    CommonProtocolType.DiceBattlefield3,
                    "ABCDEF"
                })
            });

            // Save a config of the language controller
            var saveConfig = new Config();
            saveConfig.Create(typeof(SecurityController));
            security.WriteConfig(saveConfig);
            saveConfig.Save(ConfigFileInfo);

            // Load the config in a new config.
            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);

            var commands = loadConfig.RootOf<SecurityController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();

            Assert.AreEqual("SecurityAddGroup", commands[0].Command.Name);
            Assert.AreEqual("Guest", commands[0].Command.Parameters[0].First<String>());

            Assert.AreEqual("SecurityAddGroup", commands[1].Command.Name);
            Assert.AreEqual("GroupName", commands[1].Command.Parameters[0].First<String>());

            Assert.AreEqual("SecurityGroupSetPermission", commands[2].Command.Name);
            Assert.AreEqual("GroupName", commands[2].Command.Parameters[0].First<String>());
            Assert.AreEqual(CommandType.VariablesSet.ToString(), commands[2].Command.Parameters[1].First<String>());
            Assert.AreEqual("77", commands[2].Command.Parameters[2].First<String>());

            Assert.AreEqual("SecurityGroupSetPermission", commands[3].Command.Name);
            Assert.AreEqual("GroupName", commands[3].Command.Parameters[0].First<String>());
            Assert.AreEqual(CommandType.VariablesSetA.ToString(), commands[3].Command.Parameters[1].First<String>());
            Assert.AreEqual("88", commands[3].Command.Parameters[2].First<String>());

            Assert.AreEqual("SecurityGroupSetPermission", commands[4].Command.Name);
            Assert.AreEqual("GroupName", commands[4].Command.Parameters[0].First<String>());
            Assert.AreEqual("CustomPermission", commands[4].Command.Parameters[1].First<String>());
            Assert.AreEqual("22", commands[4].Command.Parameters[2].First<String>());

            Assert.AreEqual("SecurityGroupAddAccount", commands[5].Command.Name);
            Assert.AreEqual("GroupName", commands[5].Command.Parameters[0].First<String>());
            Assert.AreEqual("Phogue", commands[5].Command.Parameters[1].First<String>());

            Assert.AreEqual("SecurityAccountSetPasswordHash", commands[6].Command.Name);
            Assert.AreEqual("Phogue", commands[6].Command.Parameters[0].First<String>());
            // We can only test if this isn't null as it contains a random salt and resulting hash.
            Assert.IsNotNull(commands[6].Command.Parameters[1].First<String>());

            Assert.AreEqual("SecurityAccountSetPreferredLanguageCode", commands[7].Command.Name);
            Assert.AreEqual("Phogue", commands[7].Command.Parameters[0].First<String>());
            Assert.AreEqual("de-DE", commands[7].Command.Parameters[1].First<String>());

            Assert.AreEqual("SecurityAccountAddPlayer", commands[8].Command.Name);
            Assert.AreEqual("Phogue", commands[8].Command.Parameters[0].First<String>());
            Assert.AreEqual(CommonProtocolType.DiceBattlefield3, commands[8].Command.Parameters[1].First<String>());
            Assert.AreEqual("ABCDEF", commands[8].Command.Parameters[2].First<String>());

            Assert.AreEqual("SecurityAccountAppendAccessToken", commands[9].Command.Name);
            Assert.AreEqual("Phogue", commands[9].Command.Parameters[0].First<String>());
            Assert.AreEqual(Guid.Parse("f380eb1e-1438-48c0-8c3d-ad55f2d40538"), commands[9].Command.Parameters[1].First<Guid>());
            Assert.AreEqual("Token Hash", commands[9].Command.Parameters[2].First<String>());
            Assert.AreEqual(DateTime.Parse("2024-04-14 20:51:00 PM"), commands[9].Command.Parameters[3].First<DateTime>());
        }
Ejemplo n.º 8
0
        public void TestWriteConfig() {
            var variables = (VariableController)new VariableController().Execute();
            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToWriteString",
                    "this is a string"
                })
            });

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToWriteInteger",
                    1
                })
            });

            // Empty strings should not be written. No point saving nothing.
            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToignore",
                    ""
                })
            });

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToNotWrite",
                    "This shouldn't appear in the saved file."
                })
            });

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    CommonVariableNames.MaximumProtocolConnections,
                    10
                })
            });

            // Save a config of the variables controller
            var saveConfig = new Config();
            saveConfig.Create(typeof (VariableController));
            variables.WriteConfig(saveConfig);
            saveConfig.Save(ConfigFileInfo);

            // Load the config in a new config.
            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);

            var commands = loadConfig.RootOf<VariableController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();

            // Order is not maintained so we can only check that the values in some disorder are output.
            // Nope, not perfect.
            foreach (var command in commands) {
                Assert.AreEqual("VariablesSetA", command.Command.Name);
                Assert.IsTrue(new List<String>() { "NameToWriteString", "NameToWriteInteger", "MaximumProtocolConnections" }.Contains(command.Command.Parameters[0].First<String>()));
                Assert.IsTrue(new List<String>() { "this is a string", "1", "10" }.Contains(command.Command.Parameters[1].First<String>()));
            }
        }