From d4c295c045ea499592260e9f6d6c7148df166f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Jacinto?= Date: Fri, 20 Mar 2026 11:11:41 +0000 Subject: [PATCH] Updated NuGet packages + Replaced deprecated Roslyn test packages. --- .../Analyzers.CodeFixes.csproj | 4 +- .../Analyzers.Package.csproj | 2 +- .../Analyzers.Test/AnalyzerVerifierHelper.cs | 13 ++- .../Analyzers.Test/Analyzers.Test.csproj | 22 ++--- .../CSharpAnalyzerVerifier`1+Test.cs | 4 +- .../Verifiers/CSharpAnalyzerVerifier`1.cs | 7 +- .../Verifiers/CSharpCodeFixVerifier`2+Test.cs | 4 +- .../Verifiers/CSharpCodeFixVerifier`2.cs | 7 +- .../CSharpCodeRefactoringVerifier`1+Test.cs | 4 +- .../VisualBasicAnalyzerVerifier`1+Test.cs | 4 +- .../VisualBasicAnalyzerVerifier`1.cs | 7 +- .../VisualBasicCodeFixVerifier`2+Test.cs | 4 +- .../Verifiers/VisualBasicCodeFixVerifier`2.cs | 7 +- ...sualBasicCodeRefactoringVerifier`1+Test.cs | 4 +- Analyzers/Analyzers/Analyzers.csproj | 6 +- .../DocumentationGenerator.csproj | 4 +- SecureCoding.Test/SecureCoding.Test.csproj | 12 +-- .../SecureIO/StringExtensionsTests.cs | 2 +- .../SecureAssemblyLoaderTests.cs | 94 +++++++++---------- ...ecureNewtonsoftDeserializationUnitTests.cs | 30 +++--- SecureCoding/SecureCoding.csproj | 6 +- 21 files changed, 121 insertions(+), 126 deletions(-) diff --git a/Analyzers/Analyzers.CodeFixes/Analyzers.CodeFixes.csproj b/Analyzers/Analyzers.CodeFixes/Analyzers.CodeFixes.csproj index 05b8fdc..b0b4f29 100644 --- a/Analyzers/Analyzers.CodeFixes/Analyzers.CodeFixes.csproj +++ b/Analyzers/Analyzers.CodeFixes/Analyzers.CodeFixes.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/Analyzers/Analyzers.Package/Analyzers.Package.csproj b/Analyzers/Analyzers.Package/Analyzers.Package.csproj index de525bd..1d71031 100644 --- a/Analyzers/Analyzers.Package/Analyzers.Package.csproj +++ b/Analyzers/Analyzers.Package/Analyzers.Package.csproj @@ -39,7 +39,7 @@ True \ - + diff --git a/Analyzers/Analyzers.Test/AnalyzerVerifierHelper.cs b/Analyzers/Analyzers.Test/AnalyzerVerifierHelper.cs index ebe1ed4..43a25b9 100644 --- a/Analyzers/Analyzers.Test/AnalyzerVerifierHelper.cs +++ b/Analyzers/Analyzers.Test/AnalyzerVerifierHelper.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; using Microsoft.CodeAnalysis.Testing; using System; using System.Collections.Immutable; @@ -13,14 +12,14 @@ namespace Skyline.DataMiner.Utils.SecureCoding.Analyzers.Tests public static class AnalyzerVerifierHelper { /// - /// Builds an instance of CSharpAnalyzerTest with the specified diagnostic analyzer type and MSTest verifier, + /// Builds an instance of CSharpAnalyzerTest with the specified diagnostic analyzer type and default verifier, /// configured with the provided test case sources and optional package references. /// /// The type of DiagnosticAnalyzer to use. /// The source code to analyze. /// Optional package references for the test environment. /// An instance of CSharpAnalyzerTest configured with the specified parameters. - public static CSharpAnalyzerTest BuildAnalyzerVerifier( + public static CSharpAnalyzerTest BuildAnalyzerVerifier( string testCaseSources, ImmutableArray packages = default) where T : DiagnosticAnalyzer, new() @@ -30,7 +29,7 @@ public static CSharpAnalyzerTest BuildAnalyzerVerifier( throw new ArgumentException($"'{nameof(testCaseSources)}' cannot be null or empty.", nameof(testCaseSources)); } - return new CSharpAnalyzerTest() + return new CSharpAnalyzerTest() { TestState = { @@ -45,7 +44,7 @@ public static CSharpAnalyzerTest BuildAnalyzerVerifier( /// /// Builds an instance of CSharpCodeFixTest with the specified diagnostic analyzer type, code fix provider type, - /// and MSTest verifier, configured with the provided test case sources, fixed state sources, and optional package references. + /// and default verifier, configured with the provided test case sources, fixed state sources, and optional package references. /// /// The type of DiagnosticAnalyzer to use. /// The type of CodeFixProvider to use. @@ -53,7 +52,7 @@ public static CSharpAnalyzerTest BuildAnalyzerVerifier( /// The source code representing the expected fixed state after applying the code fix. /// Optional package references for the test environment. /// An instance of CSharpCodeFixTest configured with the specified parameters. - public static CSharpCodeFixTest BuildAnalyzerVerifierWithCodeFix( + public static CSharpCodeFixTest BuildAnalyzerVerifierWithCodeFix( string testCaseSources, string fixedStateSources, ImmutableArray packages = default) @@ -74,7 +73,7 @@ public static CSharpCodeFixTest BuildAnalyzerVerifierWit ? ImmutableArray.Empty : packages; - return new CSharpCodeFixTest() + return new CSharpCodeFixTest() { TestState = { diff --git a/Analyzers/Analyzers.Test/Analyzers.Test.csproj b/Analyzers/Analyzers.Test/Analyzers.Test.csproj index f1a4949..9aed6e6 100644 --- a/Analyzers/Analyzers.Test/Analyzers.Test.csproj +++ b/Analyzers/Analyzers.Test/Analyzers.Test.csproj @@ -7,17 +7,17 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1+Test.cs b/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1+Test.cs index 525598d..0275b3e 100644 --- a/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1+Test.cs +++ b/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1+Test.cs @@ -1,13 +1,13 @@ using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; namespace Analyzers.Test { public static partial class CSharpAnalyzerVerifier where TAnalyzer : DiagnosticAnalyzer, new() { - public class Test : CSharpAnalyzerTest + public class Test : CSharpAnalyzerTest { public Test() { diff --git a/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1.cs b/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1.cs index 4a1ccac..6b62443 100644 --- a/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1.cs +++ b/Analyzers/Analyzers.Test/Verifiers/CSharpAnalyzerVerifier`1.cs @@ -2,7 +2,6 @@ using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; using System.Threading; using System.Threading.Tasks; @@ -13,15 +12,15 @@ public static partial class CSharpAnalyzerVerifier { /// public static DiagnosticResult Diagnostic() - => CSharpAnalyzerVerifier.Diagnostic(); + => CSharpAnalyzerVerifier.Diagnostic(); /// public static DiagnosticResult Diagnostic(string diagnosticId) - => CSharpAnalyzerVerifier.Diagnostic(diagnosticId); + => CSharpAnalyzerVerifier.Diagnostic(diagnosticId); /// public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) - => CSharpAnalyzerVerifier.Diagnostic(descriptor); + => CSharpAnalyzerVerifier.Diagnostic(descriptor); /// public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) diff --git a/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2+Test.cs b/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2+Test.cs index 35994a6..832cb8c 100644 --- a/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2+Test.cs +++ b/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2+Test.cs @@ -1,7 +1,7 @@ using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; namespace Analyzers.Test { @@ -9,7 +9,7 @@ public static partial class CSharpCodeFixVerifier where TAnalyzer : DiagnosticAnalyzer, new() where TCodeFix : CodeFixProvider, new() { - public class Test : CSharpCodeFixTest + public class Test : CSharpCodeFixTest { public Test() { diff --git a/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs b/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs index 72ebcdb..3a77a44 100644 --- a/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs +++ b/Analyzers/Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs @@ -3,7 +3,6 @@ using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; using System.Threading; using System.Threading.Tasks; @@ -15,15 +14,15 @@ public static partial class CSharpCodeFixVerifier { /// public static DiagnosticResult Diagnostic() - => CSharpCodeFixVerifier.Diagnostic(); + => CSharpCodeFixVerifier.Diagnostic(); /// public static DiagnosticResult Diagnostic(string diagnosticId) - => CSharpCodeFixVerifier.Diagnostic(diagnosticId); + => CSharpCodeFixVerifier.Diagnostic(diagnosticId); /// public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) - => CSharpCodeFixVerifier.Diagnostic(descriptor); + => CSharpCodeFixVerifier.Diagnostic(descriptor); /// public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) diff --git a/Analyzers/Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1+Test.cs b/Analyzers/Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1+Test.cs index dc04f56..b39e80b 100644 --- a/Analyzers/Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1+Test.cs +++ b/Analyzers/Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1+Test.cs @@ -1,13 +1,13 @@ using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; namespace Analyzers.Test { public static partial class CSharpCodeRefactoringVerifier where TCodeRefactoring : CodeRefactoringProvider, new() { - public class Test : CSharpCodeRefactoringTest + public class Test : CSharpCodeRefactoringTest { public Test() { diff --git a/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1+Test.cs b/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1+Test.cs index 42978c1..3cc35dc 100644 --- a/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1+Test.cs +++ b/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1+Test.cs @@ -1,5 +1,5 @@ using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.VisualBasic.Testing; namespace Analyzers.Test @@ -7,7 +7,7 @@ namespace Analyzers.Test public static partial class VisualBasicAnalyzerVerifier where TAnalyzer : DiagnosticAnalyzer, new() { - public class Test : VisualBasicAnalyzerTest + public class Test : VisualBasicAnalyzerTest { public Test() { diff --git a/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1.cs b/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1.cs index 7114dde..7f8ad36 100644 --- a/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1.cs +++ b/Analyzers/Analyzers.Test/Verifiers/VisualBasicAnalyzerVerifier`1.cs @@ -1,7 +1,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; using Microsoft.CodeAnalysis.VisualBasic.Testing; using System.Threading; using System.Threading.Tasks; @@ -13,15 +12,15 @@ public static partial class VisualBasicAnalyzerVerifier { /// public static DiagnosticResult Diagnostic() - => VisualBasicAnalyzerVerifier.Diagnostic(); + => VisualBasicAnalyzerVerifier.Diagnostic(); /// public static DiagnosticResult Diagnostic(string diagnosticId) - => VisualBasicAnalyzerVerifier.Diagnostic(diagnosticId); + => VisualBasicAnalyzerVerifier.Diagnostic(diagnosticId); /// public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) - => VisualBasicAnalyzerVerifier.Diagnostic(descriptor); + => VisualBasicAnalyzerVerifier.Diagnostic(descriptor); /// public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) diff --git a/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2+Test.cs b/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2+Test.cs index 8e1c2c3..9d0cdf0 100644 --- a/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2+Test.cs +++ b/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2+Test.cs @@ -1,6 +1,6 @@ using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.VisualBasic.Testing; namespace Analyzers.Test @@ -9,7 +9,7 @@ public static partial class VisualBasicCodeFixVerifier where TAnalyzer : DiagnosticAnalyzer, new() where TCodeFix : CodeFixProvider, new() { - public class Test : VisualBasicCodeFixTest + public class Test : VisualBasicCodeFixTest { } } diff --git a/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2.cs b/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2.cs index d31b6c4..8b77a50 100644 --- a/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2.cs +++ b/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeFixVerifier`2.cs @@ -2,7 +2,6 @@ using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; using Microsoft.CodeAnalysis.VisualBasic.Testing; using System.Threading; using System.Threading.Tasks; @@ -15,15 +14,15 @@ public static partial class VisualBasicCodeFixVerifier { /// public static DiagnosticResult Diagnostic() - => VisualBasicCodeFixVerifier.Diagnostic(); + => VisualBasicCodeFixVerifier.Diagnostic(); /// public static DiagnosticResult Diagnostic(string diagnosticId) - => VisualBasicCodeFixVerifier.Diagnostic(diagnosticId); + => VisualBasicCodeFixVerifier.Diagnostic(diagnosticId); /// public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) - => VisualBasicCodeFixVerifier.Diagnostic(descriptor); + => VisualBasicCodeFixVerifier.Diagnostic(descriptor); /// public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected) diff --git a/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeRefactoringVerifier`1+Test.cs b/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeRefactoringVerifier`1+Test.cs index 808a2a0..265b7d3 100644 --- a/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeRefactoringVerifier`1+Test.cs +++ b/Analyzers/Analyzers.Test/Verifiers/VisualBasicCodeRefactoringVerifier`1+Test.cs @@ -1,5 +1,5 @@ using Microsoft.CodeAnalysis.CodeRefactorings; -using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.VisualBasic.Testing; namespace Analyzers.Test @@ -7,7 +7,7 @@ namespace Analyzers.Test public static partial class VisualBasicCodeRefactoringVerifier where TCodeRefactoring : CodeRefactoringProvider, new() { - public class Test : VisualBasicCodeRefactoringTest + public class Test : VisualBasicCodeRefactoringTest { } } diff --git a/Analyzers/Analyzers/Analyzers.csproj b/Analyzers/Analyzers/Analyzers.csproj index e1ef45b..5daa14b 100644 --- a/Analyzers/Analyzers/Analyzers.csproj +++ b/Analyzers/Analyzers/Analyzers.csproj @@ -11,12 +11,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/DocumentationGenerator/DocumentationGenerator.csproj b/DocumentationGenerator/DocumentationGenerator.csproj index 7040a54..82324ff 100644 --- a/DocumentationGenerator/DocumentationGenerator.csproj +++ b/DocumentationGenerator/DocumentationGenerator.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/SecureCoding.Test/SecureCoding.Test.csproj b/SecureCoding.Test/SecureCoding.Test.csproj index addadb8..dff331b 100644 --- a/SecureCoding.Test/SecureCoding.Test.csproj +++ b/SecureCoding.Test/SecureCoding.Test.csproj @@ -11,15 +11,15 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + diff --git a/SecureCoding.Test/SecureIO/StringExtensionsTests.cs b/SecureCoding.Test/SecureIO/StringExtensionsTests.cs index 27effa4..c216f8b 100644 --- a/SecureCoding.Test/SecureIO/StringExtensionsTests.cs +++ b/SecureCoding.Test/SecureIO/StringExtensionsTests.cs @@ -45,7 +45,7 @@ public void IsPathValidFailure(string path) [DataRow("\n")] public void IsPathValidException(string path) { - Assert.ThrowsException(() => { StringExtensions.IsPathValid(path); }); + Assert.Throws(() => { StringExtensions.IsPathValid(path); }); } } } \ No newline at end of file diff --git a/SecureCoding.Test/SecureReflection/SecureAssemblyLoaderTests.cs b/SecureCoding.Test/SecureReflection/SecureAssemblyLoaderTests.cs index 1708ddc..166e431 100644 --- a/SecureCoding.Test/SecureReflection/SecureAssemblyLoaderTests.cs +++ b/SecureCoding.Test/SecureReflection/SecureAssemblyLoaderTests.cs @@ -72,92 +72,92 @@ public void SecureAssemblyLoadFile_CertificateInBytesArgument_Success() public void SecureAssemblyLoadFile_X509Certificate2Argument_Failure() { // Arguments Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(string.Empty, default(X509Certificate2))); - Assert.ThrowsException(() => SecureAssembly.LoadFrom("ValidString", new X509Certificate2[0])); - Assert.ThrowsException(() => SecureAssembly.LoadFile(string.Empty, default(X509Certificate2))); - Assert.ThrowsException(() => SecureAssembly.LoadFile("ValidString", new X509Certificate2[0])); + Assert.Throws(() => SecureAssembly.LoadFrom(string.Empty, default(X509Certificate2))); + Assert.Throws(() => SecureAssembly.LoadFrom("ValidString", new X509Certificate2[0])); + Assert.Throws(() => SecureAssembly.LoadFile(string.Empty, default(X509Certificate2))); + Assert.Throws(() => SecureAssembly.LoadFile("ValidString", new X509Certificate2[0])); var selfSignedCertificate = new X509Certificate2(selfSignedCertificatePfxPath, selfSignedCertificatePassword); // Signed with different Certificate test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(signedTestDllPath, selfSignedCertificate)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(signedTestDllPath, selfSignedCertificate)); + Assert.Throws(() => SecureAssembly.LoadFrom(signedTestDllPath, selfSignedCertificate)); + Assert.Throws(() => SecureAssembly.LoadFile(signedTestDllPath, selfSignedCertificate)); // Self Signed Extension (.pfx/p.12) Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, selfSignedCertificate)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(selfSignedTestDllPath, selfSignedCertificate)); + Assert.Throws(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, selfSignedCertificate)); + Assert.Throws(() => SecureAssembly.LoadFile(selfSignedTestDllPath, selfSignedCertificate)); var emptyByteArr = Array.Empty(); // Unsigned Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(unsignedTestDllPath, new X509Certificate2(emptyByteArr))); - Assert.ThrowsException(() => SecureAssembly.LoadFile(unsignedTestDllPath, new X509Certificate2(emptyByteArr))); + Assert.Throws(() => SecureAssembly.LoadFrom(unsignedTestDllPath, new X509Certificate2(emptyByteArr))); + Assert.Throws(() => SecureAssembly.LoadFile(unsignedTestDllPath, new X509Certificate2(emptyByteArr))); // Tampered Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(tamperedTestDllPath, new X509Certificate2(emptyByteArr))); - Assert.ThrowsException(() => SecureAssembly.LoadFile(tamperedTestDllPath, new X509Certificate2(emptyByteArr))); + Assert.Throws(() => SecureAssembly.LoadFrom(tamperedTestDllPath, new X509Certificate2(emptyByteArr))); + Assert.Throws(() => SecureAssembly.LoadFile(tamperedTestDllPath, new X509Certificate2(emptyByteArr))); } [TestMethod] public void SecureAssemblyLoadFile_CertificatePathArgument_Failure() { // Arguments Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(string.Empty, default(string))); - Assert.ThrowsException(() => SecureAssembly.LoadFrom("ValidString", new string[0])); - Assert.ThrowsException(() => SecureAssembly.LoadFrom(signedTestDllPath, selfSignedCertificatePfxPath)); + Assert.Throws(() => SecureAssembly.LoadFrom(string.Empty, default(string))); + Assert.Throws(() => SecureAssembly.LoadFrom("ValidString", new string[0])); + Assert.Throws(() => SecureAssembly.LoadFrom(signedTestDllPath, selfSignedCertificatePfxPath)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(string.Empty, default(string))); - Assert.ThrowsException(() => SecureAssembly.LoadFile("ValidString", new string[0])); - Assert.ThrowsException(() => SecureAssembly.LoadFile(signedTestDllPath, selfSignedCertificatePfxPath)); + Assert.Throws(() => SecureAssembly.LoadFile(string.Empty, default(string))); + Assert.Throws(() => SecureAssembly.LoadFile("ValidString", new string[0])); + Assert.Throws(() => SecureAssembly.LoadFile(signedTestDllPath, selfSignedCertificatePfxPath)); // Signed with different Certificate test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, signedCertificatePath)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(selfSignedTestDllPath, signedCertificatePath)); + Assert.Throws(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, signedCertificatePath)); + Assert.Throws(() => SecureAssembly.LoadFile(selfSignedTestDllPath, signedCertificatePath)); // Unsigned Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(unsignedTestDllPath, signedCertificatePath)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(unsignedTestDllPath, signedCertificatePath)); + Assert.Throws(() => SecureAssembly.LoadFrom(unsignedTestDllPath, signedCertificatePath)); + Assert.Throws(() => SecureAssembly.LoadFile(unsignedTestDllPath, signedCertificatePath)); // Tampered Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(tamperedTestDllPath, signedCertificatePath)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(tamperedTestDllPath, signedCertificatePath)); + Assert.Throws(() => SecureAssembly.LoadFrom(tamperedTestDllPath, signedCertificatePath)); + Assert.Throws(() => SecureAssembly.LoadFile(tamperedTestDllPath, signedCertificatePath)); } [TestMethod] public void SecureAssemblyLoadFile_CertificateInBytes_Failure() { // Arguments Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(string.Empty, default(byte[]))); - Assert.ThrowsException(() => SecureAssembly.LoadFrom(string.Empty, default(List))); - Assert.ThrowsException(() => SecureAssembly.LoadFrom("ValidString", new byte[0])); - Assert.ThrowsException(() => SecureAssembly.LoadFrom("ValidString", new List { new byte[0] })); - Assert.ThrowsException(() => SecureAssembly.LoadFrom(signedTestDllPath, selfSignedCertificatePfxPath)); - - Assert.ThrowsException(() => SecureAssembly.LoadFile(string.Empty, default(byte[]))); - Assert.ThrowsException(() => SecureAssembly.LoadFile(string.Empty, default(List))); - Assert.ThrowsException(() => SecureAssembly.LoadFile("ValidString", new byte[0])); - Assert.ThrowsException(() => SecureAssembly.LoadFile("ValidString", new List { new byte[0] })); - Assert.ThrowsException(() => SecureAssembly.LoadFile(signedTestDllPath, selfSignedCertificatePfxPath)); + Assert.Throws(() => SecureAssembly.LoadFrom(string.Empty, default(byte[]))); + Assert.Throws(() => SecureAssembly.LoadFrom(string.Empty, default(List))); + Assert.Throws(() => SecureAssembly.LoadFrom("ValidString", new byte[0])); + Assert.Throws(() => SecureAssembly.LoadFrom("ValidString", new List { new byte[0] })); + Assert.Throws(() => SecureAssembly.LoadFrom(signedTestDllPath, selfSignedCertificatePfxPath)); + + Assert.Throws(() => SecureAssembly.LoadFile(string.Empty, default(byte[]))); + Assert.Throws(() => SecureAssembly.LoadFile(string.Empty, default(List))); + Assert.Throws(() => SecureAssembly.LoadFile("ValidString", new byte[0])); + Assert.Throws(() => SecureAssembly.LoadFile("ValidString", new List { new byte[0] })); + Assert.Throws(() => SecureAssembly.LoadFile(signedTestDllPath, selfSignedCertificatePfxPath)); var signedCertificateInBytes = System.IO.File.ReadAllBytes(signedCertificatePath); // Signed with different Certificate test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, signedCertificateInBytes)); - Assert.ThrowsException(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, new List { signedCertificateInBytes })); - Assert.ThrowsException(() => SecureAssembly.LoadFile(selfSignedTestDllPath, signedCertificateInBytes)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(selfSignedTestDllPath, new List { signedCertificateInBytes })); + Assert.Throws(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, signedCertificateInBytes)); + Assert.Throws(() => SecureAssembly.LoadFrom(selfSignedTestDllPath, new List { signedCertificateInBytes })); + Assert.Throws(() => SecureAssembly.LoadFile(selfSignedTestDllPath, signedCertificateInBytes)); + Assert.Throws(() => SecureAssembly.LoadFile(selfSignedTestDllPath, new List { signedCertificateInBytes })); // Unsigned Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(unsignedTestDllPath, signedCertificateInBytes)); - Assert.ThrowsException(() => SecureAssembly.LoadFrom(unsignedTestDllPath, new List { signedCertificateInBytes })); - Assert.ThrowsException(() => SecureAssembly.LoadFile(unsignedTestDllPath, signedCertificateInBytes)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(unsignedTestDllPath, new List { signedCertificateInBytes })); + Assert.Throws(() => SecureAssembly.LoadFrom(unsignedTestDllPath, signedCertificateInBytes)); + Assert.Throws(() => SecureAssembly.LoadFrom(unsignedTestDllPath, new List { signedCertificateInBytes })); + Assert.Throws(() => SecureAssembly.LoadFile(unsignedTestDllPath, signedCertificateInBytes)); + Assert.Throws(() => SecureAssembly.LoadFile(unsignedTestDllPath, new List { signedCertificateInBytes })); // Tampered Test - Assert.ThrowsException(() => SecureAssembly.LoadFrom(tamperedTestDllPath, signedCertificateInBytes)); - Assert.ThrowsException(() => SecureAssembly.LoadFrom(tamperedTestDllPath, new List { signedCertificateInBytes })); - Assert.ThrowsException(() => SecureAssembly.LoadFile(tamperedTestDllPath, signedCertificateInBytes)); - Assert.ThrowsException(() => SecureAssembly.LoadFile(tamperedTestDllPath, new List { signedCertificateInBytes })); + Assert.Throws(() => SecureAssembly.LoadFrom(tamperedTestDllPath, signedCertificateInBytes)); + Assert.Throws(() => SecureAssembly.LoadFrom(tamperedTestDllPath, new List { signedCertificateInBytes })); + Assert.Throws(() => SecureAssembly.LoadFile(tamperedTestDllPath, signedCertificateInBytes)); + Assert.Throws(() => SecureAssembly.LoadFile(tamperedTestDllPath, new List { signedCertificateInBytes })); } } } \ No newline at end of file diff --git a/SecureCoding.Test/SecureSerialization/Json/SecureNewtonsoftDeserializationUnitTests.cs b/SecureCoding.Test/SecureSerialization/Json/SecureNewtonsoftDeserializationUnitTests.cs index c93a7e4..aa3ad39 100644 --- a/SecureCoding.Test/SecureSerialization/Json/SecureNewtonsoftDeserializationUnitTests.cs +++ b/SecureCoding.Test/SecureSerialization/Json/SecureNewtonsoftDeserializationUnitTests.cs @@ -30,20 +30,20 @@ public void SimpleObjectDeserializationSuccess() public void SimpleObjectDeserializationFailure() { // wrong arguments - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(null)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(null)); // wrong json string - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject("{")); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject("{ \" }")); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject("{ : }")); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject("{")); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject("{ \" }")); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject("{ : }")); // too complex objects ComplexDummy dummy = new ComplexDummy(new List { new ComplexDummy(new List()) }); string serializedComplexDummy = JsonConvert.SerializeObject(dummy); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(serializedComplexDummy)); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(serializedComplexDummy)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(serializedComplexDummy)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(serializedComplexDummy)); } [TestMethod] @@ -68,7 +68,7 @@ public void SimpleObjectDeserializationWithSettingsSuccess() MissingMemberHandling = MissingMemberHandling.Error }; - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject("{ \"NonExistant\":null }", serializerSettings)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject("{ \"NonExistant\":null }", serializerSettings)); } [TestMethod] @@ -76,11 +76,11 @@ public void SimpleObjectDeserializationWithSettingsFailure() { // wrong arguments JsonSerializerSettings settings = new JsonSerializerSettings(); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(null, settings)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(null, settings)); settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.All; - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject("{ }", settings)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject("{ }", settings)); } [TestMethod] @@ -113,8 +113,8 @@ public void ComplexObjectDeserializationFailure() var serializedComplexDummy = JsonConvert.SerializeObject(complexDummy, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(serializedComplexDummy, knownTypes)); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(null, knownTypes)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(serializedComplexDummy, knownTypes)); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(null, knownTypes)); } [TestMethod] @@ -127,10 +127,10 @@ public void KnownTypesExceptions() }"; // Act & Assert - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, new List())); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, default(List))); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, new List { typeof(SecurePath) })); - Assert.ThrowsException(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, new List { typeof(System.Security.Principal.WindowsIdentity) })); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, new List())); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, default(List))); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, new List { typeof(SecurePath) })); + Assert.Throws(() => SecureNewtonsoftDeserialization.DeserializeObject(payload, new List { typeof(System.Security.Principal.WindowsIdentity) })); } } } diff --git a/SecureCoding/SecureCoding.csproj b/SecureCoding/SecureCoding.csproj index 064deeb..06a2e5e 100644 --- a/SecureCoding/SecureCoding.csproj +++ b/SecureCoding/SecureCoding.csproj @@ -34,9 +34,9 @@ - - - + + +