mirror of https://github.com/abpframework/abp.git
committed by
GitHub
48 changed files with 916 additions and 46 deletions
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 118 KiB |
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
"culture": "es", |
||||
|
"texts": { |
||||
|
"Documents": "Documentos", |
||||
|
"BackToWebsite": "Regresar al sitio", |
||||
|
"Version": "Versión", |
||||
|
"Edit": "Editar", |
||||
|
"InThisDocument": "En este documento", |
||||
|
"GoToTop": "Subir", |
||||
|
"Projects": "Proyecto(s)", |
||||
|
"NoProjectWarning": "¡Aun no hay proyectos!", |
||||
|
"DocumentNotFound": "¡Oops, no se encontró el documento solicitado!" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.MongoDB.Tests</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.MongoDB.Tests</PackageId> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.MongoDB\Volo.Abp.IdentityServer.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.IdentityServer.TestBase\Volo.Abp.IdentityServer.TestBase.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
||||
|
<PackageReference Include="Mongo2Go" Version="2.2.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,22 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.MongoDB</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.MongoDB</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" /> |
||||
|
|
||||
|
<ProjectReference Include="..\..\..\..\..\abp\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,37 @@ |
|||||
|
using MongoDB.Bson.Serialization; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public class AbpIdentityServerBsonClassMap |
||||
|
{ |
||||
|
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
||||
|
|
||||
|
public static void Configure() |
||||
|
{ |
||||
|
OneTimeRunner.Run(() => |
||||
|
{ |
||||
|
BsonClassMap.RegisterClassMap<ApiResource>(map => |
||||
|
{ |
||||
|
map.AutoMap(); |
||||
|
}); |
||||
|
BsonClassMap.RegisterClassMap<Client>(map => |
||||
|
{ |
||||
|
map.AutoMap(); |
||||
|
}); |
||||
|
BsonClassMap.RegisterClassMap<IdentityResource>(map => |
||||
|
{ |
||||
|
map.AutoMap(); |
||||
|
}); |
||||
|
BsonClassMap.RegisterClassMap<PersistedGrant>(map => |
||||
|
{ |
||||
|
map.AutoMap(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
[ConnectionStringName("AbpIdentityServer")] |
||||
|
public class AbpIdentityServerMongoDbContext : AbpMongoDbContext, IAbpIdentityServerMongoDbContext |
||||
|
{ |
||||
|
public static string CollectionPrefix { get; set; } = AbpIdentityServerConsts.DefaultDbTablePrefix; |
||||
|
|
||||
|
public IMongoCollection<ApiResource> ApiResources => Collection<ApiResource>(); |
||||
|
|
||||
|
public IMongoCollection<Client> Clients => Collection<Client>(); |
||||
|
|
||||
|
public IMongoCollection<IdentityResource> IdentityResources => Collection<IdentityResource>(); |
||||
|
|
||||
|
public IMongoCollection<PersistedGrant> PersistedGrants => Collection<PersistedGrant>(); |
||||
|
|
||||
|
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
||||
|
{ |
||||
|
base.CreateModel(modelBuilder); |
||||
|
|
||||
|
modelBuilder.ConfigureIdentityServer(options => |
||||
|
{ |
||||
|
options.CollectionPrefix = CollectionPrefix; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public static class AbpIdentityServerMongoDbContextExtensions |
||||
|
{ |
||||
|
public static void ConfigureIdentityServer( |
||||
|
this IMongoModelBuilder builder, |
||||
|
Action<IdentityServerMongoModelBuilderConfigurationOptions> optionsAction = null) |
||||
|
{ |
||||
|
Check.NotNull(builder, nameof(builder)); |
||||
|
|
||||
|
var options = new IdentityServerMongoModelBuilderConfigurationOptions(); |
||||
|
|
||||
|
optionsAction?.Invoke(options); |
||||
|
|
||||
|
builder.Entity<ApiResource>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "ApiResources"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<Client>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "Clients"; |
||||
|
}); |
||||
|
builder.Entity<IdentityResource>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "IdentityResources"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<PersistedGrant>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "PersistedGrants"; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; |
||||
|
using Client = Volo.Abp.IdentityServer.Clients.Client; |
||||
|
using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpIdentityServerDomainModule), |
||||
|
typeof(AbpMongoDbModule) |
||||
|
)] |
||||
|
public class AbpIdentityServerMongoDbModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
AbpIdentityServerBsonClassMap.Configure(); |
||||
|
|
||||
|
context.Services.AddMongoDbContext<AbpIdentityServerMongoDbContext>(options => |
||||
|
{ |
||||
|
options.AddRepository<ApiResource, MongoApiResourceRepository>(); |
||||
|
options.AddRepository<IdentityResource, MongoIdentityResourceRepository>(); |
||||
|
options.AddRepository<Client, MongoClientRepository>(); |
||||
|
options.AddRepository<PersistedGrant, MongoPersistedGrantRepository>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
[ConnectionStringName("AbpIdentityServer")] |
||||
|
public interface IAbpIdentityServerMongoDbContext : IAbpMongoDbContext |
||||
|
{ |
||||
|
IMongoCollection<ApiResource> ApiResources { get; } |
||||
|
|
||||
|
IMongoCollection<Client> Clients { get; } |
||||
|
|
||||
|
IMongoCollection<IdentityResource> IdentityResources { get; } |
||||
|
|
||||
|
IMongoCollection<PersistedGrant> PersistedGrants { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public class IdentityServerMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions |
||||
|
{ |
||||
|
public IdentityServerMongoModelBuilderConfigurationOptions() |
||||
|
: base(AbpIdentityServerConsts.DefaultDbTablePrefix) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public class MongoApiResourceRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, ApiResource, Guid>, IApiResourceRepository |
||||
|
{ |
||||
|
public MongoApiResourceRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ApiResource> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.Where(ar=>ar.Name == name) |
||||
|
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<ApiResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.Where(ar=>ar.Scopes.Any(x=> scopeNames.Contains(x.Name))) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public class MongoClientRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, Client, Guid>, IClientRepository |
||||
|
{ |
||||
|
public MongoClientRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<Client> FindByCliendIdAsync(string clientId, bool includeDetails = true, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public class MongoIdentityResourceRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, IdentityResource, Guid>, IIdentityResourceRepository |
||||
|
{ |
||||
|
public MongoIdentityResourceRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.Where(ar => scopeNames.Contains(ar.Name)) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.MongoDB |
||||
|
{ |
||||
|
public class MongoPersistedGrantRepository : MongoDbRepository<IAbpIdentityServerMongoDbContext, PersistedGrant, Guid>, IPersistentGrantRepository |
||||
|
{ |
||||
|
public MongoPersistedGrantRepository(IMongoDbContextProvider<IAbpIdentityServerMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<PersistedGrant> FindByKeyAsync(string key, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
|
||||
|
return await GetMongoQueryable() |
||||
|
.FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.Where(x => x.SubjectId == subjectId) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
await DeleteAsync( |
||||
|
x => x.SubjectId == subjectId && x.ClientId == clientId, |
||||
|
cancellationToken: GetCancellationToken(cancellationToken) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
await DeleteAsync( |
||||
|
x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, |
||||
|
cancellationToken: GetCancellationToken(cancellationToken) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class ApiResourceRepository_Tests //: ApiResourceRepository_Tests<AbpIdentityServerTestEntityFrameworkCoreModule>
|
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.MongoDB.Tests</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.MongoDB.Tests</PackageId> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.MongoDB\Volo.Abp.IdentityServer.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.IdentityServer.TestBase\Volo.Abp.IdentityServer.TestBase.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
||||
|
<PackageReference Include="Mongo2Go" Version="2.2.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,33 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Mongo2Go; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.IdentityServer.MongoDB; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpIdentityServerTestBaseModule), |
||||
|
typeof(AbpIdentityServerMongoDbModule) |
||||
|
)] |
||||
|
public class AbpIdentityServerMongoDbTestModule : AbpModule |
||||
|
{ |
||||
|
private MongoDbRunner _mongoDbRunner; |
||||
|
|
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
_mongoDbRunner = MongoDbRunner.Start(); |
||||
|
|
||||
|
context.Services.Configure<DbConnectionOptions>(options => |
||||
|
{ |
||||
|
options.ConnectionStrings.Default = _mongoDbRunner.ConnectionString; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
||||
|
{ |
||||
|
_mongoDbRunner.Dispose(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class ApiResourceRepository_Tests : ApiResourceRepository_Tests<AbpIdentityServerMongoDbTestModule> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class ClientRepository_Tests : ClientRepository_Tests<AbpIdentityServerMongoDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests<AbpIdentityServerMongoDbTestModule> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.TestBase</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.TestBase</PackageId> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
||||
|
<PackageReference Include="NSubstitute" Version="3.1.0" /> |
||||
|
<PackageReference Include="Shouldly" Version="3.0.0" /> |
||||
|
<PackageReference Include="xunit" Version="2.3.1" /> |
||||
|
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" /> |
||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class AbpIdentityServerTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpAutofacModule), |
||||
|
typeof(AbpTestBaseModule), |
||||
|
typeof(AbpIdentityServerDomainModule) |
||||
|
)] |
||||
|
public class AbpIdentityServerTestBaseModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddAlwaysAllowPermissionChecker(); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
SeedTestData(context); |
||||
|
} |
||||
|
|
||||
|
private static void SeedTestData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
using (var scope = context.ServiceProvider.CreateScope()) |
||||
|
{ |
||||
|
//var dataSeeder = scope.ServiceProvider.GetRequiredService<IIdentityServerDataSeeder>();
|
||||
|
//AsyncHelper.RunSync(() => dataSeeder.SeedAsync("1q2w3E*"));
|
||||
|
|
||||
|
scope.ServiceProvider |
||||
|
.GetRequiredService<AbpIdentityServerTestDataBuilder>() |
||||
|
.Build(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Guids; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class AbpIdentityServerTestDataBuilder : ITransientDependency |
||||
|
{ |
||||
|
private readonly IGuidGenerator _guidGenerator; |
||||
|
private readonly IApiResourceRepository _apiResourceRepository; |
||||
|
private readonly IClientRepository _clientRepository; |
||||
|
private readonly IIdentityResourceRepository _identityResourceRepository; |
||||
|
//private readonly IPersistentGrantRepository _persistentGrantRepository;
|
||||
|
|
||||
|
public AbpIdentityServerTestDataBuilder( |
||||
|
IGuidGenerator guidGenerator, |
||||
|
IApiResourceRepository apiResourceRepository, |
||||
|
IClientRepository clientRepository, |
||||
|
IIdentityResourceRepository identityResourceRepository |
||||
|
/*IPersistentGrantRepository persistentGrantRepository*/) |
||||
|
{ |
||||
|
_guidGenerator = guidGenerator; |
||||
|
_apiResourceRepository = apiResourceRepository; |
||||
|
_clientRepository = clientRepository; |
||||
|
_identityResourceRepository = identityResourceRepository; |
||||
|
//_persistentGrantRepository = persistentGrantRepository;
|
||||
|
} |
||||
|
|
||||
|
public void Build() |
||||
|
{ |
||||
|
AddPersistedGrants(); |
||||
|
AddIdentityResources(); |
||||
|
AddApiResources(); |
||||
|
AddClients(); |
||||
|
} |
||||
|
|
||||
|
private void AddPersistedGrants() |
||||
|
{ |
||||
|
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
|
||||
|
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
|
||||
|
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
|
||||
|
} |
||||
|
|
||||
|
private void AddIdentityResources() |
||||
|
{ |
||||
|
_identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource1")); |
||||
|
_identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); |
||||
|
_identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); |
||||
|
} |
||||
|
|
||||
|
private void AddApiResources() |
||||
|
{ |
||||
|
_apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource1")); |
||||
|
_apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); |
||||
|
_apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); |
||||
|
} |
||||
|
|
||||
|
private void AddClients() |
||||
|
{ |
||||
|
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId1")); |
||||
|
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); |
||||
|
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public abstract class ApiResourceRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected IApiResourceRepository apiResourceRepository { get; } |
||||
|
|
||||
|
public ApiResourceRepository_Tests() |
||||
|
{ |
||||
|
apiResourceRepository = ServiceProvider.GetRequiredService<IApiResourceRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task FindByNormalizedNameAsync() |
||||
|
{ |
||||
|
(await apiResourceRepository.FindByNameAsync("NewApiResource2")).ShouldNotBeNull(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetListByScopesAsync() |
||||
|
{ |
||||
|
(await apiResourceRepository.GetListByScopesAsync(new []{ "NewApiResource2", "NewApiResource3"})).Count.ShouldBe(2); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public abstract class ClientRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected IClientRepository clientRepository { get; } |
||||
|
|
||||
|
public ClientRepository_Tests() |
||||
|
{ |
||||
|
clientRepository = ServiceProvider.GetRequiredService<IClientRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task FindByCliendIdAsync() |
||||
|
{ |
||||
|
(await clientRepository.FindByCliendIdAsync("ClientId2")).ShouldNotBeNull(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class IdentityResourceRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
private IIdentityResourceRepository identityResourceRepository; |
||||
|
public IdentityResourceRepository_Tests() |
||||
|
{ |
||||
|
identityResourceRepository = ServiceProvider.GetRequiredService<IIdentityResourceRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetListByScopesAsync() |
||||
|
{ |
||||
|
(await identityResourceRepository.GetListByScopesAsync(new []{"", "NewIdentityResource2" })).Count.ShouldBe(1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue