Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit d0addef

Browse files
authored
[Package Signing] Update Test.Utility dependency (#345)
1 parent ffed70e commit d0addef

8 files changed

Lines changed: 96 additions & 163 deletions

File tree

tests/Validation.PackageSigning.Core.Tests/Support/CertificateIntegrationTestFixture.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class CertificateIntegrationTestFixture : IDisposable
3232
private readonly Lazy<Task<X509Certificate2>> _signingCertificate;
3333
private readonly Lazy<Task<string>> _signingCertificateThumbprint;
3434
private TrustedTestCert<X509Certificate2> _trustedRoot;
35-
private readonly DisposableList _responders;
35+
private readonly DisposableList<IDisposable> _responders;
3636

3737
public CertificateIntegrationTestFixture()
3838
{
@@ -47,7 +47,7 @@ public CertificateIntegrationTestFixture()
4747
_timestampServiceUrl = new Lazy<Task<Uri>>(CreateDefaultTrustedTimestampServiceUrlAsync);
4848
_signingCertificate = new Lazy<Task<X509Certificate2>>(CreateDefaultTrustedSigningCertificateAsync);
4949
_signingCertificateThumbprint = new Lazy<Task<string>>(GetDefaultTrustedSigningCertificateThumbprintAsync);
50-
_responders = new DisposableList();
50+
_responders = new DisposableList<IDisposable>();
5151
}
5252

5353
public Task<SigningTestServer> GetTestServerAsync() => _testServer.Value;
@@ -62,7 +62,7 @@ public async Task<X509Certificate2> GetSigningCertificateAsync()
6262

6363
protected Task<CertificateAuthority> GetRootCertificateAuthority() => _rootCertificateAuthority.Value;
6464
protected Task<CertificateAuthority> GetCertificateAuthority() => _certificateAuthority.Value;
65-
protected DisposableList GetResponders() => _responders;
65+
protected DisposableList<IDisposable> GetResponders() => _responders;
6666

6767
public void Dispose()
6868
{
@@ -141,11 +141,16 @@ void CustomizeAsSigningCertificate(X509V3CertificateGenerator generator)
141141
Action<X509V3CertificateGenerator> customizeCertificate)
142142
{
143143
var keyPair = SigningTestUtility.GenerateKeyPair(publicKeyLength: 2048);
144-
var publicCertificate = ca.IssueCertificate(
145-
keyPair.Public,
146-
new X509Name($"C=US,ST=WA,L=Redmond,O=NuGet,CN=NuGet Test ${name} Certificate ({Guid.NewGuid()})"),
147-
customizeCertificate,
148-
notBefore: DateTime.UtcNow.AddSeconds(-10));
144+
145+
var publicCertificate = ca.IssueCertificate(new IssueCertificateOptions
146+
{
147+
CustomizeCertificate = customizeCertificate,
148+
NotAfter = DateTime.UtcNow.AddMinutes(10),
149+
NotBefore = DateTime.UtcNow.AddSeconds(-10),
150+
KeyPair = keyPair,
151+
152+
SubjectName = new X509Name($"C=US,ST=WA,L=Redmond,O=NuGet,CN=NuGet Test ${name} Certificate ({Guid.NewGuid()})")
153+
});
149154

150155
var certificate = new X509Certificate2(publicCertificate.GetEncoded());
151156
certificate.PrivateKey = DotNetUtilities.ToRSA(keyPair.Private as RsaPrivateCrtKeyParameters);

tests/Validation.PackageSigning.Core.Tests/Support/ExtensionMethods.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Security.Cryptography.X509Certificates;
46
using Test.Utility.Signing;
7+
using BCCertificate = Org.BouncyCastle.X509.X509Certificate;
58

69
namespace Validation.PackageSigning.Core.Tests.Support
710
{
811
public static class ExtensionMethods
912
{
10-
public static DisposableList RegisterResponders(
13+
public static X509Certificate2 ToX509Certificate2(this BCCertificate certificate)
14+
{
15+
return new X509Certificate2(certificate.GetEncoded());
16+
}
17+
18+
public static DisposableList<IDisposable> RegisterResponders(
1119
this ISigningTestServer testServer,
1220
CertificateAuthority ca,
1321
bool addCa = true,
1422
bool addOcsp = true)
1523
{
16-
var responders = new DisposableList();
24+
var responders = new DisposableList<IDisposable>();
1725
var currentCa = ca;
1826

1927
while (currentCa != null)
@@ -34,7 +42,7 @@ public static DisposableList RegisterResponders(
3442
return responders;
3543
}
3644

37-
public static DisposableList RegisterResponders(
45+
public static DisposableList<IDisposable> RegisterResponders(
3846
this ISigningTestServer testServer,
3947
TimestampService timestampService,
4048
bool addCa = true,

tests/Validation.PackageSigning.Core.Tests/Validation.PackageSigning.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<Version>4.4.0</Version>
7272
</PackageReference>
7373
<PackageReference Include="Test.Utility">
74-
<Version>4.7.0-preview1-4886</Version>
74+
<Version>4.7.0-preview1.4948+f399fefacef3d4cc769a1580e812e1045d1d3b3e</Version>
7575
</PackageReference>
7676
<PackageReference Include="xunit">
7777
<Version>2.3.1</Version>

tests/Validation.PackageSigning.ExtractAndValidateSignature.Tests/SignatureValidatorIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using NuGet.Services.Validation.Issues;
2323
using NuGetGallery;
2424
using Test.Utility.Signing;
25-
using Validation.PackageSigning.ExtractAndValidateSignature.Tests.Support;
25+
using Validation.PackageSigning.Core.Tests.Support;
2626
using Xunit;
2727
using Xunit.Abstractions;
2828
using NuGetHashAlgorithmName = NuGet.Common.HashAlgorithmName;

tests/Validation.PackageSigning.ExtractAndValidateSignature.Tests/Support/ExtensionMethods.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

tests/Validation.PackageSigning.ExtractAndValidateSignature.Tests/Validation.PackageSigning.ExtractAndValidateSignature.Tests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<Reference Include="Microsoft.CSharp" />
3636
</ItemGroup>
3737
<ItemGroup>
38-
<Compile Include="Support\ExtensionMethods.cs" />
3938
<Compile Include="Support\RecordingLogger.cs" />
4039
<Compile Include="Support\CertificateIntegrationTestCollection.cs" />
4140
<Compile Include="Support\CertificateIntegrationTestFixture.cs" />
@@ -61,7 +60,7 @@
6160
<Version>1.8.1.3</Version>
6261
</PackageReference>
6362
<PackageReference Include="Test.Utility">
64-
<Version>4.7.0-preview1-4886</Version>
63+
<Version>4.7.0-preview1.4948+f399fefacef3d4cc769a1580e812e1045d1d3b3e</Version>
6564
</PackageReference>
6665
<PackageReference Include="xunit">
6766
<Version>2.3.1</Version>

tests/Validation.PackageSigning.ValidateCertificate.Tests/OnlineCertificateVerifierIntegrationTests.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,21 @@ public async Task UnknownCertificate()
104104
public async Task RevokedEndCertificate()
105105
{
106106
// Arrange - create a revocation date with no milliseconds
107+
var crlUpdateTime = DateTimeOffset.Parse("10/21/1995 4:05:06 PM");
107108
var revocationDate = DateTimeOffset.Parse("02/18/1994 1:02:03 PM");
108109

109-
var certificate = await _fixture.GetRevokedSigningCertificateAsync(revocationDate);
110-
111-
// Act & assert
112-
var result = _target.VerifyCodeSigningCertificate(certificate, new X509Certificate2[0]);
110+
using (var revokedChain = await _fixture.GetRevokedSigningCertificateAsync(revocationDate, crlUpdateTime))
111+
{
112+
// Act & assert
113+
var result = _target.VerifyCodeSigningCertificate(revokedChain.EndCertificate, new X509Certificate2[0]);
113114

114-
Assert.Equal(EndCertificateStatus.Revoked, result.Status);
115-
Assert.Equal(X509ChainStatusFlags.Revoked, result.StatusFlags);
116-
Assert.NotNull(result.StatusUpdateTime);
117-
Assert.NotNull(result.RevocationTime);
118-
Assert.Equal(revocationDate, result.RevocationTime.Value);
115+
Assert.Equal(EndCertificateStatus.Revoked, result.Status);
116+
Assert.Equal(X509ChainStatusFlags.Revoked, result.StatusFlags);
117+
Assert.NotNull(result.StatusUpdateTime);
118+
Assert.NotNull(result.RevocationTime);
119+
Assert.Equal(crlUpdateTime, result.StatusUpdateTime.Value);
120+
Assert.Equal(revocationDate, result.RevocationTime.Value);
121+
}
119122
}
120123

121124
[Fact]

0 commit comments

Comments
 (0)