Skip to content

Commit

Permalink
Merge pull request #5865 from bdukes/bad-permission-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
david-poindexter authored Nov 8, 2023
2 parents a94acf8 + 234eb74 commit bc86e16
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
30 changes: 15 additions & 15 deletions DNN Platform/Library/Security/Permissions/FolderPermissionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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
// 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.Security.Permissions
{
using System;
using System.Data;
using System.Xml.Serialization;
using System.Xml.Serialization;

using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules;
using Newtonsoft.Json;

[Serializable]
Expand Down Expand Up @@ -39,7 +39,7 @@ public FolderPermissionInfo()
/// </summary>
/// <param name="permission">A PermissionInfo object.</param>
public FolderPermissionInfo(PermissionInfo permission)
: this((IPermissionInfo)permission)
: this((IPermissionDefinitionInfo)permission)
{
}

Expand All @@ -48,7 +48,7 @@ public FolderPermissionInfo(PermissionInfo permission)
/// Constructs a new FolderPermissionInfo.
/// </summary>
/// <param name="permission">A PermissionInfo object.</param>
public FolderPermissionInfo(IPermissionInfo permission)
public FolderPermissionInfo(IPermissionDefinitionInfo permission)
: this()
{
var @this = (IPermissionDefinitionInfo)this;
Expand All @@ -59,7 +59,7 @@ public FolderPermissionInfo(IPermissionInfo permission)
@this.PermissionName = permission.PermissionName;
}

[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.FolderPermissionId)} instead. Scheduled for removal in v11.0.0.")]
public int FolderPermissionID
Expand All @@ -75,7 +75,7 @@ public int FolderPermissionID
}
}

[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
int IFolderPermissionInfo.FolderPermissionId
{
Expand All @@ -90,7 +90,7 @@ int IFolderPermissionInfo.FolderPermissionId
}
}

[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.FolderId)} instead. Scheduled for removal in v11.0.0.")]
public int FolderID
Expand All @@ -106,7 +106,7 @@ public int FolderID
}
}

[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.FolderId)} instead. Scheduled for removal in v11.0.0.")]
int IFolderPermissionInfo.FolderId
Expand All @@ -122,7 +122,7 @@ int IFolderPermissionInfo.FolderId
}
}

[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.PortalId)} instead. Scheduled for removal in v11.0.0.")]
public int PortalID
Expand All @@ -138,7 +138,7 @@ public int PortalID
}
}

[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.PortalId)} instead. Scheduled for removal in v11.0.0.")]
int IFolderPermissionInfo.PortalId
Expand Down Expand Up @@ -170,7 +170,7 @@ public string FolderPath

/// <summary>Gets or sets the Key ID.</summary>
/// <returns>An Integer.</returns>
[XmlIgnore]
[XmlIgnore]
[JsonIgnore]
public int KeyID
{
Expand All @@ -190,7 +190,7 @@ public int KeyID
public void Fill(IDataReader dr)
{
this.FillInternal(dr);


var @this = (IFolderPermissionInfo)this;
@this.FolderPermissionId = Null.SetNullInteger(dr["FolderPermissionID"]);
@this.FolderId = Null.SetNullInteger(dr["FolderID"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<Compile Include="Providers\Membership\MembershipProviderTests.cs" />
<Compile Include="Providers\Permissions\PermissionTests.cs" />
<Compile Include="RetryableActionTests.cs" />
<Compile Include="Security\Permissions\PermissionProviderTests.cs" />
<Compile Include="Security\PortalSecurity\PortalSecurityTest.cs" />
<Compile Include="Services\ClientCapability\FacebookRequestControllerTests.cs" />
<Compile Include="Services\ClientCapability\TestClientCapability.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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.Security.Permissions;

using System.Collections.Generic;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel;
using DotNetNuke.Data;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Tests.Utilities.Fakes;
using Moq;
using NUnit.Framework;

[TestFixture]
public class PermissionProviderTests
{
[Test]
public void SaveFolderPermissions_DoesNotThrow()
{
var permissions = new List<PermissionInfo>();
var cache = new Dictionary<string, object> { { CachingProvider.GetCacheKey(DataCache.PermissionsCacheKey), permissions }, };
var fakeCachingProvider = new FakeCachingProvider(cache);
ComponentFactory.RegisterComponentInstance<CachingProvider>(fakeCachingProvider);

ComponentFactory.RegisterComponentInstance<DataProvider>(Mock.Of<DataProvider>());

var permissionProvider = new PermissionProvider();

IFolderInfo folder = new FolderInfo(initialiseEmptyPermissions: true);
Assert.DoesNotThrow(() => permissionProvider.SaveFolderPermissions(folder));
}

[Test]
public void SaveFolderPermissions_WithPermissions_DoesNotThrow()
{
var readPermission = new PermissionInfo { PermissionCode = "SYSTEM_FOLDER", PermissionKey = "READ", PermissionID = 1, };
var permissions = new List<PermissionInfo> { readPermission, };
var cache = new Dictionary<string, object> { { CachingProvider.GetCacheKey(DataCache.PermissionsCacheKey), permissions }, };
var fakeCachingProvider = new FakeCachingProvider(cache);
ComponentFactory.RegisterComponentInstance<CachingProvider>(fakeCachingProvider);

ComponentFactory.RegisterComponentInstance<DataProvider>(Mock.Of<DataProvider>());

var permissionProvider = new PermissionProvider();

IFolderInfo folder = new FolderInfo(initialiseEmptyPermissions: true);
folder.FolderPermissions.Add(new FolderPermissionInfo(readPermission) { AllowAccess = true, RoleID = -2, UserID = -1, FolderID = 2, });
Assert.DoesNotThrow(() => permissionProvider.SaveFolderPermissions(folder));
}
}

0 comments on commit bc86e16

Please sign in to comment.