-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5865 from bdukes/bad-permission-cast
- Loading branch information
Showing
3 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
DNN Platform/Tests/DotNetNuke.Tests.Core/Security/Permissions/PermissionProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |