Skip to content

Commit

Permalink
Merge pull request stratisproject#261 from fassadlr/merge-master
Browse files Browse the repository at this point in the history
Merge master to private data
  • Loading branch information
codingupastorm authored Mar 20, 2020
2 parents 6123bbd + e13e05a commit 1a2b9d0
Show file tree
Hide file tree
Showing 207 changed files with 808 additions and 12,264 deletions.
7 changes: 3 additions & 4 deletions src/CertificateAuthority.API/CertificateAuthority.API.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<AspNetCoreModuleName>AspNetCoreModuleV2</AspNetCoreModuleName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.12" />
<PackageReference Include="Microsoft.OpenApi" Version="1.1.1" />
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" />
<PackageReference Include="NLog" Version="4.6.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 10 additions & 3 deletions src/CertificateAuthority.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.OpenApi.Models;

namespace CertificateAuthority.API
{
Expand All @@ -29,7 +29,7 @@ public virtual void ConfigureServices(IServiceCollection services)
.AddApplicationPart(typeof(HelpersController).GetTypeInfo().Assembly);

services.AddSwaggerGen(c =>
c.SwaggerDoc("v1", new Info { Title = "Stratis Certificate Authority API V1", Version = "v1" }
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Stratis Certificate Authority API V1", Version = "v1" }
));

services.AddSingleton<DataCacheLayer>();
Expand All @@ -42,6 +42,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.ApplicationServices.GetService<DataCacheLayer>().Initialize();
app.ApplicationServices.GetService<CaCertificatesManager>().Initialize();

app.UseRouting();

// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();

Expand All @@ -55,7 +57,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseHsts();

app.UseHttpsRedirection();
app.UseMvc();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapDefaultControllerRoute();
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -11,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CertificateAuthority.Controllers;
using CertificateAuthority.Database;
using CertificateAuthority.Models;
Expand Down Expand Up @@ -295,7 +294,7 @@ public void CanIssueCertificateViaTemplateCsr()
}

[Fact]
public async Task CantRequestCertificateTwiceForSameIdentityAndCanReset()
public void CantRequestCertificateTwiceForSameIdentityAndCanReset()
{
CredentialsModel credentials1 = this.GetPrivilegedAccount();

Expand Down Expand Up @@ -459,41 +458,5 @@ private void Returns403IfNoAccess(Func<int, string, object> action, AccountAcces
break;
}
}

private void CheckThrowsIfNoAccess(Action<int, string> action, AccountAccessFlags requiredAccess)
{
CredentialsModel noAccessCredentials = CaTestHelper.CreateAccount(this.server.Host);
bool throwsIfNoAccess = false;

try
{
action.Invoke(noAccessCredentials.AccountId, noAccessCredentials.Password);
}
catch (InvalidCredentialsException e)
{
Assert.Equal(CredentialsExceptionErrorCodes.InvalidAccess, e.ErrorCode);
throwsIfNoAccess = true;
}
catch (Exception e)
{
}

if (!throwsIfNoAccess)
Assert.False(true, "Action was expected to throw.");

CredentialsModel accessCredentials = CaTestHelper.CreateAccount(this.server.Host, requiredAccess);

try
{
action.Invoke(accessCredentials.AccountId, accessCredentials.Password);
}
catch (InvalidCredentialsException e)
{
Assert.False(true, "Action was expected to not throw or throw different exception.");
}
catch (Exception)
{
}
}
}
}
3 changes: 1 addition & 2 deletions src/NBitcoin.Tests/NBitcoin.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Stratis.Bitcoin.Api.Tests</AssemblyName>
<PackageId>Stratis.Bitcoin.Api.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Stratis.Bitcoin.Features.Api/ConfigureSwaggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.PlatformAbstractions;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Stratis.Bitcoin.Features.Api
Expand Down Expand Up @@ -58,9 +58,9 @@ public void Configure(SwaggerGenOptions options)
options.DescribeAllEnumsAsStrings();
}

static Info CreateInfoForApiVersion(ApiVersionDescription description)
static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description)
{
var info = new Info()
var info = new OpenApiInfo()
{
Title = "Stratis Node API",
Version = description.ApiVersion.ToString(),
Expand Down
13 changes: 7 additions & 6 deletions src/Stratis.Bitcoin.Features.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static IWebHost Initialize(IEnumerable<ServiceDescriptor> services, FullN

Uri apiUri = apiSettings.ApiUri;

X509Certificate2 certificate = apiSettings.UseHttps
? GetHttpsCertificate(apiSettings.HttpsCertificateFilePath, store)
X509Certificate2 certificate = apiSettings.UseHttps
? GetHttpsCertificate(apiSettings.HttpsCertificateFilePath, store)
: null;

webHostBuilder
Expand All @@ -30,9 +30,10 @@ public static IWebHost Initialize(IEnumerable<ServiceDescriptor> services, FullN
if (!apiSettings.UseHttps)
return;

Action<ListenOptions> configureListener = listenOptions => { listenOptions.UseHttps(certificate); };
var ipAddresses = Dns.GetHostAddresses(apiSettings.ApiUri.DnsSafeHost);
foreach (var ipAddress in ipAddresses)
options.AllowSynchronousIO = true;
void configureListener(ListenOptions listenOptions) { listenOptions.UseHttps(certificate); }
IPAddress[] ipAddresses = Dns.GetHostAddresses(apiSettings.ApiUri.DnsSafeHost);
foreach (IPAddress ipAddress in ipAddresses)
{
options.Listen(ipAddress, apiSettings.ApiPort, configureListener);
}
Expand Down Expand Up @@ -72,7 +73,7 @@ public static IWebHost Initialize(IEnumerable<ServiceDescriptor> services, FullN
.UseStartup<Startup>();

IWebHost host = webHostBuilder.Build();

host.Start();

return host;
Expand Down
43 changes: 23 additions & 20 deletions src/Stratis.Bitcoin.Features.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Stratis.Bitcoin.Builder.Feature;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;

namespace Stratis.Bitcoin.Features.Api
{
public class Startup
{
public Startup(IHostingEnvironment env, IFullNode fullNode, ApiFeatureOptions apiFeatureOptions)
public Startup(IWebHostEnvironment env, IFullNode fullNode)
{
this.fullNode = fullNode;
this.apiFeatureOptions = apiFeatureOptions;

IConfigurationBuilder builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
Expand All @@ -30,13 +27,20 @@ public Startup(IHostingEnvironment env, IFullNode fullNode, ApiFeatureOptions ap
}

private readonly IFullNode fullNode;
private readonly ApiFeatureOptions apiFeatureOptions;

public IConfigurationRoot Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(
loggingBuilder =>
{
loggingBuilder.AddConfiguration(this.Configuration.GetSection("Logging"));
loggingBuilder.AddConsole();
loggingBuilder.AddDebug();
});

// Add service and create Policy to allow Cross-Origin Requests
services.AddCors
(
Expand All @@ -59,13 +63,9 @@ public void ConfigureServices(IServiceCollection services)
);
});

// Filters api features based on options provide.
IEnumerable<IFullNodeFeature> features = this.apiFeatureOptions.Includes.Any()
? this.fullNode.Services.Features.Where(feature => this.apiFeatureOptions.Includes.Contains(feature.GetType()))
: this.fullNode.Services.Features.Where(feature => !this.apiFeatureOptions.Excludes.Contains(feature.GetType()));

// Add framework services.
services.AddMvc(options =>
services
.AddMvc(options =>
{
options.Filters.Add(typeof(LoggingActionFilter));

Expand All @@ -76,9 +76,9 @@ public void ConfigureServices(IServiceCollection services)
options.Filters.Add(typeof(KeepaliveActionFilter));
}
})
// Add serializers for NBitcoin objects.
.AddJsonOptions(options => Utilities.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings))
.AddControllers(features, services);
// add serializers for NBitcoin objects
.AddNewtonsoftJson(options => Utilities.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings))
.AddControllers(this.fullNode.Services.Features, services);

// Enable API versioning.
// Note much of this is borrowed from https://github.com/microsoft/aspnet-api-versioning/blob/master/samples/aspnetcore/SwaggerSample/Startup.cs
Expand Down Expand Up @@ -110,17 +110,20 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider)
{
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseStaticFiles();
app.UseRouting();

app.UseCors("CorsPolicy");

// Register this before MVC and Swagger.
app.UseMiddleware<NoCacheMiddleware>();

app.UseMvc();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});

// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>Stratis.Bitcoin.Features.Api</AssemblyName>
<OutputType>Library</OutputType>
Expand All @@ -23,13 +23,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.12" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="3.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="System.Reactive" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="Tracer.Fody" Version="3.1.0" />
<PackageReference Include="Tracer.Fody" Version="3.2.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 1a2b9d0

Please sign in to comment.