Skip to content

Update last few projects to target netcoreapp3.0 #5128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP3_0
// Rfc2898DeriveBytes in .NET Standard 2.0 only supports SHA1

using System;
using System.Diagnostics;
using System.Security.Cryptography;
Expand Down Expand Up @@ -64,8 +61,3 @@ private static byte[] DeriveKeyImpl(string password, byte[] salt, KeyDerivationP
}
}
}

#elif NETSTANDARD2_0
#else
#error Update target frameworks
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,12 @@ private static IPbkdf2Provider GetPbkdf2Provider()
// acceptable implementation
return new Win7Pbkdf2Provider();
}
#if NETCOREAPP3_0
else
{
// fastest implementation on .NET Core for Linux/macOS.
// Not supported on .NET Framework
return new NetCorePbkdf2Provider();
}
#elif NETSTANDARD2_0
else
{
// slowest implementation
return new ManagedPbkdf2Provider();
}
#else
#error Update target frameworks
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation
{
public class Pbkdf2Tests
{

#if NET461
#elif NETCOREAPP3_0
// The 'numBytesRequested' parameters below are chosen to exercise code paths where
// this value straddles the digest length of the PRF. We only use 5 iterations so
// that our unit tests are fast.
Expand Down Expand Up @@ -60,9 +57,6 @@ public void RunTest_WithLongPassword_NetCore()
var salt = Encoding.UTF8.GetBytes("abcdefghijkl");
RunTest_WithLongPassword_Impl<NetCorePbkdf2Provider>(salt, "NGJtFzYUaaSxu+3ZsMeZO5d/qPJDUYW4caLkFlaY0cLSYdh1PN4+nHUVp4pUUubJWu3UeXNMnHKNDfnn8GMfnDVrAGTv1lldszsvUJ0JQ6p4+daQEYBc//Tj/ejuB3luwW0IinyE7U/ViOQKbfi5pCZFMQ0FFx9I+eXRlyT+I74=");
}
#else
#error Update target framework
#endif

// The 'numBytesRequested' parameters below are chosen to exercise code paths where
// this value straddles the digest length of the PRF. We only use 5 iterations so
Expand Down
92 changes: 0 additions & 92 deletions src/DataProtection/DataProtection/test/AnonymousImpersonation.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,7 @@ public void CreateInstance_DoesNotForwardingTypesExternalTypes(Type type)
[MemberData(nameof(AssemblyVersions))]
public void CreateInstance_ForwardsAcrossVersionChanges(Version version)
{
#if NET461
// run this test in an appdomain without testhost's custom assembly resolution hooks
var setupInfo = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
};
var domain = AppDomain.CreateDomain("TestDomain", null, setupInfo);
var wrappedTestClass = (TypeForwardingActivatorTests)domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(TypeForwardingActivatorTests).FullName);
wrappedTestClass.CreateInstance_ForwardsAcrossVersionChangesImpl(version);
#elif NETCOREAPP3_0
CreateInstance_ForwardsAcrossVersionChangesImpl(version);
#else
#error Target framework should be updated
#endif
}

private void CreateInstance_ForwardsAcrossVersionChangesImpl(Version newVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,5 @@ public void Encrypt_CurrentUserOrLocalMachine_Decrypt_RoundTrips(bool protectToL
var roundTrippedElement = decryptor.Decrypt(encryptedXmlInfo.EncryptedElement);
XmlAssert.Equal(originalXml, roundTrippedElement);
}

#if NET461
[ConditionalFact]
[ConditionalRunTestOnlyOnWindows]
public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails()
{
// Arrange
var originalXml = XElement.Parse(@"<mySecret value='265ee4ea-ade2-43b1-b706-09b259e58b6b' />");
var encryptor = new DpapiXmlEncryptor(protectToLocalMachine: false, loggerFactory: NullLoggerFactory.Instance);
var decryptor = new DpapiXmlDecryptor();

// Act & assert - run through encryptor and make sure we get back an obfuscated element
var encryptedXmlInfo = encryptor.Encrypt(originalXml);
Assert.Equal(typeof(DpapiXmlDecryptor), encryptedXmlInfo.DecryptorType);
Assert.DoesNotContain("265ee4ea-ade2-43b1-b706-09b259e58b6b", encryptedXmlInfo.EncryptedElement.ToString(), StringComparison.OrdinalIgnoreCase);

// Act & assert - run through decryptor (while impersonated as anonymous) and verify failure
ExceptionAssert2.ThrowsCryptographicException(() =>
AnonymousImpersonation.Run(() => decryptor.Decrypt(encryptedXmlInfo.EncryptedElement)));
}
#elif NETCOREAPP3_0
#else
#error Target framework needs to be updated
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>ASP.NET Core support for JSON PATCH.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;json;jsonpatch</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 0 additions & 12 deletions src/Http/Http/src/StreamPipeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave out these changes since this type is going to be moving to corefx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆗 I'll revert changes to StreamPipeReader and StreamPipeWriter.

Will CoreFx also take StreamPipeReaderTests and StreamPipeWriterTests? If yes, I"ll revert changes to those classes too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they will.

using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -227,18 +226,7 @@ public override async ValueTask<ReadResult> ReadAsync(CancellationToken cancella
try
{
AllocateReadTail();
#if NETCOREAPP3_0
var length = await _readingStream.ReadAsync(_readTail.AvailableMemory.Slice(_readTail.End), tokenSource.Token);
#elif NETSTANDARD2_0
if (!MemoryMarshal.TryGetArray<byte>(_readTail.AvailableMemory.Slice(_readTail.End), out var arraySegment))
{
ThrowHelper.CreateInvalidOperationException_NoArrayFromMemory();
}

var length = await _readingStream.ReadAsync(arraySegment.Array, arraySegment.Offset, arraySegment.Count, tokenSource.Token);
#else
#error Target frameworks need to be updated.
#endif
Debug.Assert(length + _readTail.End <= _readTail.AvailableMemory.Length);

_readTail.End += length;
Expand Down
19 changes: 2 additions & 17 deletions src/Http/Http/src/StreamPipeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.AspNetCore.Http
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, these types will be moved to corefx

{
/// <summary>
/// Implements PipeWriter using a underlying stream.
/// Implements PipeWriter using a underlying stream.
/// </summary>
public class StreamPipeWriter : PipeWriter, IDisposable
{
Expand Down Expand Up @@ -50,7 +49,7 @@ private CancellationTokenSource InternalTokenSource
}

/// <summary>
/// Creates a new StreamPipeWrapper
/// Creates a new StreamPipeWrapper
/// </summary>
/// <param name="writingStream">The stream to write to</param>
public StreamPipeWriter(Stream writingStream) : this(writingStream, 4096)
Expand Down Expand Up @@ -174,14 +173,7 @@ private async ValueTask<FlushResult> FlushAsyncInternal(CancellationToken cancel
for (var i = 0; i < count; i++)
{
var segment = _completedSegments[0];
#if NETCOREAPP3_0
await _writingStream.WriteAsync(segment.Buffer.Slice(0, segment.Length), localToken);
#elif NETSTANDARD2_0
MemoryMarshal.TryGetArray<byte>(segment.Buffer, out var arraySegment);
await _writingStream.WriteAsync(arraySegment.Array, 0, segment.Length, localToken);
#else
#error Target frameworks need to be updated.
#endif
_bytesWritten -= segment.Length;
segment.Return();
_completedSegments.RemoveAt(0);
Expand All @@ -190,14 +182,7 @@ private async ValueTask<FlushResult> FlushAsyncInternal(CancellationToken cancel

if (!_currentSegment.IsEmpty)
{
#if NETCOREAPP3_0
await _writingStream.WriteAsync(_currentSegment.Slice(0, _position), localToken);
#elif NETSTANDARD2_0
MemoryMarshal.TryGetArray<byte>(_currentSegment, out var arraySegment);
await _writingStream.WriteAsync(arraySegment.Array, 0, _position, localToken);
#else
#error Target frameworks need to be updated.
#endif
_bytesWritten -= _position;
_position = 0;
}
Expand Down
8 changes: 0 additions & 8 deletions src/Http/Http/test/StreamPipeReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,6 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
await Task.Yield();
return await base.ReadAsync(buffer, offset, count, cancellationToken);
}

#if NETCOREAPP2_2
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
{
await Task.Yield();
return await base.ReadAsync(buffer, cancellationToken);
}
#endif
}
}
}
29 changes: 0 additions & 29 deletions src/Http/Http/test/StreamPipeWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,6 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
await Task.Delay(30000, cancellationToken);
return 0;
}
#if NETCOREAPP2_2
public override async ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
{
await Task.Delay(30000, cancellationToken);
return 0;
}
#endif
}

internal class SingleWriteStream : MemoryStream
Expand All @@ -326,28 +319,6 @@ internal class SingleWriteStream : MemoryStream

public bool AllowAllWrites { get; set; }


#if NETCOREAPP2_2
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
try
{
if (_shouldNextWriteFail && !AllowAllWrites)
{
await Task.Delay(30000, cancellationToken);
}
else
{
await base.WriteAsync(source, cancellationToken);
}
}
finally
{
_shouldNextWriteFail = !_shouldNextWriteFail;
}
}
#endif

public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<SignAssembly>false</SignAssembly>
<LangVersion>7.1</LangVersion>
<DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>
Expand Down
Loading