This commit is contained in:
Adam Szczepanski 2021-11-09 08:25:50 +00:00
Родитель a2900cb2c5
Коммит 6bbd3f7a91
17 изменённых файлов: 105 добавлений и 104 удалений

Просмотреть файл

@ -7,18 +7,18 @@
<Microsoft_AspNetCore_Http_Abstractions_Version>2.2.0</Microsoft_AspNetCore_Http_Abstractions_Version>
<Microsoft_AspNetCore_Http_Version>2.2.2</Microsoft_AspNetCore_Http_Version>
<Microsoft_Azure_DocumentDB_Version>2.16.2</Microsoft_Azure_DocumentDB_Version>
<Microsoft_CodeAnalysis_Common>3.9.0</Microsoft_CodeAnalysis_Common>
<Microsoft_CodeAnalysis_Csharp>3.9.0</Microsoft_CodeAnalysis_Csharp>
<Microsoft_CodeAnalysis_Common>3.11.0</Microsoft_CodeAnalysis_Common>
<Microsoft_CodeAnalysis_Csharp>3.11.0</Microsoft_CodeAnalysis_Csharp>
<Microsoft_Net_Test_Sdk_Version>17.0.0</Microsoft_Net_Test_Sdk_Version>
<Microsoft_SourceLink_GitHub_Version>1.0.0</Microsoft_SourceLink_GitHub_Version>
<Microsoft_SourceLink_AzureRepos_Git_Version>1.0.0</Microsoft_SourceLink_AzureRepos_Git_Version>
<MSTest_TestAdapter_Version>2.2.7</MSTest_TestAdapter_Version>
<MSTest_TestFramework_Version>2.2.7</MSTest_TestFramework_Version>
<System_Configuration_ConfigurationManager_Version>5.0.0</System_Configuration_ConfigurationManager_Version>
<System_ServiceModel_Primitives_Version>4.8.1</System_ServiceModel_Primitives_Version>
<System_Text_Encodings_Web_Version>5.0.1</System_Text_Encodings_Web_Version>
<System_Configuration_ConfigurationManager_Version>6.0.0</System_Configuration_ConfigurationManager_Version>
<System_ServiceModel_Primitives_Version>4.9.0</System_ServiceModel_Primitives_Version>
<System_Text_Encodings_Web_Version>6.0.0</System_Text_Encodings_Web_Version>
<System_Threading_Tasks_Version>4.3.0</System_Threading_Tasks_Version>
<System_Text_Json_Version>5.0.2</System_Text_Json_Version>
<System_Text_Json_Version>6.0.0</System_Text_Json_Version>
<System_ComponentModel_Annotations>5.0.0</System_ComponentModel_Annotations>
<Xunit_Runner_VisualStudio_Version>2.4.3</Xunit_Runner_VisualStudio_Version>
</PropertyGroup>
@ -28,21 +28,20 @@
<Xunit_Core_Version>2.4.1</Xunit_Core_Version>
</PropertyGroup>
<PropertyGroup Label="Packages for Omex Extensions. AutoUpdate">
<Microsoft_Extensions_DependencyInjection_Version>5.0.2</Microsoft_Extensions_DependencyInjection_Version>
<Microsoft_Extensions_DependencyInjection_Abstractions_Version>5.0.0</Microsoft_Extensions_DependencyInjection_Abstractions_Version>
<Microsoft_Extensions_Diagnostics_HealthChecks_Version>5.0.11</Microsoft_Extensions_Diagnostics_HealthChecks_Version>
<Microsoft_Extensions_Hosting_Version>5.0.0</Microsoft_Extensions_Hosting_Version>
<Microsoft_Extensions_Hosting_Abstractions_Version>5.0.0</Microsoft_Extensions_Hosting_Abstractions_Version>
<Microsoft_Extensions_Http_Version>5.0.0</Microsoft_Extensions_Http_Version>
<Microsoft_Extensions_Logging_Version>5.0.0</Microsoft_Extensions_Logging_Version>
<Microsoft_Extensions_Logging_Abstractions_Version>5.0.0</Microsoft_Extensions_Logging_Abstractions_Version>
<Microsoft_Extensions_Logging_Console_Version>5.0.0</Microsoft_Extensions_Logging_Console_Version>
<Microsoft_Extensions_ObjectPool_Version>5.0.11</Microsoft_Extensions_ObjectPool_Version>
<Microsoft_Extensions_Options_ConfigurationExtensions_Version>5.0.0</Microsoft_Extensions_Options_ConfigurationExtensions_Version>
<Microsoft_Extensions_Options_Version>5.0.0</Microsoft_Extensions_Options_Version>
<System_Diagnostics_DiagnosticSource_Version>5.0.1</System_Diagnostics_DiagnosticSource_Version>
<Microsoft_Extensions_DependencyInjection_Version>6.0.0</Microsoft_Extensions_DependencyInjection_Version>
<Microsoft_Extensions_DependencyInjection_Abstractions_Version>6.0.0</Microsoft_Extensions_DependencyInjection_Abstractions_Version>
<Microsoft_Extensions_Diagnostics_HealthChecks_Version>6.0.0</Microsoft_Extensions_Diagnostics_HealthChecks_Version>
<Microsoft_Extensions_Hosting_Version>6.0.0</Microsoft_Extensions_Hosting_Version>
<Microsoft_Extensions_Hosting_Abstractions_Version>6.0.0</Microsoft_Extensions_Hosting_Abstractions_Version>
<Microsoft_Extensions_Http_Version>6.0.0</Microsoft_Extensions_Http_Version>
<Microsoft_Extensions_Logging_Version>6.0.0</Microsoft_Extensions_Logging_Version>
<Microsoft_Extensions_Logging_Abstractions_Version>6.0.0</Microsoft_Extensions_Logging_Abstractions_Version>
<Microsoft_Extensions_Logging_Console_Version>6.0.0</Microsoft_Extensions_Logging_Console_Version>
<Microsoft_Extensions_ObjectPool_Version>6.0.0</Microsoft_Extensions_ObjectPool_Version>
<Microsoft_Extensions_Options_ConfigurationExtensions_Version>6.0.0</Microsoft_Extensions_Options_ConfigurationExtensions_Version>
<Microsoft_Extensions_Options_Version>6.0.0</Microsoft_Extensions_Options_Version>
<System_Diagnostics_DiagnosticSource_Version>6.0.0</System_Diagnostics_DiagnosticSource_Version>
<System_Threading_Tasks_Extensions_Version>4.5.4</System_Threading_Tasks_Extensions_Version>
<System_Diagnostics_DiagnosticSource_Version>6.0.0-rc.2.21480.5</System_Diagnostics_DiagnosticSource_Version>
</PropertyGroup>
<PropertyGroup Label="ServiceFabric packages for Omex Extensions">
<Microsoft_ServiceFabric_Version>8.2.1235</Microsoft_ServiceFabric_Version>

Просмотреть файл

@ -1,7 +1,7 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)\Dependencies.props" />
<PropertyGroup Label="Target Platforms" >
<NetCoreVersions>net5.0</NetCoreVersions>
<NetCoreVersions>net5.0;net6.0</NetCoreVersions>
<NetStandardVersions>netstandard2.0</NetStandardVersions>
<LibraryTargetFrameworks>$(NetCoreVersions);$(NetStandardVersions)</LibraryTargetFrameworks>
<ExecutableTargetFrameworks>$(NetCoreVersions)</ExecutableTargetFrameworks>

Просмотреть файл

@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.402",
"version": "6.0.100",
"rollForward": "latestMajor"
}
}

Просмотреть файл

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Contains Omex Gating generator code</Description>
<RootNamespace>Microsoft.Omex.CodeGenerators.GateGen</RootNamespace>
<AssemblyName>Microsoft.Omex.CodeGenerators.GateGen</AssemblyName>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<!--
<SettingsFile>$(SolutionDir)\src\CodeGenerators\SettingsGen.Example\Settings.xml</SettingsFile>
<GenerateSettingsFile>True</GenerateSettingsFile> -->

Просмотреть файл

@ -99,7 +99,7 @@ namespace Microsoft.Omex.CodeGenerators.SettingsGen
/// </summary>
protected static readonly DiagnosticDescriptor WritingToFile = new(id: "SETTINGSGEN001",
title: "Writing to settings file",
messageFormat: "Writing to file '{0}'.",
messageFormat: "Writing to file '{0}'",
category: "SettingsGenerator",
DiagnosticSeverity.Info,
isEnabledByDefault: true);
@ -109,7 +109,7 @@ namespace Microsoft.Omex.CodeGenerators.SettingsGen
/// </summary>
protected static readonly DiagnosticDescriptor DontGen = new(id: "SETTINGSGEN002",
title: "Not generating",
messageFormat: "Not generating/updating settings file.",
messageFormat: "Not generating/updating settings file",
category: "SettingsGenerator",
DiagnosticSeverity.Info,
isEnabledByDefault: true);

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.Omex.Extensions.Compatibility.UlsLoggerAdapter
/// </summary>
internal class UlsLogAddapter : IHostedService
{
private static readonly Func<string, Exception, string> s_formatter = (message, exception) => message; // emulating behavior of standard formatter to avoid duplicating exception stack trace
private static readonly Func<string, Exception?, string> s_formatter = (message, exception) => message; // emulating behavior of standard formatter to avoid duplicating exception stack trace
private readonly ILoggerFactory m_loggerFactory;
private readonly ConcurrentDictionary<string, ILogger> m_loggersDictionary;

Просмотреть файл

@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Builder
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = "application/json";
IExceptionHandlerFeature contextFeature = context.Features.Get<IExceptionHandlerFeature>();
IExceptionHandlerFeature? contextFeature = context.Features.Get<IExceptionHandlerFeature>();
Dictionary<string, string> errorDict = new Dictionary<string, string>
{

Просмотреть файл

@ -29,7 +29,7 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web
public Task<string> OpenAsync(CancellationToken cancellationToken)
{
// Listener already opened so just returning listener uri
string? address = m_server.Features.Get<IServerAddressesFeature>()
string? address = m_server.Features.Get<IServerAddressesFeature>()?
.Addresses.FirstOrDefault(a => a.Contains(":" + m_port));
if (address == null)

Просмотреть файл

@ -16,8 +16,8 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.Middlewares
public Task<(bool success, int bytesWritten)> TryWriteBytesAsync(HttpContext context, Memory<byte> memory)
{
int bytesWritten = -1;
IHttpConnectionFeature connection = context.Features.Get<IHttpConnectionFeature>();
IPAddress? remoteIpAddress = connection.RemoteIpAddress;
IHttpConnectionFeature? connection = context.Features.Get<IHttpConnectionFeature>();
IPAddress? remoteIpAddress = connection?.RemoteIpAddress;
return Task.FromResult((remoteIpAddress != null
&& remoteIpAddress.TryWriteBytes(memory.Span.Slice(0, MaxBytesInIdentity), out bytesWritten), bytesWritten));

Просмотреть файл

@ -18,7 +18,6 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.Middlewares
{
private const int SaltLength = 48; // currently recommended salt size 32
private const int HoursToKeepSalt = 40; // should not be more then 48 hours
private readonly RandomNumberGenerator m_random;
private readonly IMemoryOwner<byte> m_currentSaltMemory;
private readonly ISystemClock m_systemClock;
private readonly ILogger<RotatingSaltProvider> m_logger;
@ -27,7 +26,6 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.Middlewares
public RotatingSaltProvider(ISystemClock systemClock, ILogger<RotatingSaltProvider> logger)
{
m_random = new RNGCryptoServiceProvider();
m_currentSaltMemory = MemoryPool<byte>.Shared.Rent(SaltLength);
m_saltGenerationTime = DateTime.MinValue;
m_systemClock = systemClock;
@ -59,14 +57,13 @@ namespace Microsoft.Omex.Extensions.Hosting.Services.Web.Middlewares
public void Dispose()
{
m_currentSaltMemory.Dispose();
m_random.Dispose();
}
private bool IsSaltOutdated(DateTimeOffset currentTime) => (currentTime - m_saltGenerationTime).TotalHours > HoursToKeepSalt;
private void RotateSalt(Span<byte> saltSpan, DateTimeOffset currentTime)
{
m_random.GetNonZeroBytes(saltSpan);
RandomNumberGenerator.Fill(saltSpan);
m_saltGenerationTime = currentTime;
// DO NOT ADD THE SALT TO THIS LOG STATEMENT. Doing so may violate compliance guarantees.

Просмотреть файл

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

Просмотреть файл

@ -32,7 +32,11 @@ namespace Microsoft.Omex.System.Data
Contents = Code.ExpectsArgument(contents, nameof(contents), TaggingUtilities.ReserveTag(0x238208d1 /* tag_9669r */));
#if NET6_0_OR_GREATER
SHA256Hash = Convert.ToBase64String(SHA256.HashData(contents));
#else
SHA256Hash = contents.GetHash<SHA256CryptoServiceProvider>();
#endif
}
/// <summary>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="$(Moq_Version)" />

Просмотреть файл

@ -105,7 +105,7 @@ namespace Hosting.Services.UnitTests
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) =>
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) =>
Messages.Add((eventId, logLevel, formatter(state, exception)));
}
}

Просмотреть файл

@ -86,13 +86,13 @@ namespace Hosting.Services.UnitTests
private class MockLogger : ILogger<DiagnosticsObserversInitializer>
{
public List<Exception> Exceptions { get; } = new();
public List<Exception?> Exceptions { get; } = new();
public IDisposable BeginScope<TState>(TState state) => throw new NotImplementedException();
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) => Exceptions.Add(exception);
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) => Exceptions.Add(exception);
}
}
}

Просмотреть файл

@ -1,65 +1,66 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Hosting.Services.Web.UnitTests;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Hosting.Services.Web.UnitTests;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Omex.Extensions.Abstractions.UnitTests;
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Omex.Extensions.Hosting.Services.Web.UnitTests.Internal
{
[TestClass]
public class HostBuilderExtensionsTests
{
[TestMethod]
public void BuildStatelessWebService_UseUniqueServiceUrl_Failing()
{
Assert.ThrowsException<ArgumentException>(() =>
{
new HostBuilder().BuildStatelessWebService<MockStartup>(
"someService1",
new WebEndpointInfo[0],
ServiceFabricIntegrationOptions.UseUniqueServiceUrl | ServiceFabricIntegrationOptions.UseReverseProxyIntegration);
});
}
[TestMethod]
public async Task BuildStatelessWebService_RegisterListeners()
{
(string name, int port) httpListener1 = ("httpListener", 20080);
(string name, int port) httpListener2 = ("httpsListener", 20443);
SfConfigurationProviderHelper.SetPublishAddress();
SfConfigurationProviderHelper.SetPortVariable(httpListener1.name, httpListener1.port);
SfConfigurationProviderHelper.SetPortVariable(httpListener2.name, httpListener2.port);
IHost host = new HostBuilder().BuildStatelessWebService<MockStartup>(
"someService2",
new WebEndpointInfo[]
{
new WebEndpointInfo(httpListener1.name, settingForCertificateCommonName: null),
new WebEndpointInfo(httpListener2.name, settingForCertificateCommonName: null)
});
IListenerBuilder<OmexStatelessService>[] builders = host.Services.GetRequiredService<IEnumerable<IListenerBuilder<OmexStatelessService>>>().ToArray();
Assert.AreEqual(2, builders.Length, "Two endpoints should be registered as listeners");
Assert.IsTrue(builders.Any(b => b.Name == httpListener1.name), $"Listener builder for {httpListener1.name} not found");
Assert.IsTrue(builders.Any(b => b.Name == httpListener2.name), $"Listener builder for {httpListener2.name} not found");
await host.StartAsync();
ICollection<string> addresses = host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses;
Assert.AreEqual(2, builders.Length, "Two addresses should be registered");
Assert.IsTrue(addresses.Any(address => address.EndsWith($":{httpListener1.port}")), $"Address for {httpListener1.name} not found");
Assert.IsTrue(addresses.Any(address => address.EndsWith($":{httpListener2.port}")), $"Address for {httpListener2.name} not found");
}
}
}
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Omex.Extensions.Hosting.Services.Web.UnitTests.Internal
{
[TestClass]
public class HostBuilderExtensionsTests
{
[TestMethod]
public void BuildStatelessWebService_UseUniqueServiceUrl_Failing()
{
Assert.ThrowsException<ArgumentException>(() =>
{
new HostBuilder().BuildStatelessWebService<MockStartup>(
"someService1",
new WebEndpointInfo[0],
ServiceFabricIntegrationOptions.UseUniqueServiceUrl | ServiceFabricIntegrationOptions.UseReverseProxyIntegration);
});
}
[TestMethod]
public async Task BuildStatelessWebService_RegisterListeners()
{
(string name, int port) httpListener1 = ("httpListener", 20080);
(string name, int port) httpListener2 = ("httpsListener", 20443);
SfConfigurationProviderHelper.SetPublishAddress();
SfConfigurationProviderHelper.SetPortVariable(httpListener1.name, httpListener1.port);
SfConfigurationProviderHelper.SetPortVariable(httpListener2.name, httpListener2.port);
IHost host = new HostBuilder().BuildStatelessWebService<MockStartup>(
"someService2",
new WebEndpointInfo[]
{
new WebEndpointInfo(httpListener1.name, settingForCertificateCommonName: null),
new WebEndpointInfo(httpListener2.name, settingForCertificateCommonName: null)
});
IListenerBuilder<OmexStatelessService>[] builders = host.Services.GetRequiredService<IEnumerable<IListenerBuilder<OmexStatelessService>>>().ToArray();
Assert.AreEqual(2, builders.Length, "Two endpoints should be registered as listeners");
Assert.IsTrue(builders.Any(b => b.Name == httpListener1.name), $"Listener builder for {httpListener1.name} not found");
Assert.IsTrue(builders.Any(b => b.Name == httpListener2.name), $"Listener builder for {httpListener2.name} not found");
await host.StartAsync();
ICollection<string>? addresses = host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>()?.Addresses;
Assert.AreEqual(2, builders.Length, "Two addresses should be registered");
Assert.IsNotNull(addresses, "Addresses should be registered");
Assert.IsTrue(addresses.Any(address => address.EndsWith($":{httpListener1.port}")), $"Address for {httpListener1.name} not found");
Assert.IsTrue(addresses.Any(address => address.EndsWith($":{httpListener2.port}")), $"Address for {httpListener2.name} not found");
}
}
}