Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Game Command validation #64

Merged
merged 6 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions LocalMultiplayerAgent.UnitTest/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,43 @@ public void EmptyNodePortInContainerModeShouldFail()
new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();

}

[TestMethod]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a couple more test cases? e.g. a test that succeeds and multiple variations of startgamecommand. #Resolved

[TestCategory("BVT")]
[DataRow("powershell.exe D:\\Assets\\GameServer.ps1")]
[DataRow("powershell.exe E:\\Assets\\GameServer.exe")]
[DataRow("E:\\MyGameRocks\\GameServer.exe")]
[DataRow("C:\\Asset\\GameServer.bat")]
public void StartGameCommandThatDoesNotContainMountPathShouldFail(string startGameCommand)
{
dynamic config = GetValidConfig();
config.RunContainer = true;
config.AssetDetails[0].MountPath = "C:\\Assets";
config.ContainerStartParameters.StartGameCommand = startGameCommand;
MultiplayerSettings settings = JsonConvert.DeserializeObject<MultiplayerSettings>(config.ToString());

settings.SetDefaultsIfNotSpecified();
new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeFalse();

}

[TestMethod]
[TestCategory("BVT")]
[DataRow("powershell.exe C:\\Assets\\GameServer.ps1")]
[DataRow("powershell.exe C:\\Assets\\GameServer.exe")]
[DataRow("C:\\Assets\\MyGameRocks\\GameServer.exe")]
[DataRow("C:\\Assets\\GameServer.bat")]
public void StartGameCommandThatContainsMountPathShouldSucceed(string startGameCommand)
{
dynamic config = GetValidConfig();
config.RunContainer = true;
config.AssetDetails[0].MountPath = "C:\\Assets";
config.ContainerStartParameters.StartGameCommand = startGameCommand;
MultiplayerSettings settings = JsonConvert.DeserializeObject<MultiplayerSettings>(config.ToString());

settings.SetDefaultsIfNotSpecified();
new MultiplayerSettingsValidator(settings, _mockSystemOperations.Object).IsValid().Should().BeTrue();

}
}
}
18 changes: 13 additions & 5 deletions LocalMultiplayerAgent/Config/MultiplayerSettingsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Microsoft.Azure.Gaming.LocalMultiplayerAgent.Config
using System.Runtime.InteropServices;
using AgentInterfaces;
using VmAgent.Core.Interfaces;
using System.Linq;
using System.IO;

public class MultiplayerSettingsValidator
{
Expand Down Expand Up @@ -77,13 +79,18 @@ public bool IsValid()
isSuccess = false;
}
}
else
else if (startGameCommand.Contains("<your_game_server_exe>"))
{
Console.WriteLine($"StartGameCommand '{startGameCommand}' is invalid");
isSuccess = false;
}
else if (_settings.AssetDetails != null && _settings.RunContainer && (Globals.GameServerEnvironment == GameServerEnvironment.Windows))
{
if (startGameCommand.Contains("<your_game_server_exe>"))
if ((!_settings.AssetDetails.Any(x => startGameCommand.Contains(x.MountPath, StringComparison.InvariantCultureIgnoreCase))))
{
Console.WriteLine($"StartGameCommand '{startGameCommand}' is invalid");
Console.WriteLine($"StartGameCommand '{startGameCommand}' is invalid and does not contain the mount path. This should look like: C:\\Assets\\GameServer.exe for example.");
isSuccess = false;
}
}
}

if (_settings.GameCertificateDetails?.Length > 0)
Expand Down Expand Up @@ -158,7 +165,8 @@ public bool IsValid()
Console.WriteLine($"Warning: You have specified an AgentListeningPort ({_settings.AgentListeningPort}) that is not the default. Please make sure that port is open on your firewall by running setup.ps1 with the agent port specified.");
}

if (_settings.RunContainer) {
if (_settings.RunContainer)
{
foreach (var portList in _settings.PortMappingsList)
{
foreach (var portInfo in portList)
Expand Down