feat: acquire legacy settings from approved network source
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Launcher.Next.Application;
|
||||
using Xunit;
|
||||
|
||||
namespace Launcher.Next.Tests;
|
||||
|
||||
public sealed class LegacyNetworkConfigurationTests
|
||||
{
|
||||
[Fact]
|
||||
public void ApprovedSettingsEndpoint_IsExactUncFile()
|
||||
{
|
||||
Assert.Equal(@"\\phimproject.com\common\BIM\save\All_Serv_Install\Settings.xml", LegacyNetworkConfiguration.ApprovedSettingsEndpoint);
|
||||
Assert.StartsWith(@"\\", LegacyNetworkConfiguration.ApprovedSettingsEndpoint, StringComparison.Ordinal);
|
||||
Assert.EndsWith("Settings.xml", LegacyNetworkConfiguration.ApprovedSettingsEndpoint, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"N:\BIM", @"\\phimproject.com\common\BIM")]
|
||||
[InlineData(@"N:\BIM\save\Apps\Plant3D\DriveA", @"\\phimproject.com\common\BIM\save\Apps\Plant3D\DriveA")]
|
||||
public void ApprovedNDriveAlias_ResolvesOnlyBimNamespace(string original, string expected)
|
||||
=> Assert.Equal(expected, LegacyNetworkConfiguration.ResolveApprovedAlias(original));
|
||||
|
||||
[Theory]
|
||||
[InlineData(@"N:\Other\payload.dll")]
|
||||
[InlineData(@"Q:\BIM\save\Apps")]
|
||||
[InlineData("relative\\Settings.xml")]
|
||||
public void UnknownLegacyAliases_AreRejected(string path)
|
||||
=> Assert.Equal("LEGACY_NETWORK_ALIAS_NOT_APPROVED", Assert.Throws<InvalidOperationException>(() => LegacyNetworkConfiguration.ResolveApprovedAlias(path)).Message);
|
||||
|
||||
[Fact]
|
||||
public void UnapprovedEndpoint_IsRejectedBeforeAnyNetworkAccess()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "launcher-network-" + Guid.NewGuid().ToString("N"));
|
||||
try
|
||||
{
|
||||
Assert.Equal("LEGACY_SETTINGS_ENDPOINT_NOT_APPROVED", Assert.Throws<InvalidOperationException>(() => LegacyNetworkConfiguration.AcquireApprovedSnapshot(@"\\example.invalid\Settings.xml", root)).Message);
|
||||
}
|
||||
finally { if (Directory.Exists(root)) Directory.Delete(root, true); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Launcher.Next.Application;
|
||||
using Xunit;
|
||||
|
||||
namespace Launcher.Next.Tests;
|
||||
|
||||
public sealed class LegacyNetworkSettingsParserTests
|
||||
{
|
||||
[Fact]
|
||||
public void FullLegacyPattern_PreservesSourcesAttributesAndMachineRestriction()
|
||||
{
|
||||
const string xml = "<root><path><help>h</help><care>c</care></path><data><pattern><name>Plant 3D_2019</name><filter>Project files |Project.xml|All files (*.*)|*.*</filter><roster>%PROJECTDIRECTORY%\\..\\_System\\Plant 3D_2019\\Applications\\download_list.xml</roster><source><course>N:\\BIM\\save\\Apps\\Plant3D\\DriveA</course></source><source><course>N:\\BIM\\save\\Apps\\Plant3D\\DriveQ</course></source><target>target</target><loader>loader</loader><object>object</object><attrib>first</attrib><attrib>second</attrib></pattern><plugin><id>b455ee6eaed79d76f084846a60ce3284</id><renewal></renewal><catalog>P_Rec_Annot</catalog><install>OrthoLoader.dll</install><machine>BUILD-01</machine></plugin></data></root>";
|
||||
var settings = new LegacyConfigurationAdapter().ParseSettings(xml);
|
||||
var pattern = Assert.Single(settings.Patterns);
|
||||
Assert.Equal(["N:\\BIM\\save\\Apps\\Plant3D\\DriveA", "N:\\BIM\\save\\Apps\\Plant3D\\DriveQ"], pattern.Sources);
|
||||
Assert.Equal(["first", "second"], pattern.Attributes);
|
||||
Assert.Equal("target", pattern.Target);
|
||||
var plugin = Assert.Single(pattern.Plugins);
|
||||
Assert.Equal("P_Rec_Annot", plugin.Catalog);
|
||||
Assert.True(plugin.IsAllowedOn("build-01"));
|
||||
Assert.False(plugin.IsAllowedOn("OTHER"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PluginWithoutMachineRestriction_IsAllowedEverywhere()
|
||||
{
|
||||
var plugin = new LegacyPluginDefinition("id", "", "catalog", "install", 0);
|
||||
Assert.True(plugin.IsAllowedOn(Environment.MachineName));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user