Merge pull request #13079 from aspnet/halter73/13020

Throw NotSupportedException given FileHandleEndPoint
This commit is contained in:
Stephen Halter 2019-08-15 14:58:49 -07:00 committed by GitHub
commit 72925ecc19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -62,6 +62,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
throw new InvalidOperationException(SocketsStrings.TransportAlreadyBound); throw new InvalidOperationException(SocketsStrings.TransportAlreadyBound);
} }
// Check if EndPoint is a FileHandleEndpoint before attempting to access EndPoint.AddressFamily
// since that will throw an NotImplementedException.
if (EndPoint is FileHandleEndPoint)
{
throw new NotSupportedException(SocketsStrings.FileHandleEndPointNotSupported);
}
Socket listenSocket; Socket listenSocket;
// Unix domain sockets are unspecified // Unix domain sockets are unspecified

View File

@ -117,10 +117,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="FileHandleEndPointNotSupported" xml:space="preserve">
<value>The Socket transport does not support binding to file handles. Consider using the libuv transport instead.</value>
</data>
<data name="OnlyIPEndPointsSupported" xml:space="preserve"> <data name="OnlyIPEndPointsSupported" xml:space="preserve">
<value>Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850</value> <value>Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850</value>
</data> </data>
<data name="TransportAlreadyBound" xml:space="preserve"> <data name="TransportAlreadyBound" xml:space="preserve">
<value>Transport is already bound.</value> <value>Transport is already bound.</value>
</data> </data>
</root> </root>

View File

@ -0,0 +1,25 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
namespace Sockets.BindTests
{
public class SocketTransportFactoryTests
{
[Fact]
public async Task ThrowsNotSupportedExceptionWhenBindingToFileHandleEndPoint()
{
var socketTransportFactory = new SocketTransportFactory(Options.Create(new SocketTransportOptions()), Mock.Of<ILoggerFactory>());
await Assert.ThrowsAsync<NotSupportedException>(async () => await socketTransportFactory.BindAsync(new FileHandleEndPoint(0, FileHandleType.Auto)));
}
}
}