Skip to content
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

Enable timestamp provider test and fix 3 broken tests #3210

Merged
Show file tree
Hide file tree
Changes from 9 commits
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,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED

using System;
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED

using System;
using System.Collections.Generic;
Expand All @@ -24,7 +24,11 @@ namespace NuGet.Packaging.FuncTest
[Collection(SigningTestCollection.Name)]
public class TimestampProviderTests
{
#if IS_DESKTOP
private const string ArgumentNullExceptionMessage = "Value cannot be null.\r\nParameter name: {0}";
#else
private const string ArgumentNullExceptionMessage = "Value cannot be null. (Parameter '{0}')";
#endif
heng-liu marked this conversation as resolved.
Show resolved Hide resolved
private const string OperationCancelledExceptionMessage = "The operation was canceled.";

private SigningTestFixture _testFixture;
Expand Down Expand Up @@ -70,7 +74,7 @@ public async Task GetTimestampAsync_WithValidInput_ReturnsTimestampAsync()
}

[CIOnlyFact]
public async Task GetTimestamp_AssertCompleteChain_SuccessAsync()
public async Task GetTimestampAsync_AssertCompleteChain_SuccessAsync()
{
var timestampService = await _testFixture.GetDefaultTrustedTimestampServiceAsync();
var timestampProvider = new Rfc3161TimestampProvider(timestampService.Url);
Expand Down Expand Up @@ -157,12 +161,11 @@ public async Task GetTimestampAsync_WhenRequestNull_ThrowsAsync()
target: SignaturePlacement.PrimarySignature
);

// Act
Action timestampAction = async () => await timestampProvider.GetTimestampAsync(null, logger, CancellationToken.None);

// Assert
timestampAction.ShouldThrow<ArgumentNullException>()
.WithMessage(string.Format(ArgumentNullExceptionMessage, nameof(request)));
var exception = await Assert.ThrowsAsync<ArgumentNullException>(
() => timestampProvider.GetTimestampAsync(request : null, logger, CancellationToken.None));
heng-liu marked this conversation as resolved.
Show resolved Hide resolved

Assert.Equal(string.Format(ArgumentNullExceptionMessage, nameof(request)), exception.Message);
heng-liu marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -188,12 +191,11 @@ public async Task GetTimestampAsync_WhenLoggerNull_ThrowsAsync()
target: SignaturePlacement.PrimarySignature
);

// Act
Action timestampAction = async () => await timestampProvider.GetTimestampAsync(request, null, CancellationToken.None);

// Assert
timestampAction.ShouldThrow<ArgumentNullException>()
.WithMessage(string.Format(ArgumentNullExceptionMessage, "logger"));
var exception = await Assert.ThrowsAsync<ArgumentNullException>(
() => timestampProvider.GetTimestampAsync(request, logger : null, CancellationToken.None));
heng-liu marked this conversation as resolved.
Show resolved Hide resolved

Assert.Equal(string.Format(ArgumentNullExceptionMessage, "logger"), exception.Message);
}
}

Expand All @@ -220,12 +222,11 @@ public async Task GetTimestampAsync_WhenCancelled_ThrowsAsync()
target: SignaturePlacement.PrimarySignature
);

// Act
Action timestampAction = async () => await timestampProvider.GetTimestampAsync(request, logger, new CancellationToken(canceled: true));

// Assert
timestampAction.ShouldThrow<OperationCanceledException>()
.WithMessage(OperationCancelledExceptionMessage);
var exception = await Assert.ThrowsAsync<OperationCanceledException>(
() => timestampProvider.GetTimestampAsync(request, logger, new CancellationToken(canceled: true)));

Assert.Equal(OperationCancelledExceptionMessage, exception.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public async Task RestoreCommand_ImportsNoMatchAsync()
}
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public async Task RestoreCommand_InvalidSignedPackageAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ await Assert.ThrowsAsync<NotImplementedException>(
}
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public async Task ValidateIntegrityAsync_WhenSignatureContentNull_Throws()
{
Expand Down Expand Up @@ -1835,7 +1835,7 @@ public void GetContentHash_UnsignedPackage_WhenGivingAFallbackFunctionThatReturn
}
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[CIOnlyFact]
public async Task GetContentHash_IsSameForUnsignedAndSignedPackageAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System;
using System.Linq;
using System.Security.Cryptography;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Read_WithInvalidAsn1_Throws()
() => EssCertId.Read(new byte[] { 0x30, 0x0b }));
}

#if !IS_CORECLR
#if IS_SIGNING_SUPPORTED
[Fact]
public void Read_WithValidInput_ReturnsEssCertId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void Read_WithNonDefaultAlgorithmIdentifier_ReturnsEssCertIdV2()
SigningTestUtility.VerifyByteArrays(bcIssuerSerial.Serial.Value.ToByteArray(), essCertIdV2.IssuerSerial.SerialNumber);
}

#if !IS_CORECLR
#if IS_SIGNING_SUPPORTED
[Fact]
public void Read_WithValidInput_ReturnsEssCertId()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System;
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void WriteTimeout_Setter_SetsValueOnUnderlyingStream()
}
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public void Close_WhenLeaveOpenFalse_DisposesUnderlyingStream()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace NuGet.Packaging.Test
{
public class SignatureTrustAndValidityVerificationProviderTests
{
#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
private static readonly Lazy<PrimarySignature> _signature = new Lazy<PrimarySignature>(
() => PrimarySignature.Load(SigningTestUtility.GetResourceBytes(".signature.p7s")));
#endif
Expand All @@ -25,7 +25,7 @@ public SignatureTrustAndValidityVerificationProviderTests()
_provider = new SignatureTrustAndValidityVerificationProvider();
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public async Task GetTrustResultAsync_WhenPackageIsNull_Throws()
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public async Task GetTrustResultAsync_WhenSignatureIsNull_Throws()
Assert.Equal("signature", exception.ParamName);
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public async Task GetTrustResultAsync_WhenSettingsIsNull_Throws()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System;
using System.IO;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void ReadAndHashUntilPosition_WhenPositionBeforeCurrentReadPosition_Throw
}
}

#if !IS_CORECLR
#if IS_SIGNING_SUPPORTED
[Fact]
public void ReadAndHashUntilPosition_WhenPositionAtStart_ReadsAndHashes()
{
Expand Down Expand Up @@ -248,7 +248,7 @@ public void HashBytes_WhenBytesNullOrEmpty_Throws(byte[] bytes)
}
}

#if !IS_CORECLR
#if IS_SIGNING_SUPPORTED
[Fact]
public void HashBytes_WithInputBytes_Hashes()
{
Expand Down Expand Up @@ -486,7 +486,7 @@ protected override void Dispose(bool disposing)

internal string GetHash()
{
#if !IS_CORECLR
#if IS_SIGNING_SUPPORTED
HashAlgorithm.TransformFinalBlock(new byte[0], inputOffset: 0, inputCount: 0);

return Convert.ToBase64String(HashAlgorithm.Hash);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void GetPackageContentHash_WithCompressedSignatureFileEntry_NotThrows()
}
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public async Task RemoveRepositorySignaturesAsync_WithNullInput_Throws()
{
Expand Down Expand Up @@ -542,7 +542,7 @@ public void Dispose()
}
}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
private sealed class RemoveTest : IDisposable
{
private bool _isDisposed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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 IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System;
using System.IO;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
using System.Security.Cryptography.Pkcs;
#endif
using System.Security.Cryptography.X509Certificates;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void Verify_WithUntrustedSelfSignedCertificate_Succeeds()

}

#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
[Fact]
public void CreateSignedAttributes_SignPackageRequest_WhenRequestNull_Throws()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public static SignedCms GenerateSignedCms(X509Certificate2 cert, byte[] content)

return cms;
}
#if IS_DESKTOP
#if IS_SIGNING_SUPPORTED
/// <summary>
/// Generates a SignedCMS object for some content.
/// </summary>
Expand Down