Updating tests to use moq.netcore

This commit is contained in:
Pranav K 2015-11-10 16:31:50 -08:00
parent 7bb3ccf201
commit ca3e4669dc
49 changed files with 209 additions and 138 deletions

1
.gitignore vendored
View File

@ -25,3 +25,4 @@ nuget.exe
*.ipch *.ipch
*.sln.ide *.sln.ide
project.lock.json project.lock.json
.vs

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.Internal;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNet.DataProtection namespace Microsoft.AspNet.DataProtection

View File

@ -6,6 +6,7 @@ using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.Cryptography.Cng; using Microsoft.AspNet.Cryptography.Cng;
using Microsoft.AspNet.Cryptography.SafeHandles; using Microsoft.AspNet.Cryptography.SafeHandles;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.Cng.Internal;
using Microsoft.AspNet.DataProtection.SP800_108; using Microsoft.AspNet.DataProtection.SP800_108;
namespace Microsoft.AspNet.DataProtection.Cng namespace Microsoft.AspNet.DataProtection.Cng

View File

@ -6,6 +6,7 @@ using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.Cryptography.Cng; using Microsoft.AspNet.Cryptography.Cng;
using Microsoft.AspNet.Cryptography.SafeHandles; using Microsoft.AspNet.Cryptography.SafeHandles;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.Cng.Internal;
using Microsoft.AspNet.DataProtection.SP800_108; using Microsoft.AspNet.DataProtection.SP800_108;
namespace Microsoft.AspNet.DataProtection.Cng namespace Microsoft.AspNet.DataProtection.Cng

View File

@ -4,12 +4,12 @@
using System; using System;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
namespace Microsoft.AspNet.DataProtection.Cng namespace Microsoft.AspNet.DataProtection.Cng.Internal
{ {
/// <summary> /// <summary>
/// Base class used for all CNG-related authentication encryption operations. /// Base class used for all CNG-related authentication encryption operations.
/// </summary> /// </summary>
internal unsafe abstract class CngAuthenticatedEncryptorBase : IOptimizedAuthenticatedEncryptor, IDisposable public unsafe abstract class CngAuthenticatedEncryptorBase : IOptimizedAuthenticatedEncryptor, IDisposable
{ {
public byte[] Decrypt(ArraySegment<byte> ciphertext, ArraySegment<byte> additionalAuthenticatedData) public byte[] Decrypt(ArraySegment<byte> ciphertext, ArraySegment<byte> additionalAuthenticatedData)
{ {

View File

@ -8,6 +8,7 @@ using Microsoft.AspNet.DataProtection;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.Cng; using Microsoft.AspNet.DataProtection.Cng;
using Microsoft.AspNet.DataProtection.KeyManagement; using Microsoft.AspNet.DataProtection.KeyManagement;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.DataProtection.Repositories; using Microsoft.AspNet.DataProtection.Repositories;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Win32; using Microsoft.Win32;

View File

@ -5,6 +5,7 @@ using System;
using Microsoft.AspNet.Cryptography.Cng; using Microsoft.AspNet.Cryptography.Cng;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.KeyManagement; using Microsoft.AspNet.DataProtection.KeyManagement;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.DataProtection namespace Microsoft.AspNet.DataProtection

View File

@ -3,13 +3,13 @@
using System; using System;
namespace Microsoft.AspNet.DataProtection namespace Microsoft.AspNet.DataProtection.Internal
{ {
/// <summary> /// <summary>
/// An interface into <see cref="Activator.CreateInstance{T}"/> that also supports /// An interface into <see cref="Activator.CreateInstance{T}"/> that also supports
/// limited dependency injection (of <see cref="IServiceProvider"/>). /// limited dependency injection (of <see cref="IServiceProvider"/>).
/// </summary> /// </summary>
internal interface IActivator public interface IActivator
{ {
/// <summary> /// <summary>
/// Creates an instance of <paramref name="implementationTypeName"/> and ensures /// Creates an instance of <paramref name="implementationTypeName"/> and ensures

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.DataProtection.Repositories; using Microsoft.AspNet.DataProtection.Repositories;
using Microsoft.AspNet.DataProtection.XmlEncryption; using Microsoft.AspNet.DataProtection.XmlEncryption;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;

View File

@ -5,6 +5,7 @@ using System;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.DataProtection.XmlEncryption; using Microsoft.AspNet.DataProtection.XmlEncryption;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement
@ -15,7 +16,13 @@ namespace Microsoft.AspNet.DataProtection.KeyManagement
/// </summary> /// </summary>
internal sealed class DeferredKey : KeyBase internal sealed class DeferredKey : KeyBase
{ {
public DeferredKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate, IInternalXmlKeyManager keyManager, XElement keyElement) public DeferredKey(
Guid keyId,
DateTimeOffset creationDate,
DateTimeOffset activationDate,
DateTimeOffset expirationDate,
IInternalXmlKeyManager keyManager,
XElement keyElement)
: base(keyId, creationDate, activationDate, expirationDate, new Lazy<IAuthenticatedEncryptor>(GetLazyEncryptorDelegate(keyManager, keyElement))) : base(keyId, creationDate, activationDate, expirationDate, new Lazy<IAuthenticatedEncryptor>(GetLazyEncryptorDelegate(keyManager, keyElement)))
{ {
} }

View File

@ -5,12 +5,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
/// <summary> /// <summary>
/// Wraps both a keyring and its expiration policy. /// Wraps both a keyring and its expiration policy.
/// </summary> /// </summary>
internal sealed class CacheableKeyRing public sealed class CacheableKeyRing
{ {
private readonly CancellationToken _expirationToken; private readonly CancellationToken _expirationToken;

View File

@ -3,9 +3,9 @@
using System; using System;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
internal struct DefaultKeyResolution public struct DefaultKeyResolution
{ {
/// <summary> /// <summary>
/// The default key, may be null if no key is a good default candidate. /// The default key, may be null if no key is a good default candidate.

View File

@ -3,9 +3,9 @@
using System; using System;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
internal interface ICacheableKeyRingProvider public interface ICacheableKeyRingProvider
{ {
CacheableKeyRing GetCacheableKeyRing(DateTimeOffset now); CacheableKeyRing GetCacheableKeyRing(DateTimeOffset now);
} }

View File

@ -4,12 +4,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
/// <summary> /// <summary>
/// Implements policy for resolving the default key from a candidate keyring. /// Implements policy for resolving the default key from a candidate keyring.
/// </summary> /// </summary>
internal interface IDefaultKeyResolver public interface IDefaultKeyResolver
{ {
/// <summary> /// <summary>
/// Locates the default key from the keyring. /// Locates the default key from the keyring.

View File

@ -5,12 +5,12 @@ using System;
using Microsoft.AspNet.DataProtection.Repositories; using Microsoft.AspNet.DataProtection.Repositories;
using Microsoft.AspNet.DataProtection.XmlEncryption; using Microsoft.AspNet.DataProtection.XmlEncryption;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
/// <summary> /// <summary>
/// Provides default implementations of the services required by an <see cref="IKeyManager"/>. /// Provides default implementations of the services required by an <see cref="IKeyManager"/>.
/// </summary> /// </summary>
internal interface IDefaultKeyServices public interface IDefaultKeyServices
{ {
/// <summary> /// <summary>
/// Gets the default <see cref="IXmlEncryptor"/> service (could return null). /// Gets the default <see cref="IXmlEncryptor"/> service (could return null).

View File

@ -5,10 +5,9 @@ using System;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
// Used for unit testing public interface IInternalXmlKeyManager
internal interface IInternalXmlKeyManager
{ {
IKey CreateNewKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate); IKey CreateNewKey(Guid keyId, DateTimeOffset creationDate, DateTimeOffset activationDate, DateTimeOffset expirationDate);

View File

@ -4,12 +4,12 @@
using System; using System;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
{ {
/// <summary> /// <summary>
/// The basic interface for accessing a read-only keyring. /// The basic interface for accessing a read-only keyring.
/// </summary> /// </summary>
internal interface IKeyRing public interface IKeyRing
{ {
/// <summary> /// <summary>
/// The authenticated encryptor that shall be used for new encryption operations. /// The authenticated encryptor that shall be used for new encryption operations.

View File

@ -1,11 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; namespace Microsoft.AspNet.DataProtection.KeyManagement.Internal
namespace Microsoft.AspNet.DataProtection.KeyManagement
{ {
internal interface IKeyRingProvider public interface IKeyRingProvider
{ {
IKeyRing GetCurrentKeyRing(); IKeyRing GetCurrentKeyRing();
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement
{ {

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.DataProtection.KeyManagement namespace Microsoft.AspNet.DataProtection.KeyManagement

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -11,6 +11,8 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.Internal;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.DataProtection.Repositories; using Microsoft.AspNet.DataProtection.Repositories;
using Microsoft.AspNet.DataProtection.XmlEncryption; using Microsoft.AspNet.DataProtection.XmlEncryption;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.Cryptography; using Microsoft.AspNet.Cryptography;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.Internal;
namespace Microsoft.AspNet.DataProtection.XmlEncryption namespace Microsoft.AspNet.DataProtection.XmlEncryption
{ {

View File

@ -1,19 +1,23 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*", "Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Test.Shared": { "type": "build", "version": "" }, "Microsoft.AspNet.DataProtection.Test.Shared": {
"Microsoft.AspNet.Testing": "1.0.0-*", "type": "build",
"xunit.runner.aspnet": "2.0.0-aspnet-*" "version": ""
}, },
"frameworks": { "Microsoft.AspNet.Testing": "1.0.0-*",
"dnx451": { }, "xunit.runner.aspnet": "2.0.0-aspnet-*"
"dnxcore50": { } },
}, "frameworks": {
"commands": { "dnx451": { },
"test": "xunit.runner.aspnet" "dnxcore50": { }
}, },
"compilationOptions": { "commands": {
"allowUnsafe": true, "test": "xunit.runner.aspnet"
"keyFile": "../../tools/Key.snk" },
} "compilationOptions": {
"allowUnsafe": true,
"keyFile": "../../tools/Key.snk",
"warningsAsErrors": true
}
} }

View File

@ -1,20 +1,21 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*", "Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
"Microsoft.AspNet.Cryptography.KeyDerivation": "1.0.0-*", "Microsoft.AspNet.Cryptography.KeyDerivation": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Test.Shared": "", "Microsoft.AspNet.DataProtection.Test.Shared": "",
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*"
"xunit.runner.aspnet": "2.0.0-aspnet-*" },
}, "frameworks": {
"frameworks": { "dnx451": { },
"dnx451": { } "dnxcore50": { }
}, },
"commands": { "commands": {
"test": "xunit.runner.aspnet" "test": "xunit.runner.aspnet"
}, },
"compilationOptions": { "compilationOptions": {
"allowUnsafe": true, "allowUnsafe": true,
"keyFile": "../../tools/Key.snk" "warningsAsErrors": true,
} "keyFile": "../../tools/Key.snk"
}
} }

View File

@ -1,20 +1,28 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*", "Microsoft.AspNet.Cryptography.Internal": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*", "Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*"
"xunit.runner.aspnet": "2.0.0-aspnet-*" },
"frameworks": {
"dnx451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
}, },
"frameworks": { "dnxcore50": {
"dnx451": { } "dependencies": {
}, "moq.netcore": "4.4.0-beta8"
"commands": { }
"test": "xunit.runner.aspnet"
},
"compile": "..\\common\\**\\*.cs",
"compilationOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
} }
},
"commands": {
"test": "xunit.runner.aspnet"
},
"compile": "../common/**/*.cs",
"compilationOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
}
} }

View File

@ -86,7 +86,7 @@ namespace Microsoft.AspNet.DataProtection
private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition
{ {
public bool IsMet => (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) != null); public bool IsMet => Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%") != null;
public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located."; public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located.";
} }

View File

@ -1,20 +1,31 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*", "Microsoft.AspNet.DataProtection.Abstractions": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*", "Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Test.Shared": { "type": "build", "version": "" }, "Microsoft.AspNet.DataProtection.Test.Shared": {
"Microsoft.AspNet.Testing": "1.0.0-*", "type": "build",
"Moq": "4.2.1312.1622", "version": ""
"xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"frameworks": { "Microsoft.AspNet.Testing": "1.0.0-*",
"dnx451": { } "xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
}, },
"commands": { "dnxcore50": {
"test": "xunit.runner.aspnet" "dependencies": {
}, "moq.netcore": "4.4.0-beta8"
"compilationOptions": { }
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
} }
},
"commands": {
"test": "xunit.runner.aspnet"
},
"compilationOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
}
} }

View File

@ -1,17 +1,7 @@
{ {
"dependencies": { "frameworks": {
"Microsoft.AspNet.Cryptography.Internal": "1.0.0-*", "dnx451": { },
"Microsoft.AspNet.Testing": "1.0.0-*", "dnxcore50": { }
"xunit.runner.aspnet": "2.0.0-aspnet-*" },
}, "shared": "**/*.cs"
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"commands": {
},
"compilationOptions": {
},
"shared": "**\\*.cs"
} }

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNet.DataProtection.Internal;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451
using System; using System;
using System.Runtime.ConstrainedExecution; using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -85,3 +86,4 @@ namespace Microsoft.AspNet.DataProtection
} }
} }
} }
#endif

View File

@ -74,14 +74,23 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
Assert.Equal(plaintext, roundTripPlaintext); Assert.Equal(plaintext, roundTripPlaintext);
} }
public static TheoryData CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementationData
=> new TheoryData<EncryptionAlgorithm, ValidationAlgorithm, Func<HMAC>>
{
{ EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA256, () => new HMACSHA256() },
{ EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA256, () => new HMACSHA256() },
{ EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA256, () => new HMACSHA256() },
{ EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA512, () => new HMACSHA512() },
{ EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512, () => new HMACSHA512() },
{ EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA512, () => new HMACSHA512() },
};
[Theory] [Theory]
[InlineData(EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA256)] [MemberData(nameof(CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementationData))]
[InlineData(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA256)] public void CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation(
[InlineData(EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA256)] EncryptionAlgorithm encryptionAlgorithm,
[InlineData(EncryptionAlgorithm.AES_128_CBC, ValidationAlgorithm.HMACSHA512)] ValidationAlgorithm validationAlgorithm,
[InlineData(EncryptionAlgorithm.AES_192_CBC, ValidationAlgorithm.HMACSHA512)] Func<HMAC> validationAlgorithmFactory)
[InlineData(EncryptionAlgorithm.AES_256_CBC, ValidationAlgorithm.HMACSHA512)]
public void CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation(EncryptionAlgorithm encryptionAlgorithm, ValidationAlgorithm validationAlgorithm)
{ {
// Parse test input // Parse test input
int keyLengthInBits = Int32.Parse(Regex.Match(encryptionAlgorithm.ToString(), @"^AES_(?<keyLength>\d{3})_CBC$").Groups["keyLength"].Value, CultureInfo.InvariantCulture); int keyLengthInBits = Int32.Parse(Regex.Match(encryptionAlgorithm.ToString(), @"^AES_(?<keyLength>\d{3})_CBC$").Groups["keyLength"].Value, CultureInfo.InvariantCulture);
@ -90,9 +99,9 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
var masterKey = Secret.Random(512 / 8); var masterKey = Secret.Random(512 / 8);
var control = new ManagedAuthenticatedEncryptor( var control = new ManagedAuthenticatedEncryptor(
keyDerivationKey: masterKey, keyDerivationKey: masterKey,
symmetricAlgorithmFactory: () => new AesCryptoServiceProvider(), symmetricAlgorithmFactory: () => Aes.Create(),
symmetricAlgorithmKeySizeInBytes: keyLengthInBits / 8, symmetricAlgorithmKeySizeInBytes: keyLengthInBits / 8,
validationAlgorithmFactory: () => KeyedHashAlgorithm.Create(validationAlgorithm.ToString())); validationAlgorithmFactory: validationAlgorithmFactory);
var test = CreateDescriptor(encryptionAlgorithm, validationAlgorithm, masterKey).CreateEncryptorInstance(); var test = CreateDescriptor(encryptionAlgorithm, validationAlgorithm, masterKey).CreateEncryptorInstance();
// Act & assert - data round trips properly from control to test // Act & assert - data round trips properly from control to test

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
var control = new ManagedAuthenticatedEncryptorDescriptor( var control = new ManagedAuthenticatedEncryptorDescriptor(
new ManagedAuthenticatedEncryptionOptions() new ManagedAuthenticatedEncryptionOptions()
{ {
EncryptionAlgorithmType = typeof(AesCryptoServiceProvider), EncryptionAlgorithmType = typeof(Aes),
EncryptionAlgorithmKeySize = 192, EncryptionAlgorithmKeySize = 192,
ValidationAlgorithmType = typeof(HMACSHA384) ValidationAlgorithmType = typeof(HMACSHA384)
}, },
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationM
<value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value> <value>k88VrwGLINfVAqzlAp7U4EAjdlmUG17c756McQGdjHU8Ajkfc/A3YOKdqlMcF6dXaIxATED+g2f62wkRRRRRzA==</value>
</masterKey> </masterKey>
</descriptor>", </descriptor>",
typeof(AesCryptoServiceProvider).AssemblyQualifiedName, typeof(HMACSHA384).AssemblyQualifiedName); typeof(Aes).AssemblyQualifiedName, typeof(HMACSHA384).AssemblyQualifiedName);
var test = new ManagedAuthenticatedEncryptorDescriptorDeserializer().ImportFromXml(XElement.Parse(xml)).CreateEncryptorInstance(); var test = new ManagedAuthenticatedEncryptorDescriptorDeserializer().ImportFromXml(XElement.Parse(xml)).CreateEncryptorInstance();
// Act & assert // Act & assert

View File

@ -7,7 +7,7 @@ using Microsoft.AspNet.Testing.xunit;
using Moq; using Moq;
using Xunit; using Xunit;
namespace Microsoft.AspNet.DataProtection.Cng namespace Microsoft.AspNet.DataProtection.Cng.Internal
{ {
public unsafe class CngAuthenticatedEncryptorBaseTests public unsafe class CngAuthenticatedEncryptorBaseTests
{ {
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.DataProtection.Cng
Assert.Equal(new byte[] { 0x20, 0x21, 0x22 }, retVal); Assert.Equal(new byte[] { 0x20, 0x21, 0x22 }, retVal);
} }
internal abstract class MockableEncryptor : CngAuthenticatedEncryptorBase public abstract class MockableEncryptor : CngAuthenticatedEncryptorBase
{ {
public override void Dispose() public override void Dispose()
{ {

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Threading; using System.Threading;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -5,6 +5,7 @@ using System;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.Testing; using Microsoft.AspNet.Testing;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -5,9 +5,11 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Reflection;
using System.Text; using System.Text;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.Testing; using Microsoft.AspNet.Testing;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -7,6 +7,7 @@ using System.Globalization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.Testing; using Microsoft.AspNet.Testing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Moq; using Moq;

View File

@ -8,6 +8,8 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.Internal;
using Microsoft.AspNet.DataProtection.KeyManagement.Internal;
using Microsoft.AspNet.DataProtection.Repositories; using Microsoft.AspNet.DataProtection.Repositories;
using Microsoft.AspNet.DataProtection.XmlEncryption; using Microsoft.AspNet.DataProtection.XmlEncryption;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;

View File

@ -5,6 +5,7 @@ using System;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel; using Microsoft.AspNet.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNet.DataProtection.Internal;
using Microsoft.AspNet.DataProtection.XmlEncryption; using Microsoft.AspNet.DataProtection.XmlEncryption;
using Moq; using Moq;

View File

@ -195,7 +195,7 @@ namespace Microsoft.AspNet.DataProtection
["EncryptionType"] = "managed", ["EncryptionType"] = "managed",
["EncryptionAlgorithmType"] = typeof(TripleDES).AssemblyQualifiedName, ["EncryptionAlgorithmType"] = typeof(TripleDES).AssemblyQualifiedName,
["EncryptionAlgorithmKeySize"] = 2048, ["EncryptionAlgorithmKeySize"] = 2048,
["ValidationAlgorithmType"] = typeof(HMACMD5).AssemblyQualifiedName ["ValidationAlgorithmType"] = typeof(HMACSHA1).AssemblyQualifiedName
}); });
var services = serviceCollection.BuildServiceProvider(); var services = serviceCollection.BuildServiceProvider();
@ -203,7 +203,7 @@ namespace Microsoft.AspNet.DataProtection
{ {
EncryptionAlgorithmType = typeof(TripleDES), EncryptionAlgorithmType = typeof(TripleDES),
EncryptionAlgorithmKeySize = 2048, EncryptionAlgorithmKeySize = 2048,
ValidationAlgorithmType = typeof(HMACMD5) ValidationAlgorithmType = typeof(HMACSHA1)
}); });
var actualConfiguration = (ManagedAuthenticatedEncryptorConfiguration)services.GetService<IAuthenticatedEncryptorConfiguration>(); var actualConfiguration = (ManagedAuthenticatedEncryptorConfiguration)services.GetService<IAuthenticatedEncryptorConfiguration>();

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.DataProtection.Repositories
// Assert // Assert
Assert.Equal(defaultDirInfo.FullName, Assert.Equal(defaultDirInfo.FullName,
new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ASP.NET", "DataProtection-Keys")).FullName); new DirectoryInfo(Path.Combine(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%"), "ASP.NET", "DataProtection-Keys")).FullName);
} }
[Fact] [Fact]
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.DataProtection.Repositories
private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition private class ConditionalRunTestOnlyIfLocalAppDataAvailable : Attribute, ITestCondition
{ {
public bool IsMet => (Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) != null); public bool IsMet => Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%") != null;
public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located."; public string SkipReason { get; } = "%LOCALAPPDATA% couldn't be located.";
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if !DNXCORE50
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.Xml; using System.Security.Cryptography.Xml;
@ -58,3 +59,5 @@ namespace Microsoft.AspNet.DataProtection.XmlEncryption
} }
} }
} }
#endif

View File

@ -33,6 +33,7 @@ namespace Microsoft.AspNet.DataProtection.XmlEncryption
XmlAssert.Equal(originalXml, roundTrippedElement); XmlAssert.Equal(originalXml, roundTrippedElement);
} }
#if !DNXCORE50
[ConditionalFact] [ConditionalFact]
[ConditionalRunTestOnlyOnWindows] [ConditionalRunTestOnlyOnWindows]
public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails() public void Encrypt_CurrentUser_Decrypt_ImpersonatedAsAnonymous_Fails()
@ -51,5 +52,6 @@ namespace Microsoft.AspNet.DataProtection.XmlEncryption
ExceptionAssert2.ThrowsCryptographicException(() => ExceptionAssert2.ThrowsCryptographicException(() =>
AnonymousImpersonation.Run(() => decryptor.Decrypt(encryptedXmlInfo.EncryptedElement))); AnonymousImpersonation.Run(() => decryptor.Decrypt(encryptedXmlInfo.EncryptedElement)));
} }
#endif
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.AspNet.DataProtection.Internal;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Moq; using Moq;
using Xunit; using Xunit;

View File

@ -1,21 +1,32 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.DataProtection": "1.0.0-*", "Microsoft.AspNet.DataProtection": "1.0.0-*",
"Microsoft.AspNet.DataProtection.Test.Shared": { "type": "build", "version": "" }, "Microsoft.AspNet.DataProtection.Test.Shared": {
"Microsoft.AspNet.Testing": "1.0.0-*", "type": "build",
"Microsoft.Extensions.DependencyInjection": "1.0.0-*", "version": ""
"Moq": "4.2.1312.1622",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"frameworks": { "Microsoft.AspNet.Testing": "1.0.0-*",
"dnx451": { } "Microsoft.Extensions.DependencyInjection": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Moq": "4.2.1312.1622"
}
}, },
"commands": { "dnxcore50": {
"test": "xunit.runner.aspnet" "dependencies": {
}, "moq.netcore": "4.4.0-beta8"
"compilationOptions": { }
"allowUnsafe": true,
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
} }
},
"commands": {
"test": "xunit.runner.aspnet"
},
"compilationOptions": {
"allowUnsafe": true,
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
}
} }