More DI-ify identity
Follow K patterns for DI - IdentityBuilder - IServiceProvider constructor - Unit tests for Startup usage/new DI builder - Move template default configuration into DefaultServices
This commit is contained in:
parent
389678042f
commit
d827b9fff2
|
|
@ -2,6 +2,10 @@
|
||||||
"version": "0.1-alpha-*",
|
"version": "0.1-alpha-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Identity": "0.1-alpha-*",
|
"Microsoft.AspNet.Identity": "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.Abstractions" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.ConfigurationModel" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.RequestContainer" : "0.1-alpha-*",
|
||||||
"System.Security.Claims": "0.1-alpha-*"
|
"System.Security.Claims": "0.1-alpha-*"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ namespace Microsoft.AspNet.Identity.Security
|
||||||
public UserManager<TUser> UserManager { get; set; }
|
public UserManager<TUser> UserManager { get; set; }
|
||||||
public HttpContext Context { get; set; }
|
public HttpContext Context { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public virtual async Task<ClaimsIdentity> CreateUserIdentityAsync(TUser user)
|
public virtual async Task<ClaimsIdentity> CreateUserIdentityAsync(TUser user)
|
||||||
{
|
{
|
||||||
if (UserManager == null)
|
if (UserManager == null)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Identity
|
||||||
|
{
|
||||||
|
public class IdentityBuilder<TUser, TRole> where TUser : class where TRole : class
|
||||||
|
{
|
||||||
|
private ServiceCollection Services { get; set; }
|
||||||
|
|
||||||
|
public IdentityBuilder(ServiceCollection services)
|
||||||
|
{
|
||||||
|
Services = services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> Use<T>(Func<T> func)
|
||||||
|
{
|
||||||
|
Services.AddInstance<T>(func());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseIdentity()
|
||||||
|
{
|
||||||
|
Services.Add(IdentityServices.GetDefaultUserServices<TUser>());
|
||||||
|
Services.Add(IdentityServices.GetDefaultRoleServices<TRole>());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseUserStore(Func<IUserStore<TUser>> func)
|
||||||
|
{
|
||||||
|
return Use(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseRoleStore(Func<IRoleStore<TRole>> func)
|
||||||
|
{
|
||||||
|
return Use(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UsePasswordValidator(Func<IPasswordValidator> func)
|
||||||
|
{
|
||||||
|
return Use(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseUserValidator(Func<IUserValidator<TUser>> func)
|
||||||
|
{
|
||||||
|
return Use(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseUserManager<TManager>() where TManager : UserManager<TUser>
|
||||||
|
{
|
||||||
|
Services.AddScoped<TManager, TManager>();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseRoleManager<TManager>() where TManager : RoleManager<TRole>
|
||||||
|
{
|
||||||
|
Services.AddScoped<TManager, TManager>();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public IdentityBuilder<TUser, TRole> UseTwoFactorProviders(Func<IDictionary<string, IUserTokenProvider<TUser>>> func)
|
||||||
|
//{
|
||||||
|
// return Use(func);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public IdentityBuilder<TUser, TRole> UseLockoutPolicy(Func<LockoutPolicy> func)
|
||||||
|
{
|
||||||
|
return Use(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
using Microsoft.AspNet.Identity;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.DependencyInjection
|
||||||
|
{
|
||||||
|
public static class IdentityServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
public static ServiceCollection AddIdentity<TUser, TRole>(this ServiceCollection services, Action<IdentityBuilder<TUser, TRole>> actionBuilder)
|
||||||
|
where TUser : class
|
||||||
|
where TRole : class
|
||||||
|
{
|
||||||
|
services.Add(IdentityServices.GetDefaultUserServices<TUser>());
|
||||||
|
services.Add(IdentityServices.GetDefaultRoleServices<TRole>());
|
||||||
|
actionBuilder(new IdentityBuilder<TUser, TRole>(services));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServiceCollection AddIdentity<TUser>(this ServiceCollection services, Action<IdentityBuilder<TUser, IdentityRole>> actionBuilder)
|
||||||
|
where TUser : class
|
||||||
|
{
|
||||||
|
services.Add(IdentityServices.GetDefaultUserServices<TUser>());
|
||||||
|
services.Add(IdentityServices.GetDefaultRoleServices<IdentityRole>());
|
||||||
|
actionBuilder(new IdentityBuilder<TUser, IdentityRole>(services));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
using Microsoft.AspNet.ConfigurationModel;
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Identity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Default services used by UserManager and RoleManager
|
||||||
|
/// </summary>
|
||||||
|
public class IdentityServices
|
||||||
|
{
|
||||||
|
|
||||||
|
public static IEnumerable<IServiceDescriptor> GetDefaultUserServices<TUser>() where TUser : class
|
||||||
|
{
|
||||||
|
return GetDefaultUserServices<TUser>(new Configuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<IServiceDescriptor> GetDefaultUserServices<TUser>(IConfiguration configuration) where TUser : class
|
||||||
|
{
|
||||||
|
var describe = new ServiceDescriber(configuration);
|
||||||
|
|
||||||
|
// TODO: review defaults for validators should get picked up from config?
|
||||||
|
yield return describe.Instance<IUserValidator<TUser>>(new UserValidator<TUser>());
|
||||||
|
yield return describe.Instance<IPasswordValidator>(new PasswordValidator()
|
||||||
|
{
|
||||||
|
RequiredLength = 6,
|
||||||
|
RequireDigit = true,
|
||||||
|
RequireLowercase = true,
|
||||||
|
RequireNonLetterOrDigit = true,
|
||||||
|
RequireUppercase = true
|
||||||
|
});
|
||||||
|
yield return describe.Instance<IPasswordHasher>(new PasswordHasher());
|
||||||
|
yield return describe.Instance<IClaimsIdentityFactory<TUser>>(new ClaimsIdentityFactory<TUser>());
|
||||||
|
yield return describe.Instance<LockoutPolicy>(new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = false,
|
||||||
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5),
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 5
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: rationalize email/sms/usertoken services
|
||||||
|
// TODO: configure lockout from config?
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<IServiceDescriptor> GetDefaultRoleServices<TRole>() where TRole : class
|
||||||
|
{
|
||||||
|
return GetDefaultRoleServices<TRole>(new Configuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<IServiceDescriptor> GetDefaultRoleServices<TRole>(IConfiguration configuration) where TRole : class
|
||||||
|
{
|
||||||
|
var describe = new ServiceDescriber(configuration);
|
||||||
|
|
||||||
|
// TODO: review defaults for validators should get picked up from config?
|
||||||
|
yield return describe.Instance<IRoleValidator<TRole>>(new RoleValidator<TRole>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Identity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration for lockout
|
||||||
|
/// </summary>
|
||||||
|
public class LockoutPolicy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// If true, will enable user lockout when users are created
|
||||||
|
/// </summary>
|
||||||
|
public bool UserLockoutEnabledByDefault { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Number of access attempts allowed for a user before lockout (if enabled)
|
||||||
|
/// </summary>
|
||||||
|
public int MaxFailedAccessAttemptsBeforeLockout { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default amount of time an user is locked out for after MaxFailedAccessAttempsBeforeLockout is reached
|
||||||
|
/// </summary>
|
||||||
|
public TimeSpan DefaultAccountLockoutTimeSpan { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
using Microsoft.AspNet.DependencyInjection.Fallback;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity
|
namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
|
|
@ -13,6 +15,11 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
|
||||||
|
public RoleManager(IServiceProvider services)
|
||||||
|
{
|
||||||
|
Initialize(services);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -23,8 +30,9 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("store");
|
throw new ArgumentNullException("store");
|
||||||
}
|
}
|
||||||
Store = store;
|
var services = new ServiceCollection { IdentityServices.GetDefaultRoleServices<TRole>() };
|
||||||
RoleValidator = new RoleValidator<TRole>();
|
services.AddInstance<IRoleStore<TRole>>(store);
|
||||||
|
Initialize(services.BuildServiceProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -65,6 +73,21 @@ namespace Microsoft.AspNet.Identity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize(IServiceProvider services)
|
||||||
|
{
|
||||||
|
if (services == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("services");
|
||||||
|
}
|
||||||
|
Store = services.GetService<IRoleStore<TRole>>();
|
||||||
|
if (Store == null)
|
||||||
|
{
|
||||||
|
// TODO: what is the right way to enforce required services
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
RoleValidator = services.GetService<IRoleValidator<TRole>>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose this object
|
/// Dispose this object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
using Microsoft.AspNet.DependencyInjection.Fallback;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity
|
namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
|
|
@ -23,25 +24,18 @@ namespace Microsoft.AspNet.Identity
|
||||||
private TimeSpan _defaultLockout = TimeSpan.Zero;
|
private TimeSpan _defaultLockout = TimeSpan.Zero;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
private IPasswordHasher _passwordHasher;
|
private IPasswordHasher _passwordHasher;
|
||||||
|
private LockoutPolicy _lockoutPolicy;
|
||||||
|
|
||||||
|
// Needed for mock unit tests
|
||||||
public UserManager() { }
|
public UserManager() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor which takes a service provider to find the default interfaces to hook up
|
/// Constructor which takes a service provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serviceProvider"></param>
|
/// <param name="serviceProvider"></param>
|
||||||
public UserManager(IServiceProvider serviceProvider)
|
public UserManager(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
if (serviceProvider == null)
|
Initialize(serviceProvider);
|
||||||
{
|
|
||||||
throw new ArgumentNullException("serviceProvider");
|
|
||||||
}
|
|
||||||
PasswordHasher = serviceProvider.GetService<IPasswordHasher>();
|
|
||||||
UserValidator = serviceProvider.GetService<IUserValidator<TUser>>();
|
|
||||||
PasswordValidator = serviceProvider.GetService<IPasswordValidator>();
|
|
||||||
ClaimsIdentityFactory = serviceProvider.GetService<IClaimsIdentityFactory<TUser>>();
|
|
||||||
Store = serviceProvider.GetService<IUserStore<TUser>>();
|
|
||||||
// TODO: maybe each optional store as well? Email and SMS services?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -54,10 +48,29 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("store");
|
throw new ArgumentNullException("store");
|
||||||
}
|
}
|
||||||
Store = store;
|
var services = new ServiceCollection { IdentityServices.GetDefaultUserServices<TUser>() };
|
||||||
UserValidator = new UserValidator<TUser>();
|
services.AddInstance<IUserStore<TUser>>(store);
|
||||||
PasswordHasher = new PasswordHasher();
|
Initialize(services.BuildServiceProvider());
|
||||||
ClaimsIdentityFactory = new ClaimsIdentityFactory<TUser>();
|
}
|
||||||
|
|
||||||
|
public void Initialize(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
if (serviceProvider == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("serviceProvider");
|
||||||
|
}
|
||||||
|
PasswordHasher = serviceProvider.GetService<IPasswordHasher>();
|
||||||
|
UserValidator = serviceProvider.GetService<IUserValidator<TUser>>();
|
||||||
|
PasswordValidator = serviceProvider.GetService<IPasswordValidator>();
|
||||||
|
ClaimsIdentityFactory = serviceProvider.GetService<IClaimsIdentityFactory<TUser>>();
|
||||||
|
LockoutPolicy = serviceProvider.GetService<LockoutPolicy>();
|
||||||
|
Store = serviceProvider.GetService<IUserStore<TUser>>();
|
||||||
|
if (Store == null)
|
||||||
|
{
|
||||||
|
// TODO: what is the right way to enforce required services
|
||||||
|
throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
// TODO: Email/Sms/Token services
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -132,23 +145,30 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IUserTokenProvider<TUser> UserTokenProvider { get; set; }
|
public IUserTokenProvider<TUser> UserTokenProvider { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
public LockoutPolicy LockoutPolicy { get; set; }
|
||||||
/// If true, will enable user lockout when users are created
|
|
||||||
/// </summary>
|
|
||||||
public bool UserLockoutEnabledByDefault { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
private bool UserLockoutEnabledByDefault
|
||||||
/// Number of access attempts allowed for a user before lockout (if enabled)
|
|
||||||
/// </summary>
|
|
||||||
public int MaxFailedAccessAttemptsBeforeLockout { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Default amount of time an user is locked out for after MaxFailedAccessAttempsBeforeLockout is reached
|
|
||||||
/// </summary>
|
|
||||||
public TimeSpan DefaultAccountLockoutTimeSpan
|
|
||||||
{
|
{
|
||||||
get { return _defaultLockout; }
|
get
|
||||||
set { _defaultLockout = value; }
|
{
|
||||||
|
return LockoutPolicy != null && LockoutPolicy.UserLockoutEnabledByDefault;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int MaxFailedAccessAttemptsBeforeLockout
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return LockoutPolicy != null ? LockoutPolicy.MaxFailedAccessAttemptsBeforeLockout : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimeSpan DefaultAccountLockoutTimeSpan
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return LockoutPolicy != null ? LockoutPolicy.DefaultAccountLockoutTimeSpan : TimeSpan.FromMinutes(5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"version": "0.1-alpha-*",
|
"version": "0.1-alpha-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
||||||
"System.Security.Claims" : "0.1-alpha-*",
|
"System.Security.Claims" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.HttpFeature" : "0.1-alpha-*",
|
"Microsoft.AspNet.HttpFeature" : "0.1-alpha-*",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 2013
|
||||||
|
VisualStudioVersion = 12.0.30408.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.net45", "..\src\Microsoft.AspNet.Identity\Microsoft.AspNet.Identity.net45.csproj", "{4D061067-3FE9-442D-81D3-29658DA2FF8F}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{31019886-9CDA-4072-B3D9-E513122CECD0}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.Entity.net45", "..\src\Microsoft.AspNet.Identity.Entity\Microsoft.AspNet.Identity.Entity.net45.csproj", "{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.InMemory.net45", "..\src\Microsoft.AspNet.Identity.InMemory\Microsoft.AspNet.Identity.InMemory.net45.csproj", "{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.Security.net45", "..\src\Microsoft.AspNet.Identity.Security\Microsoft.AspNet.Identity.Security.net45.csproj", "{720B2280-085C-441D-98CD-B241145A1C12}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{394C0E59-7E24-453E-993C-7B914C62110A}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.Test.net45", "..\test\Microsoft.AspNet.Identity.Test\Microsoft.AspNet.Identity.Test.net45.csproj", "{B3A5D740-2C31-4EBC-AADB-356263965C1F}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.Security.Test.net45", "..\test\Microsoft.AspNet.Identity.Security.Test\Microsoft.AspNet.Identity.Security.Test.net45.csproj", "{9F67914A-1F35-4068-A21A-F279C4053ADD}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.InMemory.Test.net45", "..\test\Microsoft.AspNet.Identity.InMemory.Test\Microsoft.AspNet.Identity.InMemory.Test.net45.csproj", "{E2154446-8A68-478B-927F-FD05251C8452}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Identity.Entity.Test.net45", "..\test\Microsoft.AspNet.Identity.Entity.Test\Microsoft.AspNet.Identity.Entity.Test.net45.csproj", "{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|Mixed Platforms = Release|Mixed Platforms
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{4D061067-3FE9-442D-81D3-29658DA2FF8F} = {31019886-9CDA-4072-B3D9-E513122CECD0}
|
||||||
|
{1832A433-ABB4-4D87-B7CE-E80E9A3E8CA7} = {31019886-9CDA-4072-B3D9-E513122CECD0}
|
||||||
|
{173CABE9-9FDF-43A0-AF9B-409F8AA2BE56} = {31019886-9CDA-4072-B3D9-E513122CECD0}
|
||||||
|
{720B2280-085C-441D-98CD-B241145A1C12} = {31019886-9CDA-4072-B3D9-E513122CECD0}
|
||||||
|
{B3A5D740-2C31-4EBC-AADB-356263965C1F} = {394C0E59-7E24-453E-993C-7B914C62110A}
|
||||||
|
{9F67914A-1F35-4068-A21A-F279C4053ADD} = {394C0E59-7E24-453E-993C-7B914C62110A}
|
||||||
|
{E2154446-8A68-478B-927F-FD05251C8452} = {394C0E59-7E24-453E-993C-7B914C62110A}
|
||||||
|
{CFCEFA4C-548D-459A-A051-1DBE3F2FF91F} = {394C0E59-7E24-453E-993C-7B914C62110A}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
|
|
@ -81,7 +81,12 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
|
|
||||||
public static UserManager<EntityUser> CreateManager(EntityContext context)
|
public static UserManager<EntityUser> CreateManager(EntityContext context)
|
||||||
{
|
{
|
||||||
return new UserManager<EntityUser>(new UserStore(context));
|
var manager = new UserManager<EntityUser>(new UserStore(context))
|
||||||
|
{
|
||||||
|
UserValidator = new UserValidator<EntityUser>(),
|
||||||
|
PasswordValidator = new PasswordValidator()
|
||||||
|
};
|
||||||
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserManager<EntityUser> CreateManager()
|
public static UserManager<EntityUser> CreateManager()
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,58 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
{
|
{
|
||||||
public class UserStoreTest
|
public class UserStoreTest
|
||||||
{
|
{
|
||||||
|
class ApplicationUserManager : UserManager<EntityUser>
|
||||||
|
{
|
||||||
|
public ApplicationUserManager(IServiceProvider services) : base(services) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CanUseAddedManagerInstance()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var store = new UserStore(new IdentityContext());
|
||||||
|
services.AddInstance<UserManager<EntityUser>>(new UserManager<EntityUser>(store));
|
||||||
|
var provider = services.BuildServiceProvider();
|
||||||
|
var manager = provider.GetService<UserManager<EntityUser>>();
|
||||||
|
Assert.NotNull(manager);
|
||||||
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(new EntityUser("hello")));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CanUseSingletonManagerInstance()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var store = new UserStore(new IdentityContext());
|
||||||
|
services.AddIdentity<EntityUser, EntityRole>(s =>
|
||||||
|
{
|
||||||
|
s.UseUserStore(() => store);
|
||||||
|
s.UseUserManager<ApplicationUserManager>();
|
||||||
|
});
|
||||||
|
//services.AddSingleton<ApplicationUserManager, ApplicationUserManager>();
|
||||||
|
|
||||||
|
var provider = services.BuildServiceProvider();
|
||||||
|
var manager = provider.GetService<ApplicationUserManager>();
|
||||||
|
Assert.NotNull(manager);
|
||||||
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(new EntityUser("hello")));
|
||||||
|
}
|
||||||
|
|
||||||
|
//[Fact]
|
||||||
|
//public async Task CanUseSingletonGenericManagerInstance()
|
||||||
|
//{
|
||||||
|
// var services = new ServiceCollection();
|
||||||
|
// var store = new UserStore(new IdentityContext());
|
||||||
|
// services.AddIdentity<EntityUser>(s =>
|
||||||
|
// {
|
||||||
|
// s.UseStore(() => store);
|
||||||
|
// s.UseManager<UserManager<EntityUser>>();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// var provider = services.BuildServiceProvider();
|
||||||
|
// var manager = provider.GetService<UserManager<EntityUser>>();
|
||||||
|
// Assert.NotNull(manager);
|
||||||
|
// IdentityResultAssert.IsSuccess(await manager.CreateAsync(new EntityUser("hello")));
|
||||||
|
//}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task UserStoreMethodsThrowWhenDisposedTest()
|
public async Task UserStoreMethodsThrowWhenDisposedTest()
|
||||||
{
|
{
|
||||||
|
|
@ -723,8 +775,11 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task SingleFailureLockout()
|
public async Task SingleFailureLockout()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
{
|
||||||
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new EntityUser("fastLockout");
|
var user = new EntityUser("fastLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -740,9 +795,12 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task TwoFailureLockout()
|
public async Task TwoFailureLockout()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
{
|
||||||
mgr.MaxFailedAccessAttemptsBeforeLockout = 2;
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 2
|
||||||
|
};
|
||||||
var user = new EntityUser("twoFailureLockout");
|
var user = new EntityUser("twoFailureLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -762,9 +820,12 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task ResetAccessCountPreventsLockout()
|
public async Task ResetAccessCountPreventsLockout()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
{
|
||||||
mgr.MaxFailedAccessAttemptsBeforeLockout = 2;
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 2
|
||||||
|
};
|
||||||
var user = new EntityUser("resetLockout");
|
var user = new EntityUser("resetLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -788,8 +849,11 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task CanEnableLockoutManuallyAndLockout()
|
public async Task CanEnableLockoutManuallyAndLockout()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.MaxFailedAccessAttemptsBeforeLockout = 2;
|
{
|
||||||
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 2
|
||||||
|
};
|
||||||
var user = new EntityUser("manualLockout");
|
var user = new EntityUser("manualLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.False(await mgr.GetLockoutEnabledAsync(user));
|
Assert.False(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -812,7 +876,10 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task UserNotLockedOutWithNullDateTimeAndIsSetToNullDate()
|
public async Task UserNotLockedOutWithNullDateTimeAndIsSetToNullDate()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new EntityUser("LockoutTest");
|
var user = new EntityUser("LockoutTest");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -840,7 +907,10 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task LockoutEndToUtcNowMinus1SecInUserShouldNotBeLockedOut()
|
public async Task LockoutEndToUtcNowMinus1SecInUserShouldNotBeLockedOut()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new EntityUser("LockoutUtcNowTest") { LockoutEnd = DateTime.UtcNow.AddSeconds(-1) };
|
var user = new EntityUser("LockoutUtcNowTest") { LockoutEnd = DateTime.UtcNow.AddSeconds(-1) };
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -852,7 +922,10 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task LockoutEndToUtcNowSubOneSecondWithManagerShouldNotBeLockedOut()
|
public async Task LockoutEndToUtcNowSubOneSecondWithManagerShouldNotBeLockedOut()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new EntityUser("LockoutUtcNowTest");
|
var user = new EntityUser("LockoutUtcNowTest");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -865,7 +938,10 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task LockoutEndToUtcNowPlus5ShouldBeLockedOut()
|
public async Task LockoutEndToUtcNowPlus5ShouldBeLockedOut()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new EntityUser("LockoutUtcNowTest") { LockoutEnd = DateTime.UtcNow.AddMinutes(5) };
|
var user = new EntityUser("LockoutUtcNowTest") { LockoutEnd = DateTime.UtcNow.AddMinutes(5) };
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -877,7 +953,10 @@ namespace Microsoft.AspNet.Identity.Entity.Test
|
||||||
public async Task UserLockedOutWithDateTimeLocalKindNowPlus30()
|
public async Task UserLockedOutWithDateTimeLocalKindNowPlus30()
|
||||||
{
|
{
|
||||||
var mgr = TestIdentityFactory.CreateManager();
|
var mgr = TestIdentityFactory.CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new EntityUser("LockoutTest");
|
var user = new EntityUser("LockoutTest");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,15 @@
|
||||||
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*",
|
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Identity": "",
|
"Microsoft.AspNet.Identity": "",
|
||||||
"Microsoft.AspNet.Identity.Entity": "",
|
"Microsoft.AspNet.Identity.Entity": "",
|
||||||
"Microsoft.AspNet.DependencyInjection": "0.1-alpha-*",
|
"Microsoft.AspNet.PipelineCore": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Logging": "0.1-alpha-*",
|
"Microsoft.AspNet.Logging": "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.RequestContainer": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*",
|
"Microsoft.AspNet.Security.DataProtection": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Testing": "0.1-alpha-*",
|
"Microsoft.AspNet.Testing": "0.1-alpha-*",
|
||||||
"Microsoft.Data.Entity": "0.1-alpha-*",
|
"Microsoft.Data.Entity": "0.1-alpha-*",
|
||||||
"Microsoft.Data.InMemory": "0.1-alpha-*",
|
"Microsoft.Data.InMemory": "0.1-alpha-*",
|
||||||
"Microsoft.Data.Relational": "0.1-alpha-*",
|
"Microsoft.Data.Relational": "0.1-alpha-*",
|
||||||
"Microsoft.Data.SqlServer": "0.1-pre-*",
|
"Remotion.Linq": "1.16-alpha",
|
||||||
"System.Security.Claims": "0.1-alpha-*",
|
"System.Security.Claims": "0.1-alpha-*",
|
||||||
"Xunit.KRunner": "0.1-alpha-*",
|
"Xunit.KRunner": "0.1-alpha-*",
|
||||||
"xunit.abstractions": "2.0.0-aspnet-*",
|
"xunit.abstractions": "2.0.0-aspnet-*",
|
||||||
|
|
|
||||||
|
|
@ -559,8 +559,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task SingleFailureLockout()
|
public async Task SingleFailureLockout()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
{
|
||||||
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
UserLockoutEnabledByDefault = true
|
||||||
|
};
|
||||||
var user = new IdentityUser("fastLockout");
|
var user = new IdentityUser("fastLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -576,9 +579,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task TwoFailureLockout()
|
public async Task TwoFailureLockout()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
{
|
||||||
mgr.MaxFailedAccessAttemptsBeforeLockout = 2;
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 2
|
||||||
|
};
|
||||||
var user = new IdentityUser("twoFailureLockout");
|
var user = new IdentityUser("twoFailureLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -598,9 +604,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task ResetAccessCountPreventsLockout()
|
public async Task ResetAccessCountPreventsLockout()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
{
|
||||||
mgr.MaxFailedAccessAttemptsBeforeLockout = 2;
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 2
|
||||||
|
};
|
||||||
var user = new IdentityUser("resetLockout");
|
var user = new IdentityUser("resetLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -624,8 +633,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task CanEnableLockoutManuallyAndLockout()
|
public async Task CanEnableLockoutManuallyAndLockout()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1);
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
mgr.MaxFailedAccessAttemptsBeforeLockout = 2;
|
{
|
||||||
|
DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1),
|
||||||
|
MaxFailedAccessAttemptsBeforeLockout = 2
|
||||||
|
};
|
||||||
var user = new IdentityUser("manualLockout");
|
var user = new IdentityUser("manualLockout");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.False(await mgr.GetLockoutEnabledAsync(user));
|
Assert.False(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -648,7 +660,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task UserNotLockedOutWithNullDateTimeAndIsSetToNullDate()
|
public async Task UserNotLockedOutWithNullDateTimeAndIsSetToNullDate()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new IdentityUser("LockoutTest");
|
var user = new IdentityUser("LockoutTest");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -676,8 +691,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task LockoutEndToUtcNowMinus1SecInUserShouldNotBeLockedOut()
|
public async Task LockoutEndToUtcNowMinus1SecInUserShouldNotBeLockedOut()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
var user = new IdentityUser("LockoutUtcNowTest") {LockoutEnd = DateTimeOffset.UtcNow.AddSeconds(-1)};
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
|
var user = new IdentityUser("LockoutUtcNowTest") { LockoutEnd = DateTimeOffset.UtcNow.AddSeconds(-1) };
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
Assert.True(user.LockoutEnabled);
|
Assert.True(user.LockoutEnabled);
|
||||||
|
|
@ -688,7 +706,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task LockoutEndToUtcNowSubOneSecondWithManagerShouldNotBeLockedOut()
|
public async Task LockoutEndToUtcNowSubOneSecondWithManagerShouldNotBeLockedOut()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new IdentityUser("LockoutUtcNowTest");
|
var user = new IdentityUser("LockoutUtcNowTest");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -701,8 +722,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task LockoutEndToUtcNowPlus5ShouldBeLockedOut()
|
public async Task LockoutEndToUtcNowPlus5ShouldBeLockedOut()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
var user = new IdentityUser("LockoutUtcNowTest") {LockoutEnd = DateTimeOffset.UtcNow.AddMinutes(5)};
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
|
var user = new IdentityUser("LockoutUtcNowTest") { LockoutEnd = DateTimeOffset.UtcNow.AddMinutes(5) };
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
Assert.True(user.LockoutEnabled);
|
Assert.True(user.LockoutEnabled);
|
||||||
|
|
@ -713,7 +737,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
public async Task UserLockedOutWithDateTimeLocalKindNowPlus30()
|
public async Task UserLockedOutWithDateTimeLocalKindNowPlus30()
|
||||||
{
|
{
|
||||||
var mgr = CreateManager();
|
var mgr = CreateManager();
|
||||||
mgr.UserLockoutEnabledByDefault = true;
|
mgr.LockoutPolicy = new LockoutPolicy
|
||||||
|
{
|
||||||
|
UserLockoutEnabledByDefault = true,
|
||||||
|
};
|
||||||
var user = new IdentityUser("LockoutTest");
|
var user = new IdentityUser("LockoutTest");
|
||||||
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user));
|
||||||
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
Assert.True(await mgr.GetLockoutEnabledAsync(user));
|
||||||
|
|
@ -1431,7 +1458,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
|
|
||||||
private static UserManager<IdentityUser> CreateManager()
|
private static UserManager<IdentityUser> CreateManager()
|
||||||
{
|
{
|
||||||
return new UserManager<IdentityUser>(new InMemoryUserStore<IdentityUser>());
|
var manager = new UserManager<IdentityUser>(new InMemoryUserStore<IdentityUser>())
|
||||||
|
{
|
||||||
|
UserValidator = new UserValidator<IdentityUser>(),
|
||||||
|
PasswordValidator = new PasswordValidator()
|
||||||
|
};
|
||||||
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RoleManager<IdentityRole> CreateRoleManager()
|
private static RoleManager<IdentityRole> CreateRoleManager()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
using Microsoft.AspNet.Abstractions;
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
using Microsoft.AspNet.DependencyInjection.Fallback;
|
||||||
|
using Microsoft.AspNet.PipelineCore;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Identity.InMemory.Test
|
||||||
|
{
|
||||||
|
public class StartupTest
|
||||||
|
{
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task EnsureStartupUsageWorks()
|
||||||
|
{
|
||||||
|
IBuilder builder = new Builder(new ServiceCollection().BuildServiceProvider());
|
||||||
|
|
||||||
|
builder.UseServices(services => services.AddIdentity<ApplicationUser>(s =>
|
||||||
|
{
|
||||||
|
s.UseUserStore(() => new InMemoryUserStore<ApplicationUser>());
|
||||||
|
s.UseUserManager<ApplicationUserManager>();
|
||||||
|
s.UseRoleStore(() => new InMemoryRoleStore<IdentityRole>());
|
||||||
|
s.UseRoleManager<ApplicationRoleManager>();
|
||||||
|
}));
|
||||||
|
|
||||||
|
var userStore = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>();
|
||||||
|
var roleStore = builder.ApplicationServices.GetService<IRoleStore<IdentityRole>>();
|
||||||
|
var userManager = builder.ApplicationServices.GetService<ApplicationUserManager>();
|
||||||
|
var roleManager = builder.ApplicationServices.GetService<ApplicationRoleManager>();
|
||||||
|
|
||||||
|
Assert.NotNull(userStore);
|
||||||
|
Assert.NotNull(userManager);
|
||||||
|
Assert.NotNull(roleStore);
|
||||||
|
Assert.NotNull(roleManager);
|
||||||
|
|
||||||
|
await CreateAdminUser(builder.ApplicationServices);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task CreateAdminUser(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
const string userName = "admin";
|
||||||
|
const string roleName = "Admins";
|
||||||
|
const string password = "1qaz@WSX";
|
||||||
|
var userManager = serviceProvider.GetService<ApplicationUserManager>();
|
||||||
|
var roleManager = serviceProvider.GetService<ApplicationRoleManager>();
|
||||||
|
|
||||||
|
var user = new ApplicationUser { UserName = userName };
|
||||||
|
IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));
|
||||||
|
IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(new IdentityRole { Name = roleName }));
|
||||||
|
IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(user, roleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class ApplicationUserManager : UserManager<ApplicationUser>
|
||||||
|
{
|
||||||
|
public ApplicationUserManager(IServiceProvider services) : base(services) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApplicationRoleManager : RoleManager<IdentityRole>
|
||||||
|
{
|
||||||
|
public ApplicationRoleManager(IServiceProvider services) : base(services) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApplicationUser : IdentityUser
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
{
|
{
|
||||||
"version": "0.1-alpha-*",
|
"version": "0.1-alpha-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Identity" : "",
|
"Microsoft.AspNet.Abstractions" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Identity.InMemory" : "",
|
"Microsoft.AspNet.ConfigurationModel" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.Identity" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.Identity.InMemory" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.PipelineCore" : "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.RequestContainer" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Testing" : "0.1-alpha-*",
|
"Microsoft.AspNet.Testing" : "0.1-alpha-*",
|
||||||
"Xunit.KRunner": "0.1-alpha-*",
|
"Xunit.KRunner": "0.1-alpha-*",
|
||||||
"xunit.abstractions": "2.0.0-aspnet-*",
|
"xunit.abstractions": "2.0.0-aspnet-*",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
using System.Security.Claims;
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
|
using Microsoft.AspNet.DependencyInjection.Fallback;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Identity.Test
|
||||||
|
{
|
||||||
|
public class IdentityBuilderTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void CanSpecifyUserValidatorInstance()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var validator = new UserValidator<IdentityUser>();
|
||||||
|
services.AddIdentity<IdentityUser>(b => b.UseUserValidator(() => validator));
|
||||||
|
Assert.Equal(validator, services.BuildServiceProvider().GetService<IUserValidator<IdentityUser>>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CanSpecifyPasswordValidatorInstance()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var validator = new PasswordValidator();
|
||||||
|
services.AddIdentity<IdentityUser>(b => b.UsePasswordValidator(() => validator));
|
||||||
|
Assert.Equal(validator, services.BuildServiceProvider().GetService<IPasswordValidator>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CanSpecifyLockoutPolicyInstance()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var policy = new LockoutPolicy();
|
||||||
|
services.AddIdentity<IdentityUser>(b => b.UseLockoutPolicy(() => policy));
|
||||||
|
Assert.Equal(policy, services.BuildServiceProvider().GetService<LockoutPolicy>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CanSpecifyPasswordHasherInstance()
|
||||||
|
{
|
||||||
|
CanOverride<IPasswordHasher, PasswordHasher>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CanSpecifyClaimsIdentityFactoryInstance()
|
||||||
|
{
|
||||||
|
CanOverride<IClaimsIdentityFactory<IdentityUser>, ClaimsIdentityFactory<IdentityUser>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EnsureDefaultServices()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var builder = new IdentityBuilder<IdentityUser, IdentityRole>(services);
|
||||||
|
builder.UseIdentity();
|
||||||
|
|
||||||
|
var provider = services.BuildServiceProvider();
|
||||||
|
var userValidator = provider.GetService<IUserValidator<IdentityUser>>() as UserValidator<IdentityUser>;
|
||||||
|
Assert.NotNull(userValidator);
|
||||||
|
Assert.True(userValidator.AllowOnlyAlphanumericUserNames);
|
||||||
|
Assert.False(userValidator.RequireUniqueEmail);
|
||||||
|
|
||||||
|
var pwdValidator = provider.GetService<IPasswordValidator>() as PasswordValidator;
|
||||||
|
Assert.NotNull(userValidator);
|
||||||
|
Assert.True(pwdValidator.RequireDigit);
|
||||||
|
Assert.True(pwdValidator.RequireLowercase);
|
||||||
|
Assert.True(pwdValidator.RequireNonLetterOrDigit);
|
||||||
|
Assert.True(pwdValidator.RequireUppercase);
|
||||||
|
Assert.Equal(6, pwdValidator.RequiredLength);
|
||||||
|
|
||||||
|
var hasher = provider.GetService<IPasswordHasher>() as PasswordHasher;
|
||||||
|
Assert.NotNull(hasher);
|
||||||
|
|
||||||
|
var claimsFactory = provider.GetService<IClaimsIdentityFactory<IdentityUser>>() as ClaimsIdentityFactory<IdentityUser>;
|
||||||
|
Assert.NotNull(claimsFactory);
|
||||||
|
Assert.Equal(ClaimTypes.Role, claimsFactory.RoleClaimType);
|
||||||
|
Assert.Equal(ClaimsIdentityFactory<IdentityUser>.DefaultSecurityStampClaimType, claimsFactory.SecurityStampClaimType);
|
||||||
|
Assert.Equal(ClaimTypes.Name, claimsFactory.UserNameClaimType);
|
||||||
|
Assert.Equal(ClaimTypes.NameIdentifier, claimsFactory.UserIdClaimType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CanOverride<TService, TImplementation>() where TImplementation : TService,new()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var instance = new TImplementation();
|
||||||
|
services.AddIdentity<IdentityUser>(b => b.Use<TService>(() => instance));
|
||||||
|
Assert.Equal(instance, services.BuildServiceProvider().GetService<TService>());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ConstructorThrowsWithNullStore()
|
public void ConstructorThrowsWithNullStore()
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentNullException>("store", () => new RoleManager<TestRole>(null));
|
Assert.Throws<ArgumentNullException>("store", () => new RoleManager<TestRole>((IRoleStore<TestRole>)null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -34,8 +34,9 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
public async Task RoleManagerPublicNullChecks()
|
public async Task RoleManagerPublicNullChecks()
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentNullException>("store",
|
Assert.Throws<ArgumentNullException>("store",
|
||||||
() => new RoleManager<TestRole>(null));
|
() => new RoleManager<TestRole>((IRoleStore<TestRole>)null));
|
||||||
var manager = new RoleManager<TestRole>(new NotImplementedStore());
|
var manager = new RoleManager<TestRole>(new NotImplementedStore());
|
||||||
|
Assert.Throws<ArgumentNullException>("services", () => manager.Initialize(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.CreateAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.CreateAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.UpdateAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.UpdateAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.DeleteAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.DeleteAsync(null));
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
using Microsoft.AspNet.DependencyInjection;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Identity.Test
|
|
||||||
{
|
|
||||||
public static class TestServices
|
|
||||||
{
|
|
||||||
public static IEnumerable<IServiceDescriptor> DefaultServices<TUser, TKey>()
|
|
||||||
where TUser : class
|
|
||||||
{
|
|
||||||
var describer = new ServiceDescriber();
|
|
||||||
yield return describer.Transient<IPasswordValidator, PasswordValidator>();
|
|
||||||
yield return describer.Transient<IUserValidator<TUser>, UserValidator<TUser>>();
|
|
||||||
yield return describer.Transient<IPasswordHasher, PasswordHasher>();
|
|
||||||
yield return describer.Transient<IClaimsIdentityFactory<TUser>, ClaimsIdentityFactory<TUser>>();
|
|
||||||
yield return describer.Transient<IUserStore<TUser>, NoopUserStore>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
using Microsoft.AspNet.DependencyInjection.Fallback;
|
using Microsoft.AspNet.DependencyInjection.Fallback;
|
||||||
using Moq;
|
using Moq;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -20,13 +21,19 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ServiceProviderWireupTest()
|
public void EnsureDefaultServicesDefaultsWithStoreWorks()
|
||||||
{
|
{
|
||||||
var manager = new TestManager(TestServices.DefaultServices<TestUser, string>().BuildServiceProvider());
|
var services = new ServiceCollection {IdentityServices.GetDefaultUserServices<TestUser>()};
|
||||||
|
services.AddInstance<IUserStore<TestUser>>(new NoopUserStore());
|
||||||
|
var manager = new TestManager(services.BuildServiceProvider());
|
||||||
Assert.NotNull(manager.PasswordHasher);
|
Assert.NotNull(manager.PasswordHasher);
|
||||||
Assert.NotNull(manager.PasswordValidator);
|
Assert.NotNull(manager.PasswordValidator);
|
||||||
Assert.NotNull(manager.UserValidator);
|
Assert.NotNull(manager.UserValidator);
|
||||||
Assert.NotNull(manager.StorePublic);
|
Assert.NotNull(manager.StorePublic);
|
||||||
|
Assert.NotNull(manager.LockoutPolicy);
|
||||||
|
Assert.Equal(TimeSpan.FromMinutes(5), manager.LockoutPolicy.DefaultAccountLockoutTimeSpan);
|
||||||
|
Assert.Equal(5, manager.LockoutPolicy.MaxFailedAccessAttemptsBeforeLockout);
|
||||||
|
Assert.False(manager.LockoutPolicy.UserLockoutEnabledByDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NET45
|
#if NET45
|
||||||
|
|
@ -419,13 +426,12 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ManagerPublicNullChecks()
|
public async Task ManagerPublicNullChecks()
|
||||||
{
|
{
|
||||||
Assert.Throws<ArgumentNullException>("store",
|
|
||||||
() => new UserManager<TestUser>((IUserStore<TestUser>) null));
|
|
||||||
Assert.Throws<ArgumentNullException>("serviceProvider",
|
Assert.Throws<ArgumentNullException>("serviceProvider",
|
||||||
() => new UserManager<TestUser>((IServiceProvider)null));
|
() => new UserManager<TestUser>((IServiceProvider)null));
|
||||||
var manager = new UserManager<TestUser>(new NotImplementedStore());
|
var manager = new UserManager<TestUser>(new NotImplementedStore());
|
||||||
Assert.Throws<ArgumentNullException>(() => manager.ClaimsIdentityFactory = null);
|
Assert.Throws<ArgumentNullException>(() => manager.ClaimsIdentityFactory = null);
|
||||||
Assert.Throws<ArgumentNullException>(() => manager.PasswordHasher = null);
|
Assert.Throws<ArgumentNullException>(() => manager.PasswordHasher = null);
|
||||||
|
Assert.Throws<ArgumentNullException>("serviceProvider", () => manager.Initialize(null));
|
||||||
await
|
await
|
||||||
Assert.ThrowsAsync<ArgumentNullException>("user",
|
Assert.ThrowsAsync<ArgumentNullException>("user",
|
||||||
async () => await manager.CreateIdentityAsync(null, "whatever"));
|
async () => await manager.CreateIdentityAsync(null, "whatever"));
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.ConfigurationModel" : "0.1-alpha-*",
|
"Microsoft.AspNet.ConfigurationModel" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Identity" : "",
|
"Microsoft.AspNet.Identity" : "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.Testing" : "0.1-alpha-*",
|
"Microsoft.AspNet.Testing" : "0.1-alpha-*",
|
||||||
"Xunit.KRunner": "0.1-alpha-*",
|
"Xunit.KRunner": "0.1-alpha-*",
|
||||||
"xunit.abstractions": "2.0.0-aspnet-*",
|
"xunit.abstractions": "2.0.0-aspnet-*",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue