* Move AuditService to core project * Move two factor login service to core * Move ServerRegistrationService to core * Move BasicAuthService to Core project * Move IdKeyMap to core project * Added CacheInstructionService to the infrastructure namespace * Move DataTypeService to core namespace * Update CacheInstructionService.cs to use CoreScopeProvider * Move core editors to core * Move more Property editors and configuration * Remove obsoleted constructors in internal classes * Update PropertyEditors to use new ctors * Fix propertyEditors to use new ctors * Use the right property editor constructors * add DI in the property method * Update grid to use new ctor * Fix non-assignment of variable * Apply suggestions from code review Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix suggestions from code review Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Kevin Jump <kevin@thejumps.co.uk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
41 lines
1.7 KiB
C#
41 lines
1.7 KiB
C#
using System.Linq;
|
|
using System.Net;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Configuration;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Services.Implement;
|
|
using Umbraco.Cms.Web.Common.Mvc;
|
|
using IpAddressUtilities = Umbraco.Cms.Web.Common.Mvc.IpAddressUtilities;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Services
|
|
{
|
|
[TestFixture]
|
|
public class BasicAuthServiceTests
|
|
{
|
|
[TestCase(true, ExpectedResult = true)]
|
|
[TestCase(false, ExpectedResult = false)]
|
|
public bool IsBasicAuthEnabled(bool enabled)
|
|
{
|
|
var sut = new BasicAuthService(Mock.Of<IOptionsMonitor<BasicAuthSettings>>(_ => _.CurrentValue == new BasicAuthSettings() {Enabled = enabled}), new IpAddressUtilities());
|
|
|
|
return sut.IsBasicAuthEnabled();
|
|
}
|
|
|
|
[TestCase("::1", "1.1.1.1", ExpectedResult = false)]
|
|
[TestCase("::1", "1.1.1.1, ::1", ExpectedResult = true)]
|
|
[TestCase("127.0.0.1", "127.0.0.1, ::1", ExpectedResult = true)]
|
|
[TestCase("127.0.0.1", "", ExpectedResult = false)]
|
|
[TestCase("125.125.125.1", "125.125.125.0/24", ExpectedResult = true)]
|
|
[TestCase("125.125.124.1", "125.125.125.0/24", ExpectedResult = false)]
|
|
public bool IsIpAllowListed(string clientIpAddress, string commaSeperatedAllowlist)
|
|
{
|
|
var allowedIPs = commaSeperatedAllowlist.Split(",").Select(x=>x.Trim()).ToArray();
|
|
var sut = new BasicAuthService(Mock.Of<IOptionsMonitor<BasicAuthSettings>>(_ => _.CurrentValue == new BasicAuthSettings() {AllowedIPs = allowedIPs}), new IpAddressUtilities());
|
|
|
|
return sut.IsIpAllowListed(IPAddress.Parse(clientIpAddress));
|
|
}
|
|
}
|
|
}
|