private void CreateUsers(IdentityServerDbContext context) { if (!context.Users.Any()) { var adminUser = new ApplicationUser { UserName = "******", Email = "*****@*****.**", Mobile = "0123456789", EmailConfirmed = true }; _userManager.CreateAsync(adminUser, "Admin@1234").Result.ToString(); _userManager.AddClaimAsync(adminUser, new Claim(IdentityServerConstants.StandardScopes.Phone, adminUser.Mobile.ToString(), ClaimValueTypes.Integer)).Result.ToString(); _userManager.AddToRoleAsync(_userManager.FindByNameAsync("*****@*****.**") .GetAwaiter().GetResult(), "Admin").Result.ToString(); var normalUser = new ApplicationUser { UserName = "******", Email = "*****@*****.**", Mobile = "0123456789", EmailConfirmed = true }; _userManager.CreateAsync(normalUser, "User@1234").Result.ToString(); _userManager.AddClaimAsync(adminUser, new Claim(IdentityServerConstants.StandardScopes.Phone, adminUser.Mobile.ToString(), ClaimValueTypes.Integer)).Result.ToString(); _userManager.AddToRoleAsync(_userManager.FindByNameAsync("*****@*****.**") .GetAwaiter().GetResult(), "User").Result.ToString(); } }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var user = new User(); var id = Guid.NewGuid(); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(user); await context.SaveChangesAsync().ConfigureAwait(false); } RolesModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _userManager.Setup(x => x.Users).Returns(context.Users); model = new RolesModel(_userManager.Object, _roleManager.Object); get = await model.OnGetAsync(id).ConfigureAwait(false); } // Assert Assert.Null(model.UserModel); Assert.Null(model.Roles); Assert.IsType <NotFoundResult>(get); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; RedirectUrisModel redirectUris; IActionResult post; var clientId = Random.Next(); var client = new Client { Id = clientId, RedirectUris = new List <ClientRedirectUri> { new ClientRedirectUri { Id = Random.Next() } } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { redirectUris = new RedirectUrisModel(context) { Client = new Client { Id = clientId } }; post = await redirectUris.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { client = await context.Clients .Include(x => x.RedirectUris) .SingleOrDefaultAsync(x => x.Id.Equals(clientId)) .ConfigureAwait(false); Assert.Empty(client.RedirectUris); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/RedirectUris", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Client.Id), key); Assert.Equal(redirectUris.Client.Id, value); }); }
public async Task OnPostAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; IActionResult post; var client = new Client { Id = Random.Next() }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { var redirectUris = new RedirectUrisModel(context) { Client = new Client { Id = Random.Next() } }; post = await redirectUris.OnPostAsync().ConfigureAwait(false); } // Assert Assert.IsType <PageResult>(post); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; PropertiesModel properties; IActionResult post; var identityResourceId = Random.Next(); var identityResource = new IdentityResource { Id = identityResourceId, Properties = new List <IdentityResourceProperty> { new IdentityResourceProperty { Id = Random.Next() } } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(identityResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { properties = new PropertiesModel(context) { IdentityResource = new IdentityResource { Id = identityResourceId } }; post = await properties.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { identityResource = await context.IdentityResources .Include(x => x.Properties) .SingleOrDefaultAsync(x => x.Id.Equals(identityResourceId)) .ConfigureAwait(false); Assert.Empty(identityResource.Properties); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Properties", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(IdentityResource.Id), key); Assert.Equal(properties.IdentityResource.Id, value); }); }
public async Task OnGetAsync_InvalidId() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidId)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var role = new Role(); role.RoleClaims.Add(new RoleClaim()); role.RoleClaims.Add(new RoleClaim()); role.RoleClaims.Add(new RoleClaim()); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } ClaimsModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _roleManager.Setup(x => x.Roles).Returns(context.Roles); model = new ClaimsModel(_roleManager.Object); get = await model.OnGetAsync(Guid.Empty).ConfigureAwait(false); } // Assert Assert.Null(model.Role); Assert.Null(model.Claims); Assert.IsType <NotFoundResult>(get); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var userClaim = new UserClaim { ClaimType = "Claim Type", ClaimValue = "Claim Value" }; var user = new User { Email = "Email" }; user.Claims.Add(userClaim); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(user); await context.SaveChangesAsync().ConfigureAwait(false); } IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _userManager.Setup(x => x.Users).Returns(context.Users); var model = new ClaimsModel(_userManager.Object) { UserModel = new User { Id = user.Id } }; get = await model.OnPostAsync().ConfigureAwait(false); } // Assert _userManager.Verify( x => x.RemoveClaimsAsync( It.Is <User>(y => y.Id.Equals(user.Id)), It.Is <IEnumerable <Claim> >(y => y.SingleOrDefault(z => z.Type.Equals(userClaim.ClaimType) && z.Value.Equals(userClaim.ClaimValue)) != null)), Times.Once); var result = Assert.IsType <RedirectToPageResult>(get); Assert.Equal("../Details/Claims", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(User.Id), key); Assert.Equal(user.Id, value); }); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var roleClaim = new RoleClaim { ClaimType = "Claim Type", ClaimValue = "Claim Value" }; var role = new Role { Name = "Role Name" }; role.RoleClaims.Add(roleClaim); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _roleManager.Setup(x => x.Roles).Returns(context.Roles); var model = new ClaimsModel(_roleManager.Object) { Role = new Role { Id = role.Id } }; get = await model.OnPostAsync().ConfigureAwait(false); } // Assert _roleManager.Verify( x => x.RemoveClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(roleClaim.ClaimType) && y.Value.Equals(roleClaim.ClaimValue))), Times.Once); var result = Assert.IsType <RedirectToPageResult>(get); Assert.Equal("../Details/Claims", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Role.Id), key); Assert.Equal(role.Id, value); }); }
public UserClaimsController(IdentityServerDbContext dbContext, ILogger <UserClaimsController> logger) { if (dbContext == null || logger == null) { throw new ArgumentNullException(); } Contract.EndContractBlock(); _dbContext = dbContext; _logger = logger; }
public static void SeedHostDb(IdentityServerDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); }
public void Seed(IServiceProvider serviceProvider) { using IServiceScope scope = serviceProvider.GetRequiredService <IServiceScopeFactory>() .CreateScope(); // Seeding Users and roles IdentityServerDbContext appContext = scope.ServiceProvider.GetService <IdentityServerDbContext>(); appContext.Database.Migrate(); CreateRoles(); CreateUsers(appContext); }
private void SeedData(IdentityServerDbContext dbContext) { if (!dbContext.Scopes.Any(e => e.Name == "system")) { dbContext.Scopes.Add(new ScopeEntity("system")); } if (!dbContext.Clients.Any(e => e.ClientId == "testclient")) { dbContext.Clients.Add(new ClientEntity("testclient")); } dbContext.SaveChanges(); }
public RolesController(IdentityServerDbContext dbContext, RoleManager <IdentityRole> roleManager, ILogger <RolesController> logger, ILogger <RolePaginationProvider> paginationLogger) { if (dbContext == null || roleManager == null || logger == null) { throw new ArgumentNullException(); } Contract.EndContractBlock(); _dbContext = dbContext; _roleManager = roleManager; _logger = logger; _paginationLogger = paginationLogger; }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var user = new User(); user.UserRoles.Add(new UserRole { Role = new Role() }); user.UserRoles.Add(new UserRole { Role = new Role() }); user.UserRoles.Add(new UserRole { Role = new Role() }); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(user); await context.SaveChangesAsync().ConfigureAwait(false); var rolesList = await context.Roles.ToListAsync().ConfigureAwait(false); _roleManager.Setup(x => x.Roles).Returns(rolesList.AsQueryable()); } RolesModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _userManager.Setup(x => x.Users).Returns(context.Users); model = new RolesModel(_userManager.Object, _roleManager.Object); get = await model.OnGetAsync(user.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.UserModel); Assert.Equal(user.Id, model.UserModel.Id); var roles = Assert.IsAssignableFrom <IEnumerable <Role> >(model.Roles); Assert.Equal(user.UserRoles.Count, roles.Count()); Assert.IsType <PageResult>(get); }
public IdentityDbContextFixture() { // ... initialize data in the test database ... var services = new ServiceCollection(); //var connectionString = @"Server=(local);Database=identityserver;Trusted_Connection=True;"; var connectionString = @"Server=192.168.1.13;Database=identityserver;User ID=sa;Password=Welcome123;"; services.AddIdentityServerEntityFrameworkCoreServices(options => options.UseSqlServer(connectionString)); services.AddOptions(); var serviceProvider = services.BuildServiceProvider(); var dbContext = serviceProvider.GetService <IdentityServerDbContext>(); this.DbContext = dbContext; //dbContext.Database.Migrate(); var ensureCreated = dbContext.Database.EnsureCreated(); SeedData(dbContext); }
public UsersController(IdentityServerDbContext dbContext, IPaginationDataProvider <User, object> userPaginationProvider, IPaginationDataProvider <IdentityUserClaim <string>, object> userClaimPaginationProvider, IPaginationDataProvider <IdentityRole, object> rolePaginationProvider, UserManager <User> userManager, RoleManager <IdentityRole> roleManager, ILogger <UsersController> logger) { if (dbContext == null || userPaginationProvider == null || userClaimPaginationProvider == null || rolePaginationProvider == null || userManager == null || logger == null) { throw new ArgumentNullException(); } Contract.EndContractBlock(); _dbContext = dbContext; _userPaginationProvider = userPaginationProvider; _userClaimPaginationProvider = userClaimPaginationProvider; _rolePaginationProvider = rolePaginationProvider; _userManager = userManager; _logger = logger; }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var identityResource = new IdentityResource { Id = Random.Next(), Properties = new List <IdentityResourceProperty> { new IdentityResourceProperty(), new IdentityResourceProperty(), new IdentityResourceProperty() } }; PropertiesModel model; IActionResult get; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(identityResource); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new PropertiesModel(context); get = await model.OnGetAsync(identityResource.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.IdentityResource); Assert.Equal(identityResource.Id, model.IdentityResource.Id); var properties = Assert.IsAssignableFrom <IEnumerable <IdentityResourceProperty> >(model.Properties); Assert.Equal(identityResource.Properties.Count, properties.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var client = new Client { Id = Random.Next(), RedirectUris = new List <ClientRedirectUri> { new ClientRedirectUri(), new ClientRedirectUri(), new ClientRedirectUri() } }; RedirectUrisModel model; IActionResult get; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new RedirectUrisModel(context); get = await model.OnGetAsync(client.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.Client); Assert.Equal(client.Id, model.Client.Id); var redirectUris = Assert.IsAssignableFrom <IEnumerable <ClientRedirectUri> >(model.RedirectUris); Assert.Equal(client.RedirectUris.Count, redirectUris.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var role = new Role { Id = Guid.NewGuid() }; role.RoleClaims.Add(new RoleClaim()); role.RoleClaims.Add(new RoleClaim()); role.RoleClaims.Add(new RoleClaim()); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } ClaimsModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _roleManager.Setup(x => x.Roles).Returns(context.Roles); model = new ClaimsModel(_roleManager.Object); get = await model.OnGetAsync(role.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.Role); Assert.Equal(role.Id, model.Role.Id); var claims = Assert.IsAssignableFrom <IEnumerable <RoleClaim> >(model.Claims); Assert.Equal(role.RoleClaims.Count, claims.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; RedirectUrisModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new RedirectUrisModel(context); get = await model.OnGetAsync(Random.Next()).ConfigureAwait(false); } // Assert Assert.Null(model.Client); Assert.Null(model.RedirectUris); Assert.IsType <NotFoundResult>(get); }
public async Task OnPostAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var role = new Role { Id = Guid.NewGuid() }; var id = Guid.NewGuid(); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } IActionResult post; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _roleManager.Setup(x => x.Roles).Returns(context.Roles); var model = new ClaimsModel(_roleManager.Object) { Role = new Role { Id = id } }; post = await model.OnPostAsync().ConfigureAwait(false); } // Assert _roleManager.Verify(x => x.UpdateAsync(It.IsAny <Role>()), Times.Never); Assert.IsType <PageResult>(post); }
public static async Task Seed(IdentityServerDbContext dbContext) { var roleStore = new RoleStore <IdentityRole>(dbContext); await roleStore.CreateAsync(new IdentityRole { Id = Guid.NewGuid().ToString(), Name = "user", NormalizedName = "user" }); await roleStore.CreateAsync(new IdentityRole { Id = Guid.NewGuid().ToString(), Name = "admin", NormalizedName = "admin" }); var userStore = new UserStore <AppUser>(dbContext); var password = new PasswordHasher <AppUser>(); var rootUser = new AppUser { Id = Guid.NewGuid().ToString(), UserName = "******", Email = "*****@*****.**", NormalizedEmail = "*****@*****.**", NormalizedUserName = "******", SecurityStamp = Guid.NewGuid().ToString("D"), LockoutEnabled = true, ShippingAddress = new Core.SharedKernel.AddressInfo(Guid.NewGuid(), "123 Address", "HCM", "TB district", "7000", "VN") }; rootUser.PasswordHash = password.HashPassword(rootUser, "root"); await userStore.CreateAsync(rootUser); await userStore.AddToRoleAsync(rootUser, "admin"); }
public IdentityResourceClaimsController(IdentityServerDbContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; }
public async Task OnPostAsync() { // Arrange const string originalRoleClaim2Type = "Claim 2 Type"; const string newRoleClaim2Type = "New Claim Type"; var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var roleClaim1 = new RoleClaim { ClaimType = "Claim 1 Type", ClaimValue = "Claim 1 Value" }; var roleClaim2 = new RoleClaim { ClaimType = originalRoleClaim2Type, ClaimValue = "Claim 2 Value" }; var roleClaim3 = new RoleClaim { ClaimType = "Claim 3 Type", ClaimValue = "Claim 3 Value" }; var roleClaim4 = new RoleClaim { ClaimType = "Claim 4 Type", ClaimValue = "Claim 4 Value" }; var role = new Role { Name = "Role Name" }; role.RoleClaims.Add(roleClaim1); role.RoleClaims.Add(roleClaim2); role.RoleClaims.Add(roleClaim3); using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(role); await context.SaveChangesAsync().ConfigureAwait(false); } IActionResult post; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { _roleManager.Setup(x => x.Roles).Returns(context.Roles); var model = new ClaimsModel(_roleManager.Object) { Role = role }; model.Role.RoleClaims.Single(x => x.ClaimType.Equals(roleClaim2.ClaimType)).ClaimType = newRoleClaim2Type; model.Role.RoleClaims.Remove(roleClaim3); model.Role.RoleClaims.Add(roleClaim4); post = await model.OnPostAsync().ConfigureAwait(false); } // Assert _roleManager.Verify(x => x.RemoveClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(roleClaim1.ClaimType) && y.Value.Equals(roleClaim1.ClaimValue))), Times.Never); _roleManager.Verify(x => x.AddClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(roleClaim1.ClaimType) && y.Value.Equals(roleClaim1.ClaimValue))), Times.Never); _roleManager.Verify(x => x.RemoveClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(originalRoleClaim2Type) && y.Value.Equals(roleClaim2.ClaimValue))), Times.Once); _roleManager.Verify(x => x.AddClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(newRoleClaim2Type) && y.Value.Equals(roleClaim2.ClaimValue))), Times.Once); _roleManager.Verify( x => x.AddClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(roleClaim4.ClaimType) && y.Value.Equals(roleClaim4.ClaimValue))), Times.Once); _roleManager.Verify( x => x.RemoveClaimAsync( It.Is <Role>(y => y.Id.Equals(role.Id)), It.Is <Claim>(y => y.Type.Equals(roleClaim3.ClaimType) && y.Value.Equals(roleClaim3.ClaimValue))), Times.Once); var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Claims", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Role.Id), key); Assert.Equal(role.Id, value); }); }
public ApiResourceSecretsController(IdentityServerDbContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; }
public DefaultTenantBuilder(IdentityServerDbContext context) { _context = context; }
public ClientPostLogoutRedirectUrisController(IdentityServerDbContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; }
public async Task OnPostAsync() { // Arrange const string redirectUri1OriginalRedirectUri = "Original RedirectUri"; const string redirectUri1EditedRedirectUri = "Edited RedirectUri"; const string newRedirectUriRedirectUri = "New RedirectUri"; var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; RedirectUrisModel redirectUris; IActionResult post; var redirectUri1 = new ClientRedirectUri { Id = Random.Next(), RedirectUri = redirectUri1OriginalRedirectUri }; var redirectUri2 = new ClientRedirectUri { Id = Random.Next() }; var clientId = Random.Next(); var client = new Client { Id = clientId, RedirectUris = new List <ClientRedirectUri> { redirectUri1, redirectUri2 } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { redirectUris = new RedirectUrisModel(context) { Client = new Client { Id = clientId, RedirectUris = new List <ClientRedirectUri> { new ClientRedirectUri { Id = redirectUri1.Id, RedirectUri = redirectUri1EditedRedirectUri }, new ClientRedirectUri { RedirectUri = newRedirectUriRedirectUri } } } }; post = await redirectUris.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { client = await context.Clients .Include(x => x.RedirectUris) .SingleOrDefaultAsync(x => x.Id.Equals(clientId)) .ConfigureAwait(false); redirectUri1 = client.RedirectUris.SingleOrDefault(x => x.Id.Equals(redirectUri1.Id)); redirectUri2 = client.RedirectUris.SingleOrDefault(x => x.Id.Equals(redirectUri2.Id)); var newRedirectUri = client.RedirectUris.SingleOrDefault(x => x.RedirectUri.Equals(newRedirectUriRedirectUri)); Assert.NotNull(redirectUri1); Assert.Equal(redirectUri1EditedRedirectUri, redirectUri1.RedirectUri); Assert.Null(redirectUri2); Assert.NotNull(newRedirectUri); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/RedirectUris", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Client.Id), key); Assert.Equal(redirectUris.Client.Id, value); }); }
public ApiScopeClaimsController(IdentityServerDbContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; }
public UserClaimPaginationProvider(IdentityServerDbContext dbContext, ILogger <UserClaimPaginationProvider> logger) : base(dbContext, logger) { }