Skip to content

Commit

Permalink
Enable timestamp provider test and fix 3 broken tests (#3210)
Browse files Browse the repository at this point in the history
enable all unit tests; enable 8 more tests; enable timestampProviderTest; fix 3 broken tests in TimestampProviderTests
  • Loading branch information
heng-liu authored Feb 13, 2020
1 parent 93951d2 commit 0d3a2b3
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 44 deletions.
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,6 @@ namespace NuGet.Packaging.FuncTest
[Collection(SigningTestCollection.Name)]
public class TimestampProviderTests
{
private const string ArgumentNullExceptionMessage = "Value cannot be null.\r\nParameter name: {0}";
private const string OperationCancelledExceptionMessage = "The operation was canceled.";

private SigningTestFixture _testFixture;
Expand Down Expand Up @@ -70,7 +69,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 +156,12 @@ 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));

Assert.Equal("request", exception.ParamName);
Assert.StartsWith("Value cannot be null.", exception.Message);
}
}

Expand All @@ -188,12 +187,12 @@ 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));

Assert.Equal("logger", exception.ParamName);
Assert.StartsWith("Value cannot be null.", exception.Message);
}
}

Expand All @@ -220,12 +219,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

0 comments on commit 0d3a2b3

Please sign in to comment.