From b88b691fbfeb54d1eb78f665a4252875d4d59a85 Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Mon, 2 Oct 2023 16:16:19 +0200 Subject: [PATCH] S3884: Add UTs for Alias any type --- ...urityPInvokeMethodShouldNotBeCalledTest.cs | 4 ++++ ...PInvokeMethodShouldNotBeCalled.CSharp12.cs | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SecurityPInvokeMethodShouldNotBeCalled.CSharp12.cs diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/SecurityPInvokeMethodShouldNotBeCalledTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/SecurityPInvokeMethodShouldNotBeCalledTest.cs index ad8b2ebd3c7..260130e9953 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/SecurityPInvokeMethodShouldNotBeCalledTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/SecurityPInvokeMethodShouldNotBeCalledTest.cs @@ -38,6 +38,10 @@ public void SecurityPInvokeMethodShouldNotBeCalled_CS() => public void SecurityPInvokeMethodShouldNotBeCalled_CSharp11() => builderCS.AddPaths("SecurityPInvokeMethodShouldNotBeCalled.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11).Verify(); + [TestMethod] + public void SecurityPInvokeMethodShouldNotBeCalled_CSharp12() => + builderCS.AddPaths("SecurityPInvokeMethodShouldNotBeCalled.CSharp12.cs").WithOptions(ParseOptionsHelper.FromCSharp12).Verify(); + #endif [TestMethod] diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SecurityPInvokeMethodShouldNotBeCalled.CSharp12.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SecurityPInvokeMethodShouldNotBeCalled.CSharp12.cs new file mode 100644 index 00000000000..71db14ca7d9 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SecurityPInvokeMethodShouldNotBeCalled.CSharp12.cs @@ -0,0 +1,23 @@ +using System; +using System.Runtime.InteropServices; +using IntPtrAliasFromKeywork = nint; + +class AliasAnyType +{ + [DllImport("OlE32.dll")] + static extern int CoSetProxyBlanket( + [MarshalAs(UnmanagedType.IUnknown)] object pProxy, + uint dwAuthnSvc, + uint dwAuthzSvc, + [MarshalAs(UnmanagedType.LPWStr)] string pServerPrincName, + uint dwAuthnLevel, + IntPtrAliasFromKeywork dwImpLevel, + IntPtrAliasFromKeywork pAuthInfo, + uint dwCapabilities); + + void Test() + { + _ = CoSetProxyBlanket(null, 0, 0, null, 0, 0, 0, 0); // Noncompliant + // ^^^^^^^^^^^^^^^^^ + } +}