Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy PR [Don't merge] #140

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.joern.csharpsrc2cpg.querying.dataflow

import io.joern.csharpsrc2cpg.testfixtures.CSharpCode2CpgFixture
import io.shiftleft.semanticcpg.language.*
import io.joern.dataflowengineoss.language.*

class InterfaceDataflowTests extends CSharpCode2CpgFixture(withDataFlow = true) {

"simple interface dataflow" should {
val cpg = code(
"""
|namespace Anything.Any
|{
| public class AnotherRepoImplementation : BaseRepo
| {
| private readonly DB _db;
|
| public AnotherRepoImplementation(DB db)
| {
| _db = db;
| }
|
| public override AnyValue fun(string x)
| {
| return _db.put(x);
| }
| }
|}
|""".stripMargin,
"index.cs"
)
.moreCode(
"""
|namespace Anything.Any
|{
| public interface IRepo
| {
| AnyValue fun(string x);
| }
|}
|""".stripMargin,
"IService.cs"
)
.moreCode(
"""
|using Anything.Any;
|
|namespace Anything.ApiEndpoint
|{
| public class EndpointClass
| {
| private readonly IRepo _repo;
|
| public EndpointClass(IRepo repo)
| {
| _repo = repo;
| }
|
| public AnyValue Get()
| {
| var firstName = "firstName";
| var any = _repo.fun(firstName);
| return any;
| }
| }
|}
|""".stripMargin,
"service.cs"
)
.moreCode(
"""
|namespace Anything.Any
|{
| public abstract class BaseRepo : IRepo
| {
| public abstract AnyValue fun(string x);
| }
|}
|""".stripMargin,
"BaseRepo.cs"
)

"find path from firstName to fun call" ignore {
val src = cpg.literal.codeExact("firstName").l
val sink = cpg.call.nameExact("put")
sink.reachableBy(src).size shouldBe 1
}
}
}
Loading