[csharp] How to write a test case with external DLLs ? #20565
-
Hello, I would like to create a test case for a query, so far I have this structure:
CodeQL can't compile my test code (I can compile it with Visual Studio). I don't know how to create the options file:
Is there a way to list the required DLLs ?
Here is my code if it can help: using System.IO;
using System.Text;
using System.Xml;
using System.Activities.Presentation;
using System.Web.Caching;
using System.Data.Linq;
using System.Web;
using System.Web.SessionState;
using System.Security.Principal;
using System.Web.Security;
namespace ExtensionSinks
{
internal class Program
{
static void Main(string[] args)
{
// Simulated tainted input
string tainted = "tainted_input";
string taintedInput = "";
byte[] taintedBytes = Encoding.UTF8.GetBytes(tainted);
Stream taintedStream = new MemoryStream(taintedBytes);
TextReader taintedReader = new StringReader(tainted);
XmlReader xmlReader = XmlReader.Create(taintedReader);
BinaryReader binaryReader = new BinaryReader(taintedStream);
var designer = new WorkflowDesigner();
designer.PropertyInspectorFontAndColorData = tainted;
DBConvert.ChangeType(tainted, typeof(string));
DBConvert.ChangeType<string>(tainted);
OutputCache.Deserialize(taintedStream);
HttpStaticObjectsCollection.Deserialize(binaryReader);
SessionStateItemCollection.Deserialize(binaryReader);
var identity = new GenericIdentity("user");
var rp1 = new RolePrincipal(identity, tainted);
var rp2 = new RolePrincipal(tainted, identity, tainted);
var rp3 = new RolePrincipal(identity, tainted);
}
}
} I reviewed the CodeQL source repository and noticed that it supports linking .csproj files. However, when I attempted to use the one generated by Visual Studio, the process failed. I also came across tests that use stubs—is there a way to generate these stubs automatically? Unfortunately, I haven’t been able to find clear documentation on how to do this. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Hi @Hug0Vincent, Thanks for your question. Your options file looks correct to me, or at least very similar to things that our see in our tests. Let me ask internally how this is supposed to work. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
The extractor is resolving DLL's in the following way:
@hvitved : As applications are getting more "complicated" - do you know of any easy way to "detect" which assemblies to provide to the extractor for testing purposes (other than looking it up)? |
Beta Was this translation helpful? Give feedback.
dotnet
(containing the code you pasted above), then maybe check thebin/Debug
folder to see, which DLLs it uses?