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

Fix AssemblyInstaller failing to UnRegister dll if missing from disk. #4359

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ private void RemoveBindingRedirect(InstallFile file)
/// <returns><c>true</c> if the XML Merge was applied successfully, <c>false</c> if the file was not a strong-named assembly or could not be read.</returns>
private bool ApplyXmlMerge(InstallFile file, string xmlMergeFile)
{
var assemblyName = ReadAssemblyName(Path.Combine(this.PhysicalBasePath, file.FullName));
var assemblyFileFullPath = Path.Combine(this.PhysicalBasePath, file.FullName);
if (!File.Exists(assemblyFileFullPath))
{
return false;
}

var assemblyName = ReadAssemblyName(assemblyFileFullPath);
var publicKeyToken = ReadPublicKey(assemblyName);
if (string.IsNullOrEmpty(publicKeyToken))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<Compile Include="Services\ClientCapability\TestClientCapability.cs" />
<Compile Include="Services\CryptographyProviders\FipsCompilanceCryptographyProviderTests.cs" />
<Compile Include="Services\CryptographyProviders\CoreCryptographyProviderTests.cs" />
<Compile Include="Services\Installer\AssemblyInstallerTests.cs" />
<Compile Include="Services\Localization\LocalizationTests.cs" />
<Compile Include="Services\Mobile\PreviewProfileControllerTests.cs" />
<Compile Include="Services\Mobile\RedirectionControllerTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Tests.Core.Services.Installer
{
using System;
using System.IO;
using System.Linq;
using System.Xml.XPath;

using DotNetNuke.Abstractions;
using DotNetNuke.Abstractions.Application;
using DotNetNuke.Common;
using DotNetNuke.Services.Installer;
using DotNetNuke.Services.Installer.Installers;
using DotNetNuke.Services.Installer.Packages;
using DotNetNuke.Services.Localization;
using DotNetNuke.Tests.Utilities;
using DotNetNuke.Tests.Utilities.Mocks;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using NUnit.Framework;

public class AssemblyInstallerTests : DnnUnitTest
{
[SetUp]
public void SetUp()
{
var serviceCollection = new ServiceCollection();
var appInfo = new Mock<IApplicationStatusInfo>();
appInfo.SetupGet(app => app.Status).Returns(UpgradeStatus.None);
serviceCollection.AddTransient<IApplicationStatusInfo>(container => appInfo.Object);
serviceCollection.AddTransient<INavigationManager>(container => Mock.Of<INavigationManager>());
Globals.DependencyProvider = serviceCollection.BuildServiceProvider();

var dataProvider = MockComponentProvider.CreateDataProvider();
dataProvider.Setup(p => p.UnRegisterAssembly(It.IsAny<int>(), It.IsAny<string>())).Returns(true);

LocalizationProvider.SetTestableInstance(new Mock<ILocalizationProvider>().Object);
}

[Test]
public void Install_UnRegisterAssembly_ShouldSucceed_WhenFileIsMissing()
{
var installer = new AssemblyInstaller
{
DeleteFiles = true,
Package = new PackageInfo(new InstallerInfo(Directory.GetCurrentDirectory(), InstallMode.Install)),
};
var manifestNav = GetUnRegisterAssemblyManifest();
installer.ReadManifest(manifestNav);

installer.Install();

Assert.IsTrue(installer.Log.Valid);
}

private static XPathNavigator GetUnRegisterAssemblyManifest()
{
var doc = new XPathDocument(new StringReader(@"
<assemblies>
<assembly action=""UnRegister"">
<path>bin\Providers</path>
<name>FakeAssembly.dll</name>
<sourceFileName>FakeAssembly.dll</sourceFileName>
<version>01.02.03</version>
</assembly>
</assemblies>
"));
return doc.CreateNavigator();
}
}
}